Hello Everyone, everything has been going good with the whole JAVA learning process until today. I have been working on Inheritance and have not been able to complete this project.
My problem is coming from the test class, I simply do not know how to set it up to output the proper information. So first I have to create a Date class, then a Phone class which is the parent of the CellPhone class and LandLinePhone class. I then have to create a test class called PhoneTest. Everything has been completed except for the PhoneTest class which is the one that outputs everything. Thanks for looking at my issue, hopefully someone can point me in the correct direction. The PhoneTest class is what I am haveing issues with, it will be the last class in this file that i will list. Thanks for anyone that can help me this.
First I need to develop the classes according to the UML Provide (ill attach a picture of the UML for a visual representation)
in the PhoneTest class the main method created the two dimensional string array, calls createPhones, calculates the monthly charge, and calls printBill
The Method printBill prints the information for each instance to the system prompt.
(along with the UML attachment I will also attach the instruction page of the program for better understanding of what I need to do.
--Here are my codes--
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 Number" + 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", "3/31/2012", "0.6", "750"},
{"Land", "Apple", "817-272-4567", "3","15","2012", "9.25", "300"},
{"Land", "Verizon", "817-272-9886", "4","1","2012", "12.60", "1125"},
{"Cell", "LG", "817-272-6283", "4","15","2012", ".035", "250"} };
//calls createPhones
//calculates the monthly charge
// calls printBill
}
public Phone[] createPhones(String d[][])
{
//need help as of what goes in here
}
public void printBill (Phone p[])
{
//need help as of what goes in here
}
}
=================================================================================================