Hey all i am having problems with my current asignment in my java class. I just cant seem to grasp the concept of getting values in one class but not getting the same (or overriding) in another class that calls it. Here is the problem for my class:
Create class SeniorOccupant that extends class Occupant. Class SeniorOccupant contains two pricate boolean instance variables, AARP & AAA. Provide "get" methods for both instance variables.
Class SeniorOccupant also overrides the Occupant class' getTotalCharge() method. If either (but not both) SeniorOccupant class instance variables are true, then the getTotalCharge() method should return a double value that is 90% of the value returned by the getTotalCharge() method in the Occupant class. If both instance variables are true, then the getTotalCharge() method should return a double value that is 85% of the value returned by the getTotalCharge() method in the Occupant class. If neither instance variables are true, then the getTotalCharge() method should truen the same double value that is returned by the getTotalCharge() method in the Occupant class.
Class SeniorOccupant should also override the Occupant class' toString() method. For the additional instance variables, include the variable names (AARP and AAA) and their respective values. Additionally, method toString() should return the correct totalCharge value i.e. the total charge should be the same as the value returned by the getTotalCharge() method.
And here is the Occupant class code:
import java.text.DecimalFormat;
class Occupant
{
final int adultCharge = 30; //-------------------------
final int childCharge = 10; //----Define static numbers
final double motelTax = .10; //-------------------------
int intTotal; //------------------------------
int intAdults; //---Define variable declaration
int intChild; // -
int intNights; // -
int intBase; // -
int intTax; //------------------------------
public Occupant(int adults, int children, int nights)
{
intAdults = adults;
intChild = children;
intNights = nights;
}
public int getAdults()
{
return intAdults;
}
public int getChildren()
{
return intChild;
}
public int getNights()
{
return intNights;
}
public double getAdultCharge()
{
intAdults = getAdults() * adultCharge * getNights();
return intAdults;
}
public double getChildCharge()
{
intChild = getChildren() * childCharge * getNights();
return intChild;
}
public double getBaseCharge()
{
intBase = getAdults() + getChildren();
return intBase;
}
public double getMotelTax()
{
double intTax = intBase * motelTax;
return intTax;
}
public double getTotalCharge()
{
intTotal = intBase + intTax;
return intTotal;
}
public String toString()
{
DecimalFormat dollars = new DecimalFormat("$###.00");
return "# of Adults: " + intAdults + "\n" +
"# of Children: " + intChild + "\n" +
"# of Nights: " + intNights + "\n" +
"Adult Charge: " + dollars.format(getAdultCharge()) + "\n" +
"Child Charge: " + dollars.format(getChildCharge()) + "\n" +
"Base Charge: " + dollars.format(getBaseCharge()) + "\n" +
"Tax: " + dollars.format(getMotelTax()) + "\n" +
"Total: " + dollars.format(getTotalCharge()) + "\n";
}
}
And this is the SeniorOccupant code im currently working on (which i have no idea if i even started right...):
public class SeniorOccupant extends Occupant
{
private Occupant occ;
private boolean AARP;
private boolean AAA;
public SeniorOccupant(int inNum1, int inNum2, int inNum3, boolean inTF1, boolean inTF2)
{
super(inNum1, inNum2, inNum3);
AARP = inTF1;
AAA = inTF2;
}
public boolean getAARP()
{
return AARP;
}
public boolean getAAA()
{
return AAA;
}
public double checkTF()
{
if (AARP || true)
{
return occ.getTotalCharge() * .90;
}
else if (AARP && AAA)
{
return occ.getTotalCharge() * .85;
}
else
{
return occ.getTotalCharge();
}
}
public String toString()
{
return super.toString() +
"AARP: " + getAARP() + "\n" +
"AAA: " + getAAA() + "\n";
}
}
And here is the "test" code:
public class TestClass10 {
public static void main(String args[])
{
Occupant o1 = new Occupant(1,2,3);
Occupant o2 = new Occupant(4,0,4);
SeniorOccupant o3 = new SeniorOccupant(1,2,3,true,false);
SeniorOccupant o4 = new SeniorOccupant(1,2,3,false,true);
SeniorOccupant o5 = new SeniorOccupant(1,2,3,true,true);
SeniorOccupant o6 = new SeniorOccupant(1,2,3,false,false);
displayOccupant(o1);
displayOccupant(o2);
displayOccupant(o3);
displayOccupant(o4);
displayOccupant(o5);
displayOccupant(o6);
}
private static void displayOccupant(Occupant o)
{
System.out.println(o);
System.out.println("Total charge: " + o.getTotalCharge() + "\n\n");
}
}
Any help would be great as i am brain dead right now!
David