Write a class called CarTest java using main method Create two Car objects with
ID: 3836770 • Letter: W
Question
Write a class called CarTest java using main method Create two Car objects with the colors Red and White, respectively. Set features of the first car as follows by using set methods. Brand: Nissan Model: Juke Year: 2013 Kilometers (in thousands): 61.3 furl type (Gasoline/Diesel): Diesel Print information of the first car by using printInformation method. Calculate the sale price of the car by using priceOfCar method. Read information of the second car by using readInformation method Print information of the second car by using printInformation method. Calculate the rental price of the car by using priceOfCar method. Compare the two cars by using areCarsEqual method and print result as given In sample output. A sample start for Car.java and CarTestjava classes are provided below Car.java public class Car {//TODO: the methods and data about the Car class//will be declared in this file//variables public Strinp, color; private String brand;//constructor public Car(String c) { this.color = c; }//methods public String getBrand() { return this. Brand; } } CarTest.java public class CarTest { public static void main(String[] args) {//TODO: you will write a main program//that uses and tests the Car class here Car cl = new Car("Red"); c1.SrtBrand ("Nissan"); } } You need to fill in these classes. Analyze sample outputs given below and write your codes accordingly. This red car is Nissan's "Juke". It has travelled 61300.0 KM since 2013 using diesel as fuel. Price for sale of this car is 105387.0 TL. Enter information of second car: Brand: Renault Yodel: Clio Year: 2001 Kilometers (in thousand): 180.5 Fuel Type (Gasoline/Diesel): Gasoline This white car is Renault's "Clio". It has travelled 180500.0 KM since 2001 using gasoline as fuel. Price for rent of this car is 67.75 TL. These cars do not have same features. This red car is Nissan's "Juke". It has travelled 61300.6 KM since 2013 using diesel as fuel. Price for sale of this car is 105387.0 TL. Enter information of second car: Brand: Nissan Model: Juke Year: 2013 Kilometers (in thousand): 61.3 Fuel Type (Gasoline/Diesel): Diesel This white car is Nissan's "Juke". It has travelled 61300.0 KM since 2013 using diesel as fuel. Price for rent of this car is 161.35 TL. These cars have same features.Explanation / Answer
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cheggindia;
import java.util.Scanner;
/**
*
* @author R Gautam
*/
public class Car {
String color;
String brand;
String model;
int year;
double km = 0.0;
double salePrice = 0.0;
String fuel;
public Car(String color) {
this.color = color;
}
public static Car readInformation(Car c1, String brand, String model, int year, double km, String fuel) {
c1.setBrand(brand);
c1.setFuel(fuel);
c1.setKm(km);
c1.setModel(model);
c1.setYear(year);
return c1;
}
public static void printInformation(Car obj) {
System.out.println("This " + obj.color + " car is " + obj.brand + "'s " + obj.model + ". It has travelled " + (obj.km * 1000) + " KM since " + obj.year + " using " + obj.fuel + " as a fuel.");
}
public static Car priceOfCar(Car obj, double salePrice) {
obj.setSalePrice(salePrice);
System.out.println("Prise for sale of this car is " + obj.salePrice + " TL.");
return obj;
}
public static void areCarsEquels(Car obj1, Car obj2) {
if ((obj1.brand.equalsIgnoreCase(obj2.brand))
&& (obj1.color.equalsIgnoreCase(obj2.color))
&& (obj1.fuel.equalsIgnoreCase(obj2.fuel))
&& (obj1.model.equalsIgnoreCase(obj2.model))
&& (obj1.year == obj2.year)) {
System.out.println("These Cars do not same features");
} else {
System.out.println("These Cars have same features");
}
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public double getKm() {
return km;
}
public void setKm(double km) {
this.km = km;
}
public String getFuel() {
return fuel;
}
public void setFuel(String fuel) {
this.fuel = fuel;
}
public double getSalePrice() {
return salePrice;
}
public void setSalePrice(double salePrice) {
this.salePrice = salePrice;
}
}
class CarTest {
public static void main(String[] args) {
Car c1 = new Car("Red");
c1 = Car.readInformation(c1, "Nissan", "Juke", 2013, 61.3, "Diesel");
Car.printInformation(c1);
Car.priceOfCar(c1, 105387);
Car c2 = new Car("Wight");
System.out.println("Enter Information of second car");
Scanner sc = new Scanner(System.in);
System.out.println("Brand :");
String brand = sc.next();
System.out.println("Model");
String model = sc.next();
System.out.println("Year");
int year = sc.nextInt();
System.out.println("Kilometers (In Thousand)");
double km = sc.nextDouble();
System.out.println("Fuel Type (Gasoline/Diesel)");
String fuel = sc.next();
c2 = Car.readInformation(c2, brand, model, year, km, fuel);
Car.printInformation(c2);
Car.priceOfCar(c2, 67.75);
Car.areCarsEquels(c1, c2);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.