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.
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 current programs-------
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"} }; Phone myPhones [] = new Phone [4]; myPhones = createPhones(d); System.out.println (myPhones); //calls createPhones //calculates the monthly charge // calls printBill } public Phone[] createPhones(String d[][]) { Phone myPhones[] = new Phone [d.length]; for (int i = 0; i < d.length; i++) { if (d[i][0].equals("CellPhone")) myPhones [i] = new CellPhone (d[i][1], d[i][2], new Date (Integer.parseInt(d[i][3])), Double.parseDouble(d[i][4]), Integer.parseInt(d[i][5]) ); else myPhones [i] = new LandLinePhone (d[i][1], d[i][2], new Date (Integer.parseInt(d[i][3])), Double.parseDouble(d[i][4]), Integer.parseInt(d[i][5]) ); //need help as of what would go in here //Something is still wrong with myPhones } } public void printBill (Phone p[]) { //need help as of what goes here } }
Screen shot 2012-04-05 at 3.24.17 PM.jpg
Screen shot 2012-04-05 at 3.24.25 PM.jpg