Now create a Customer object that keeps track of the customer\'s name (i.e., a S
ID: 3784870 • Letter: N
Question
Now create a Customer object that keeps track of the customer's name (i.e., a String), the type of cellPhone they have (i.e., a CellPhone object that you created in part 1), the type of plan that they have (i.e., a PhonePlan object that you just created), the number of callsMade so far during the month, and finally, the balance owed on their account (a float). Create a constructor that takes the customer's name. cellPhone type and phonePlan (see example in part 2). New customers should have an account balance initially equal to 0 for regular plans and $0.40 per minute purchased (i.e.. initial minutes allowed) for Pay-as-you-go plans. Create get and set methods for the three instance variables. Create a toString() method that displays the customer as follows: Tim Bur with a Apple I Phone 6Plus on a Pay-as-you-go Plan with 30 minutes and 0XB retraining Rita Book with a BlackBerry PRIV on a Regular (100 minute, 0.5GB data) Monthly Plan with 100 minutes remaining and 500000KB remaining Note that all of the red portions in the output above will vary from customer to customer. You must also make use of the toString() method that you created in part 3 by calling it from within here. Test your code with the following test program and make sure that the output is correct.Explanation / Answer
Please find the required solution:(Assuming part-1 is not given question)
public class Customer {
String name;
CellPhone cellphone;
PhonePlan phoneplan;
public Customer(String name, CellPhone cellphone, PhonePlan phoneplan) {
this.name = name;
this.cellphone = cellphone;
this.phoneplan = phoneplan;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public CellPhone getCellphone() {
return cellphone;
}
public void setCellphone(CellPhone cellphone) {
this.cellphone = cellphone;
}
public PhonePlan getPhoneplan() {
return phoneplan;
}
public void setPhoneplan(PhonePlan phoneplan) {
this.phoneplan = phoneplan;
}
@Override
public String toString() {
return name
+ " with "
+ getCellphone().getBrand()
+ " "
+ getCellphone().getModel()
+ " is on a "
+ (getPhoneplan().isPayAsYouGo() ? "Pay-As-You-Go-Plan"
: "Regular plan(" + getPhoneplan().getMinutes()
+ " minutes,"
+ (double) getPhoneplan().getData()
/ (1000 * 100) + " GB data)") + " with "
+ getPhoneplan().getMinutes() + " min "
+ getPhoneplan().getData() + " kb";
}
public static void main(String[] args) {
CellPhone iPhone = new CellPhone("iPhone 6 Plus", "Apple", 12400.00f);
CellPhone galaxy = new CellPhone("Galaxy 7", "Samsung", 18200.00f);
CellPhone priv = new CellPhone("PRIV", "BlackBerry", 24210.00f);
System.out.println(new Customer("Rob Banks", iPhone, new PhonePlan(200,
2500000, false)));
System.out.println(new Customer("Rita Book", priv, new PhonePlan(100,
50000, false)));
System.out.println(new Customer("Sue Parmann", iPhone, new PhonePlan(
60, 2500000, true)));
System.out.println(new Customer("Tim Bur", iPhone, new PhonePlan(30, 0,
true)));
System.out.println(new Customer("April Rain", galaxy, new PhonePlan(
200, 1000000, true)));
}
}
class CellPhone {
String model;
String brand;
float price;
public CellPhone(String model, String brand, float price) {
this.model = model;
this.brand = brand;
this.price = price;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
}
class PhonePlan {
int minutes;
int data;
boolean payAsYouGo;
public PhonePlan(int minutes, int data, boolean payAsYouGo) {
this.minutes = minutes;
this.data = data;
this.payAsYouGo = payAsYouGo;
}
public int getMinutes() {
return minutes;
}
public void setMinutes(int minutes) {
this.minutes = minutes;
}
public int getData() {
return data;
}
public void setData(int data) {
this.data = data;
}
public boolean isPayAsYouGo() {
return payAsYouGo;
}
public void setPayAsYouGo(boolean payAsYouGo) {
this.payAsYouGo = payAsYouGo;
}
}
Sample output:
Rob Banks with Apple iPhone 6 Plus is on a Regular plan(200 minutes,25.0 GB data) with 200 min 2500000 kb
Rita Book with BlackBerry PRIV is on a Regular plan(100 minutes,0.5 GB data) with 100 min 50000 kb
Sue Parmann with Apple iPhone 6 Plus is on a Pay-As-You-Go-Plan with 60 min 2500000 kb
Tim Bur with Apple iPhone 6 Plus is on a Pay-As-You-Go-Plan with 30 min 0 kb
April Rain with Samsung Galaxy 7 is on a Pay-As-You-Go-Plan with 200 min 1000000 kb
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.