Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please help with java // Main.java import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Main { public static void main(String[] args) { // example List
please help with java
// Main.java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Main {
public static void main(String[] args) {
// example
List cars = new ArrayList(
Arrays.asList(
new FordBronco("sport", 50000, 8),
new FordBronco("turbo", 58000, 10),
new FordBronco("turbo-sport", 55000, 9.2),
new TeslaS("sedan", 65000, 0),
new TeslaS("sedan", 68000, 0),
new TeslaS("sport", 75000, 0),
new TeslaS("sport", 70000, 0),
new KiaRio("hatchback", 18000, 5.1),
new KiaRio("hatchback", 15000, 5.8),
new KiaRio("sedan", 18000, 5.1),
new KiaRio("sedan", 19000, 5.3),
new KiaRio("turbo", 25000, 15.1)
)
);
AutoAutoSalesman aas = new AutoAutoSalesman(cars);
}
}
// Car.java
public class Car {
private final String style;
private final double price;
private final double fuelEconomy;
public Car(String style, double price, double fuelEconomy) {
this.style = style;
this.price = price;
this.fuelEconomy = fuelEconomy;
}
public String getStyle() {
return style;
}
public double getPrice() {
return price;
}
public double getFuelEconomy() {
return fuelEconomy;
}
public void goes() {
System.out.println("Vroom");
}
@Override
public String toString() {
return this.getClass().toString() +
" " + getStyle() +
" " + getPrice() +
" " + getFuelEconomy();
}
}
// FordBronco.java
public class FordBronco extends Car {
public FordBronco(String style, double price, double fuelEconomy) {
super(style, price, fuelEconomy);
}
@Override
public void goes() {
System.out.println("VROOM");
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started