Share Pastebin
Guest
Public paste!

test

By: a guest | Feb 9th, 2010 | Syntax: None | Size: 1.18 KB | Hits: 26 | Expires: Never
Copy text to clipboard
  1. //Jesse Parks
  2. //TestObject06
  3. public class TestObject06
  4. {
  5.         public static void main(String[] args)
  6.         {
  7.                 // construct objects
  8.                 Car aCar = new Car();
  9.                 // display object data
  10.                 System.out.println("My Car's Data:");
  11.                 System.out.println("\n" + aCar.getName() + "\n" + aCar.getColor() + "\n" + aCar.getGallons() + " Gallons of gas");
  12.                 System.out.println();
  13.                 System.out.println("My charger gas changes");
  14.                 aCar.gallons(10);
  15.                 System.out.println(" My gas changed to " + aCar.getGallons());
  16.         }
  17.         }
  18.         class Car
  19. {
  20.         // private data variables
  21.         private String name;
  22.         private String color;
  23.         private int numGallons;
  24.         // constructor methods
  25.         public Car()
  26.         {
  27.                 name = "Ford F150";
  28.                 color = "Bright red";
  29.                 numGallons = 5;
  30.         }
  31.         public Car(String c, String b, int g)
  32.         {
  33.                 name = c;
  34.                 color = b;
  35.                 numGallons = g;
  36.         }
  37.         // access methods
  38.         public String getName()
  39.         {
  40.                 return name;
  41.                
  42.         }
  43.         public String getColor()
  44.         {
  45.                 return color;
  46.         }
  47.         public int getGallons()
  48.         {
  49.                 return numGallons;
  50.         }
  51.         // alter methods
  52.         public void setName(String c)
  53.         {
  54.                 name = c;
  55.         }
  56.         public void gallons(int g)
  57.         {
  58.                 numGallons = g;
  59.                 for (int x=1; x<=numGallons; x++)
  60.                         System.out.print("");
  61.         }
  62.                
  63. }