Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

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 carList = new ArrayList(); public void add(NewCar car){ this.carList.add(car); } public void display(){ for(NewCar car : this.carList){ System.out.println(car.toString()); } } public void select(double maxPrice){ for(NewCar car : this.carList){ double finalPrice = car.price; if(finalPrice

________________________________________________________-

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(); } }

Model sticker price discount sales tax months financed Rio Rio Year Make 2010 Kia 2007 Kia 2004 Honda Civic 2002 Honda Civic 2010 Chevrolet Cobalt 2000 Honda Accord 2009 SubaruForester 2000 Chevrolet Malibu 11000 9000 6000 6000 12000 3000 22000 22000 1000 0 0 0 2000 0 0 0 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 36 60 60 60 60 60 60 60

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

Students also viewed these Databases questions

Question

Explain the various employee benefit laws.

Answered: 1 week ago