In this assignment you need to develop a class named yourlastname_Car with the f
ID: 3633304 • Letter: I
Question
In this assignment you need to develop a class named yourlastname_Car with the following attributes: model, year, color, mileage. It should also have the following methods: a default constructor, set and get methods for each of the attributes, and a toString method that prints out the Car information in any format you choose. This code should go into a yourlastname_Car.java file.Then you need to develop a class with a main method to test your Car class, name it yourlastname_TestCar.java. It will create one or more objects of the class Car and test all the methods. Please refer to the Student class example given in this week's module to do this assignment. Note: You may add other attributes and methods if you would like, just be sure you test everything in your Car class in your main.
Add comments to your program starting with your name at the top, then throughout your program to describe what you are doing. Also be sure to indent consistently throughout your program to make it more readable.
Extra Credit: For 5 points of extra credit, add a static member variable to your class and a static method to access it. Test this method from your test program.
Please submit your program in the DropBox area by midnight on Sunday, November 13. Upload both your .java files, I will compile and run them on my computer. Be sure you have tested it first to make sure it compiles with no errors and then runs and does what you expect. You will not receive any credit for a program that does not compile.
Explanation / Answer
please rate - thanks
hope this is good
includes extra credit
import java.util.*;
public class yourlastname_TestCar
{
public static void main(String[] args)
{Scanner in=new Scanner(System.in);
yourlastname_Car a=new yourlastname_Car();
System.out.println("After constructor "+a);
a.setModel("Chevy");
a.setYear(2011);
a.setMileage(100);
a.setColor("White");
a.setEngine(1.8);
System.out.println("after setting everything");
System.out.println(a.getColor()+" "+a.getYear()
+" "+a.getModel()+" "+a.getEngine()+
" liter engine"+" "+a.getMileage()+" miles");
}
}
--------------------------------------------
class yourlastname_Car
{static private double engine;
private String model;
private int year;
private int mileage;
private String color;
public yourlastname_Car()
{model="Kia";
year=2000;
mileage=1000;
color="Black";
engine=1.4;
}
public void setModel(String m)
{model=m;
}
public void setMileage(int m)
{mileage=m;
}
public static void setEngine(double e)
{engine=e;
}
public static double getEngine()
{return engine;
}
public void setYear(int y)
{year=y;
}
public void setColor(String c)
{color=c;
}
public int getYear()
{return year;
}
public String getModel()
{return model;
}
public int getMileage()
{return mileage;
}
public String getColor()
{return color;
}
public String toString()
{return color+" "+year+" "+model+" "+engine+" liter engine"+" "+mileage+" miles";
}
}