I cannot get my code to compile without errors. package userentalcar; /** * * @a
ID: 3655705 • Letter: I
Question
I cannot get my code to compile without errors. package userentalcar; /** * * @author Bob */ public class RentalCar { int carType; double rentalRate; int getCarType() { return carType; } double getRentalRate() { return rentalRate; } public RentalCar(int carType){ this.carType = carType; if(carType == 1) { this.rentalRate = 69.95; } else if(carType == 2) { this.rentalRate = 89.95; } else { this.rentalRate = 99.99; } } class Luxury extends RentalCar{ double Surcharge; double getSurcharge(){ return this.Surchage; } public Luxury(int carType){ RentalCar(carType); this.Surcharge = 40.00; } } _________________________________________ package userentalcar; import java.util.Scanner; /** * * @author Bob */ public class UseRentalCar { /** * @param args the command line arguments */ public static void main(String[] args) { System.out.println("Enter carType of car1: (1) for Compact (2) for Mid-sized (3) for Full size "); Scanner my_input = New Scanner(System.in); int cartype = my_input.nextInt(); RentalCar car1 = new RentalCar(cartype); System.out.println("Enter carType of car2: (1) for Compact (2) for Mid-sized (3) for Full size "); cartype = my_input.nextInt(); RentalCar car2 = new RentalCar(2); System.out.println("Enter carType of car3: (1) for Compact (2) for Mid-sized (3) for Full size "); cartype = my_input.nextInt(); RentalCar car3 = new RentalCar(3); System.out.println("Enter carType of car4: (1) for Compact (2) for Mid-sized (3) for Full size "); cartype = my_input.nextInt(); Luxury car4 = new Luxury(2); System.out.println(car1.getCarType.toString()+" "+car1.getRentalrate().toString()); System.out.println(car2.getCarType.toString()+" "+car2.getRentalrate().toString()); System.out.println(car3.getCarType.toString()+" "+car3.getRentalrate().toString()); System.out.println(car4.getCarType.toString()+" "+car4.getRentalrate().toString())+" "+car4.getSurcharge().toString(); } }Explanation / Answer
import java.util.Scanner; class RentalCar { int carType; double rentalRate; int getCarType() { return this.carType; } double getRentalRate() { return this.rentalRate; } public RentalCar(int carType){ this.carType = carType; if(carType == 1) { this.rentalRate = 69.95; } else if(carType == 2) { this.rentalRate = 89.95; } else { this.rentalRate = 99.99; } } } class Luxury extends RentalCar{ double Surcharge; double getSurcharge(){ return this.Surcharge; } public Luxury(int carType){ super(carType); this.Surcharge = 40.00; } } public class UseRentalCar { public static void main(String[] args){ System.out.println("Enter carType of car1: (1) for Compact (2) for Mid-sized (3) for Full size "); Scanner my_input = new Scanner(System.in); int cartype = my_input.nextInt(); RentalCar car1 = new RentalCar(cartype); System.out.println("Enter carType of car2: (1) for Compact (2) for Mid-sized (3) for Full size "); cartype = my_input.nextInt(); RentalCar car2 = new RentalCar(2); System.out.println("Enter carType of car3: (1) for Compact (2) for Mid-sized (3) for Full size "); cartype = my_input.nextInt(); RentalCar car3 = new RentalCar(3); System.out.println("Enter carType of car4: (1) for Compact (2) for Mid-sized (3) for Full size "); cartype = my_input.nextInt(); Luxury car4 = new Luxury(cartype); System.out.println(car1.getCarType()+" "+car1.getRentalRate()); System.out.println(car2.getCarType()+" "+car2.getRentalRate()); System.out.println(car3.getCarType()+" "+car3.getRentalRate()); System.out.println(car4.getCarType()+" "+car4.getRentalRate()+" "+car4.getSurcharge()); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.