package CarLot;
Main Method:
//HW06.java CS 140-01
//10/23/12
//Dominic Torro
//This program builds several car objects
public class CarLot
{
public static void main (String[] args)
{
//Builds 3 car objects.
Car car1 = new Car (1996, "Dodge", "Neon", "4dr", "rust" );
Car car2 = new Car (1978, "Ford", "Mustang", "2dr", "black");
Car car3 = new Car (1967, "Chevrolet", "Corvette", "2dr", "silver");
//Header to explain what program does
System.out.println("This program builds several car objects");
//Print original information for each car using a toString()
System.out.println ("Car 1: " +car1);
System.out.println ("Car 2: " +car2);
System.out.println ("Car 3: " +car3);
//Set color of car3 to red
car3.setColor("red");
//Set year of car1 to 2001
car1.setYear(2001);
//Set model of car 1 to Challenger
car1.setModel("Challenger");
//Set model of car2 to Taurus
car2.setModel("Taurus");
//Print new info for car1 using getter methods
System.out.println("Car 1 is now a: " +car1.getYear() +car1.getModel());
System.out.println ("Car 2 is now a: " +car2.getModel());
System.out.println ("Car 3 is now a: " +car3.getColor());
}
}
This is my worker class:
package CarLot;
import java.text.DecimalFormat;
public class CarWorker
{
//Instance Data
int year;
String make;
String model;
String bodytype;
String color;
//Constructor method
public Car (int yearIn, String makeIn, String modelIn, String bodytypeIn, String colorIn)
{
year = yearIn;
make = makeIn;
model = modelIn;
bodytype = bodytypeIn;
color = colorIn;
}
//Getters and setters
public int getYear()
{
return year;
}
public void setyear(yearIn)
{
year = yearIn;
}
public String getmake()
{
return make;
}
public void setmake(makeIn)
{
make = makeIn;
}
public String getmodel()
{
return model;
}
public void setmodel(modelIn)
{
model = modelIn;
}
public String bodytype()
{
return bodytype;
}
public void setbodytype(bodytypeIn)
{
bodytype = bodytypeIn;
}
public String getcolor()
{
return color;
}
public void setcolor(colorIn)
{
color = colorIn;
}
public String toString()
{
String result = "";
return result = ""
}
}