Question
Need help with display the final price on each car being displayed and need to have a quote for an abbreviation for each cars. Thank
Need help with display the final price on each car being displayed and need to have a quote for an abbreviation for each cars. Thank you!
public class NewCar { String year; String make; String model; double price; double monthPay; String desc; String abb; NewCar(String year, String make, String model) { this.year = year; this.make = make; this.model = model; this.price = 0; this.monthPay = 0; this.desc = this.year+" "+make+" "+ model; this.abb = this.year.substring(2,4)+make.charAt(0)+model.charAt(0); } double calFinalPrice(double sPrice, double discount, double salesTax) { double temp = sPrice-discount; double tax = (double)(temp*salesTax)/100; this.price = temp+tax; return this.price; } double calZeroPctMonPayt(int month) { this.monthPay = (double)this.price/month; return this.monthPay; } public String toString() { String des = this.desc ; String ab = this.abb; return "You want to purchase a " + des + " Abbreveiation: " + ab; } }
________________________________________________________________
import java.util.ArrayList; public class NewCarList { ArrayList ________________________________________________________- public class NewCarListTester { public static void main(String[] args) { //Creating 5 NewCar instances NewCar car1 = new NewCar("2010", "Kia", "Rio"); NewCar car2 = new NewCar("2007", "Kia", "Rio"); NewCar car3 = new NewCar("2004", "Honda", "Civic"); NewCar car4 = new NewCar("2004", "Honda", "Civic"); NewCar car5 = new NewCar("2010", "Chevrolet", "Cobalt"); //Creating a NewCarList object NewCarList carList = new NewCarList(); //adding cars to the list //while calculating finalPrice also carList.add(car1); car1.calFinalPrice(11000, 1000, 0.08); carList.add(car2); car2.calFinalPrice(9000, 0, 0.08); carList.add(car3); car3.calFinalPrice(6000, 0, 0.08); carList.add(car4); car4.calFinalPrice(6000, 0, 0.08); carList.add(car5); car5.calFinalPrice(12000, 2000, 0.08); //Display all Cars System.out.println("*** List of cars"); carList.display(); System.out.println(); //Display using select() System.out.println("*** List of cars under $9720"); carList.select(9720); System.out.println(); //Adding 3 more cars NewCar car6 = new NewCar("2000", "Honda", "Accord");carList.add(car6); car6.calFinalPrice(60000, 6, 5); NewCar car7 = new NewCar("2009", "Suburu", "Forester");carList.add(car7); car7.calFinalPrice(70000, 7, 4); NewCar car8 = new NewCar("2011", "Chevrolet", "Malibu"); carList.add(car8); car8.calFinalPrice(80000, 8, 3); car6.calFinalPrice(3000, 0, 0.08); carList.add(car6); car7.calFinalPrice(22000, 0, 0.08); carList.add(car7); car8.calFinalPrice(22000, 0, 0.08); carList.add(car8); //droping 2nd item i.e. item at index 1 carList.drop(1); //Display carList again System.out.println("Displaying all cars after drop(): "); carList.display(); System.out.println(); } }
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