You are on page 1of 2

package MyJavaPrograms; import java.text.DecimalFormat; public class MyMobilePhone { DecimalFormat dec = new DecimalFormat("###.

00"); private private private private double creditsPesos; int totalCallMinutes; double callRate; int totalMessageSent;

//Given public MyMobilePhone() { creditsPesos = 0; totalCallMinutes = 0; callRate = 2.50; totalMessageSent = 0; } //add to your credits public void load(double pesos) { creditsPesos = creditsPesos + pesos; } //if the credit is insufficient, the call method is not executed public void call(int minutes) { if(creditsPesos<2.50) { return; } else { totalCallMinutes+=(creditsPesos/callRate); } } //check balance public double getLoadLeft() { return creditsPesos; } //return total minutes called public int getTotalMinutesCalled() { return totalCallMinutes; } //prints out the report about the attributes of the MyMobilePhone public void printSummary() { System.out.println("Credits left: P" + dec.format(creditsPesos)) ; System.out.println("Total call duration: " + getTotalMinutesCall

ed() + " minutes"); System.out.println("Rate per call: " + dec.format(callRate)); System.out.println("Number of text messages sent: " + getNumText Messages()); } //implement new data public void changeRate(double newCallRate) { callRate = newCallRate; } //substract 1 peso from the credits public void sendTextMessage() { creditsPesos = creditsPesos - 1; } //return number of text messages sent public int getNumTextMessages() { return totalMessageSent; } }

You might also like