In: Computer Science
**I request you to Please Provide the positive Rating**
SOURCE CODE:
package sampleproject;
public class Car {
private String brand="Ford";
private String color="Red";
private int MPG=30;
public Car() {
super();
}
public Car(String brand) {
super();
this.brand = brand;
}
public Car(String brand, String color) {
super();
this.brand = brand;
this.color = color;
}
public Car(String brand, String color, int MPG)
{
super();
this.brand = brand;
this.color = color;
this.MPG = MPG;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getMPG() {
return MPG;
}
public void setMPG(int MPG) {
this.MPG = MPG;
}
@Override
public String toString() {
return "Car [brand=" + brand + ",
color=" + color + ", MPG=" + MPG + "]";
}
void DisplayCarInformation()
{
System.out.println(" " +brand+", "+color+"color ,
"+MPG+"mpg");
}
public static void main(String[] args) {
// TODO Auto-generated method
stub
Car c1=new Car();
System.out.println(c1.toString());
c1.DisplayCarInformation();
Car c2=new Car("Chevy","Red",
30);
Car c3=new Car("Tesla","Green",
30);
Car c4=new Car("Toyota", "Blue", 28
);
System.out.println(c1.toString());
c1.DisplayCarInformation();
System.out.println(c2.toString());
c2.DisplayCarInformation();
System.out.println(c3.toString());
c3.DisplayCarInformation();
System.out.println(c4.toString());
c4.DisplayCarInformation();
}
}
OUTPUT:
Car [brand=Ford, color=Red, MPG=30]
Ford, Redcolor , 30mpg
Car [brand=Ford, color=Red, MPG=30]
Ford, Redcolor , 30mpg
Car [brand=Chevy, color=Red, MPG=30]
Chevy, Redcolor , 30mpg
Car [brand=Tesla, color=Green, MPG=30]
Tesla, Greencolor , 30mpg
Car [brand=Toyota, color=Blue, MPG=28]
Toyota, Bluecolor , 28mpg