I know that I am very close to this but I am having trouble and my brain is abso
ID: 3555361 • Letter: I
Question
I know that I am very close to this but I am having trouble and my brain is absolutely spent. Im too old for school...
Here is the question:
Create a class named CarRental that contains fields that hold a renter's name, zip code, size of the car rented, daily rental fee, length of rental in days, and total rental fee. The class contains a constructor that requires all the rental data except the daily rate and total fee, which are calculated bades on the sice of the car; economy at $29.99 per day, midsize at 38.99$ per day, or full size at 43.50 per day. The class also includes a display() method that displays all the rental data. Create a subclass named LuxuryCarRental. This class sets the rental fee at $79.99 per day and prompts the user to respond to the option of including a chauffer at $200 more per day. Override the parent class display() method to include chauffer fee information. Write an application named UseCarRental that prompts the user for the data needed for a rental and creates an object of the correct type. Display the total rental fee. Save the files as CarRental.java, LuxaryCarRental.java, and UseCarRental.java.
Here is my code:
package CarRental;
public class CarRental
{
String name;
int zipcode;
String size;
double dFee;
int days;
double total;
public String getName()
{
return name;
}
public int getZipcode()
{
return zipcode;
}
public String getSize()
{
return size;
}
public int getDays()
{
return days;
}
public CarRental(String size)
{
if(size.charAt(0)=='m')
dFee = 38.99;
else
if(size.charAt(0)=='f')
dFee = 43.50;
else
dFee = 29.99;
}
public void calculateTotal(int days)
{
total = dFee*days;
}
public void print()
{
System.out.println("Your rental total cost is: $" + total);
}
}
package CarRental;
import java.util.*;
public class LuxaryCarRental extends CarRental
{
public LuxaryCarRental(String size, int days)
{
super(size);
}
public void CalculateTotalN()
{
super.calculateTotal(days);
dFee = 79.99;
int chauffer;
Scanner keyboard = new Scanner(System.in);
System.out.println("Do you want to add a chauffer for $200? Enter 0 for"
+ " yes and 1 for no");
chauffer = keyboard.nextInt();
if(chauffer!=1)
total = dFee;
else
total = dFee + 100;
}
}
package CarRental;
import java.util.*;
public class UseCarRental
{
public static void main(String args[])
{
String name, size;
int zipcode, days;
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter total days you plan on renting: ");
days = keyboard.nextInt();
System.out.println("Enter your name: ");
name = keyboard.next();
System.out.println("Enter your billing zipcode: ");
zipcode = keyboard.nextInt();
System.out.println("Enter the size of the car: ");
size = keyboard.next();
CarRental economy = new CarRental(size);
economy.calculateTotal(days);
economy.print();
LuxaryCarRental fullsize = new LuxaryCarRental(size, days);
fullsize.CalculateTotalN();
fullsize.print();
}
There are no syntax error, but I am not gettign the ouputs that the question asks. Please help m!
Explanation / Answer
public class CarRental { String name; int zipcode; String size; double dFee; int days; double total; public String getName() { return name; } public int getZipcode() { return zipcode; } public String getSize() { return size; } public int getDays() { return days; } public CarRental(String size) { if(size.charAt(0)=='m') dFee = 38.99; else if(size.charAt(0)=='f') dFee = 43.50; else dFee = 29.99; } public void calculateTotal(int days) { total = dFee*days; } public void print() { System.out.println("Your rental total cost is: $" + total); } } public class LuxaryCarRental extends CarRental { private int days; double total; String size; public LuxaryCarRental(String size, int days) { super(size); this.size = size; this.days = days; } public void CalculateTotalN() { dFee = 79.99; int chauffer; Scanner keyboard = new Scanner(System.in); System.out.println("Do you want to add a chauffer for $200? Enter 0 for" + " yes and 1 for no"); chauffer = keyboard.nextInt(); if(chauffer==1) total = dFee; else total = dFee + 200; } public void print() { System.out.println("Your rental total cost is: $" + total); } } public class UseCarRental { public static void main(String args[]) { String name, size; int zipcode, days; Scanner keyboard = new Scanner(System.in); System.out.println("Enter total days you plan on renting: "); days = keyboard.nextInt(); System.out.println("Enter your name: "); name = keyboard.next(); System.out.println("Enter your billing zipcode: "); zipcode = keyboard.nextInt(); System.out.println("Enter the size of the car: "); size = keyboard.next(); System.out.println("Do you want to get a luxury car : Enter 0 for Yes and 1 for No"); String answer = keyboard.next(); if(answer.equalsIgnoreCase("0")) { LuxaryCarRental fullsize = new LuxaryCarRental(size, days); fullsize.CalculateTotalN(); fullsize.print(); } else { CarRental economy = new CarRental(size); economy.calculateTotal(days); economy.print(); } } }