Change 3 different attributes in any of McLaren and Ferrari class.
Here is the code:
import java.util.Scanner;
public class Main {
private static Scanner sc = new Scanner(System.in);
private static Ferrari fr = new Ferrari();
private static McLaren mc = new McLaren();
public static void main(String[] args) {
System.out.println(fr.toString());
System.out.println();
System.out.println(mc.toString());
System.out.println("Enter Ferrari 812 engine Specs: ");
String engine = sc.nextLine();
fr.setEngine(engine);
System.out.println("Enter McLaren 720S top speed: ");
int speed = sc.nextInt();
mc.setSpeed(speed);
System.out.println(" Available Options: ");
displayCar(fr, mc);
int choice = getUserChoice();
if(choice ==1) {
System.out.println("Fantastic!! You chose Ferrari 812 Superfast.");
System.out.println("with 789-819 hp");
} else if(choice == 2) {
System.out.println("Nice choice, the McLaren720S has 710hp.");
System.out.println("0-60mph takes just 2.8sec and 124mph arrives in an astonishing 7.8 seconds.");
}
}
public static void displayCar(Ferrari f, McLaren m) {
System.out.println("\n. FERRARI 812:");
System.out.println(f.toString());
System.out.println();
}
public static int getUserChoice() {
System.out.println("Enter your choice from the available options:");
int choice = sc.nextInt();
return choice;
}
}
class McLaren {
private int speed;
private String engine;
private boolean sunroof;
private final double PRICE = 225000.00;
public McLaren() {
this(200,"McLaren 4.0-liter twin-turbo V8", false);
}
public McLaren(int speed, String engine, boolean sunroof) {
this.speed = speed;
this.engine = engine;
this.sunroof = sunroof;
}
public void setSpeed(int s) {
this.speed = s;
}
public void setEngine(String e) {
this.engine = e;
}
public void setSunroof(boolean s) {
this.sunroof = s;
}
public int getSpeed() {
return speed;
}
public String getEngine() {
return engine;
}
public double getPrice() {
return PRICE;
}
public boolean getSunroof() {
return sunroof;
}
public String toString() {
return "Speed: " + getSpeed() + "mph\nEngine:" + getEngine() + "\nSunroof:" + getSunroof() + "\nPrice:
}
}
class Ferrari {
private int speed;
private String engine;
private boolean sunroof;
private final double PRICE = 300000.00;
public Ferrari() {
this(190, "Ferrari 296 3.0- Liter V6", true);
}
public Ferrari(int speed, String engine, boolean sunroof) {
this.speed = speed;
this.engine = engine;
this.sunroof = sunroof;
}
public void setSpeed(int s) {
this.speed = s;
}
public void setEngine(String e) {
this.engine = e;
}
public void setSunroof(boolean s) {
this.sunroof = s;
}
public int getSpeed() {
return speed;
}
public String getEngine() {
return engine;
}
public boolean getSunroof() {
return sunroof;
}
public double getPrice() {
return PRICE;
}
public String toString() {
return "Speed: " + getSpeed() + "mph\nEngine: " + getEngine() + "\nSunroof: " + getSunroof() + "\nPrice:
}
}
sectetur adip
sectetur adipiscing elit.
sectetur adipiscing el
secte
sectetur adipiscing elit. Nam lacinia pulvinar tortor
sectetur adipiscing elit. Nam lacinia pulvina
sectetur adipiscing elit. Nam lacinia pulvina
Unlock access to this and over
10,000 step-by-step explanations
Have an account? Log In