Hello everyone, I am close to finishing this project, but i am stuck on my PhoneTest class. To be specific I am stuck on the Method printBill. (This is an Inheritance project).
Their is a Date class for the month/day/year
Their is a parent class which is the Phone class
Then the children are CellPhone class and LandLinePhone class
Then their is the PhoneTest class, which is the one that I need to complete this project.
I have created the main method which creates a two-dimensional string array, calls createPhones, calculates monthly charge, and calls printBill. I have inserted all the data in the 2D string array already, I have also completed the createPhones method. My main issue is coming from method printBill, I am not exactly sure as of how to start it and complete it, so any guidance would be appreciated.
This is what method printBill needs to do:
Method printBill prints the the information for each instance to the system prompt as follows:
Type Minutes $xxx.xx x/x/xxxx
Type $xxx.xx x/x/xxxx
Type $xxx.xx x/x/xxxx
Type Minutes $xxx.xx x/x/xxxx
Total $xxx.xx
- Where Type is the type of phone (cell or land line), Minutes is minutes used (only for cell phone),
$xxx.xx is the monthly charge, and x/x/xxxx is the bill date.
Could someone show me how to code this?
-Here are my classes-
public class Date
{
private int month;
private int day;
private int year;
public Date ()
{
setMonth (0);
setDay (0);
setYear (0);
}
public Date (int m, int d, int y)
{
setMonth (m);
setDay (d);
setYear (y);
}
public void setMonth (int m)
{
month = m;
}
public int getMonth ()
{
return month;
}
public void setDay (int d)
{
day =d;
}
public int getDay()
{
return day;
}
public void setYear (int y)
{
year =y;
}
public int getYear ()
{
return year;
}
public String toString()
{
return ("Month" + month +
"Day" + day +
"Year" + year);
}
}
public class Phone
{
private String brand;
private String phoneNumber;
private double monthlyCharge;
private Date billDate;
public Phone ()
{
setBrand ("");
setPhoneNumber ("");
setMonthlyCharge (0.0);
setBillDate (new Date () );
}
public Phone (String b, String pn, double mc, Date bd)
{
setBrand (B);
setPhoneNumber (pn);
setMonthlyCharge (mc);
setBillDate (bd);
}
public void setBillDate (Date bd)
{
billDate = bd;
}
public Date getBillDate()
{
return billDate;
}
public void setBrand (String B)
{
brand = b;
}
public String getBrand ()
{
return brand;
}
public void setPhoneNumber ( String pn )
{
phoneNumber = pn;
}
public String getPhoneNumber ()
{
return phoneNumber;
}
public void setMonthlyCharge (double mc)
{
monthlyCharge = mc;
}
public double getMonthlyCharge ()
{
return monthlyCharge;
}
public String toString ()
{
return ("Brand: " + brand +
"Phone Numbe: " + phoneNumber +
"Monthly Charge: " + monthlyCharge +
billDate.toString () );
}
public void calculateMonthlyCharge ()
{
setMonthlyCharge(12.0);
}
}
public class CellPhone extends Phone
{
private double pricePerMinute;
private int minutesUsed;
public CellPhone ()
{
super();
setPricePerMinute(0.0);
setMinutesUsed (0);
}
public CellPhone (String b, String pn, double mc, Date bd, double ppm,int mu)
{
super (b, pn, mc, bd);
setPricePerMinute(ppm);
setMinutesUsed (mu);
}
public void setPricePerMinute (double ppm)
{
pricePerMinute = ppm;
}
public double getPricePerMinute ()
{
return pricePerMinute;
}
public void setMinutesUsed (int mu)
{
minutesUsed = mu;
}
public int getMinutesUsed()
{
return minutesUsed;
}
public String toString()
{
return (super.toString() +
"Price Per Minute " + pricePerMinute +
"Minutes Used " + minutesUsed);
}
public void calculateMonthlyCharge()
{
super.calculateMonthlyCharge();
setMonthlyCharge (pricePerMinute * minutesUsed + super.getMonthlyCharge());
}
}
public class LandLinePhone extends Phone
{
private double longDistanceFee;
private int longDistanceMinutes;
public LandLinePhone()
{
super();
setLongDistanceFee(0.0);
setLongDistanceMinutes(0);
}
public LandLinePhone (String b, String pn, double mc, Date bd, double ldf, int ldm)
{
super(b, pn, mc, bd);
setLongDistanceFee(ldf);
setLongDistanceMinutes(ldm);
}
public void setLongDistanceFee(double ldf)
{
longDistanceFee = ldf;
}
public double getLongDistanceFee ()
{
return longDistanceFee;
}
public void setLongDistanceMinutes (int ldm)
{
longDistanceMinutes = ldm;
}
public int getLongDistanceMinutes ()
{
return longDistanceMinutes;
}
public String toString()
{
return (super.toString() +
"Long Distance Fee" + longDistanceFee +
"Long Distance Minutes" + longDistanceMinutes);
}
public void calculateMonthlyCharge()
{
super.calculateMonthlyCharge();
setMonthlyCharge (longDistanceFee + super.getMonthlyCharge());
}
}
==========================================================================================================
public class PhoneTest
{
public static void main (String args [])
{
double total;
String d[][] = { {"Cell", "Samsung", "817-272-1234", "0", "3","31","2012", "0.6", "750"},
{"Land", "Apple", "817-272-4567", "0", "3","15","2012", "9.25", "300"},
{"Land", "Verizon", "817-272-9886", "0", "4","1","2012", "12.60", "1125"},
{"Cell", "LG", "817-272-6283","0","4", "15","2012", ".035", "250"} };
Phone myPhones [] = createPhones(d);
for (Phone m:myPhones)
{
System.out.println( m.getMonthlyCharge() );
}
//calculates the monthly charge
// calls printBill
}
public static Phone[] createPhones(String d[][])
{
Phone myPhones[] = new Phone [d.length];
for (int i = 0; i < d.length; i++)
{
if (d[i][0].equals("Cell"))
myPhones [i] = new CellPhone (d[i][1], d[i][2], Double.parseDouble(d[i][3]),
new Date (Integer.parseInt(d[i][4]), Integer.parseInt(d[i][5]), Integer.parseInt(d[i][6])),
Double.parseDouble(d[i][7]),
Integer.parseInt(d[i][8]) );
else
myPhones [i] = new LandLinePhone (d[i][1], d[i][2], Double.parseDouble(d[i][3]),
new Date (Integer.parseInt(d[i][4]), Integer.parseInt(d[i][5]), Integer.parseInt(d[i][6])),
Double.parseDouble(d[i][7]),
Integer.parseInt(d[i][8]) );
}
return myPhones;
}
public static void printBill (Phone p[])
{
//need help as of what goes here
}
}