Good evening all!
The assignments are getting confusing! Again, not asking for a straight up answer but rather a pointer in the right direction so any help is appreciated.
Edit 2: Here is the exercise in question if it helps clear anything up:
I'm wondering how I can set the dailyFee variable in the CarRental.java file using the UseCarRental.java file. The if statements from CarRental.java don't seem to be working properly (inputting size doesn't set the dailyFee variable). Additionally, if I enter "l" for the size, it's not prompting to LuxuryCarRental.java. Here is the code:
CarRental.java
import javax.swing.JOptionPane;
public class CarRental
{
private String name;
private String zipCode;
private String size;
private double dailyFee;
private int rentalDays;
private double totalFee;
public CarRental(String name, String zipCode, String size, double dailyFee, int rentalDays, double totalFee)
{
this.name = name;
this.zipCode = zipCode;
this.size = size;
if (size == "e")
{
this.dailyFee = 29.99;
}
else if (size == "m")
{
this.dailyFee = 38.99;
}
else if (size == "f")
{
this.dailyFee = 43.50;
}
this.dailyFee = dailyFee;
this.rentalDays = rentalDays;
totalFee = dailyFee * rentalDays;
}
public CarRental(){}
public void display()
{
JOptionPane.showMessageDialog(null, "Luxury car for " + name + " from zip code " + zipCode + "\n"
+ "Type = " + size + "\n"
+ "Daily Fee = " + dailyFee + "\n"
+ "Days = " + rentalDays + "\n"
+ "Your rental is $" + totalFee);
}
//includes getters and setters but I didn't include them in this post
LuxuryCarRental.java
import javax.swing.JOptionPane;
public class LuxuryCarRental extends CarRental
{
public LuxuryCarRental(String name, String zipCode, String size, double dailyFee, int rentalDays, double totalFee, String includeChauffeur)
{
super(name, zipCode, size, dailyFee, rentalDays, totalFee);
if (size == "l")
{
dailyFee = 79.99;
includeChauffeur = JOptionPane.showInputDialog(null, "Include chauffeur? Y/N");
if (includeChauffeur == "Y")
{
totalFee = totalFee + 200;
}
}
}
}
UseCarRental.java (incomplete)
import javax.swing.JOptionPane;
public class UseCarRental
{
public static void main(String[] args)
{
CarRental userInfo = new CarRental();
userInfo.setName(JOptionPane.showInputDialog("Enter name"));
userInfo.setZipCode(JOptionPane.showInputDialog("Enter zip code"));
userInfo.setSize(JOptionPane.showInputDialog("Enter type of car" + "\n" + "e - economy" + "\n" + "m - midsize" + "\n" + "f - full" + "\n" + "l - luxury"));
userInfo.setRentalDays(Integer.parseInt(JOptionPane.showInputDialog("Enter days to rent")));
System.out.println(userInfo.getDailyFee());
userInfo.display();
}
}
As you can see, I'm completely stumped as to how I can use setDailyFee in UseCarRental.java to set the dailyFee variable, which is need to make the totalFee calculation.
Edit: Being asked to explain why this is not a duplicate question. I fixed the string comparison issue (not updated here yet) but the core issue is still setters and inheritance.
Edit 3: Well I guess the question of the century (for clarity's sake) is: how do I set dailyFee value? I thought that it would be set by the if statement in CarRental.java once size is entered?