In: Computer Science
Write a program for XXX Phones, a provider of cellular phone service. Prompt a user for maximum monthly values for talk minutes used, text messages sent, and gigabytes of data used, and then recommend the best plan for the customer’s needs. A customer who needs fewer than 400 minutes of talk and no text or data should accept Plan A at $29 per month. A customer who needs fewer than 400 minutes of talk and any text messages should accept Plan B at $35 per month. A customer who needs 400 or more minutes of talk and no data should accept either Plan C for up to 100 text messages at $45 per month or Plan D for 100 text messages or more at $50 per month. A customer who needs any data should accept Plan E for up to 2 gigabytes at $59 or Plan F for 2 gigabytes or more at $65. Save the file as Mobile.java
Again, Don’t forget to create the application/project MobileTest.java Class that has the main method and an object to use the Mobile class.
Hey mate, below is provided two separated java projects with one file is saved as Mobile.java and the other is MobileTest.java. The MobileTest.java contains the main method of the program which also creates a Mobile class object (m) to show the working of the two java files as a single program.
Mobile.java
public class Mobile{
int talkMin,textMes,dataGiga;
void plan(int talkMin,int textMes,int dataGiga){
if(talkMin<400 && dataGiga==0)
{
if(textMes==0)
{
System.out.println("Plan A at $29 per month");
}
else{
System.out.println("Plan B at $35 per month");
}
}
else if(talkMin>=400 && dataGiga==0)
{
if(textMes<=100)
{
System.out.println("Plan C at $45 per month");
}
else{
System.out.println("Plan D at $50 per month");
}
}
else if(dataGiga>0)
{
if(dataGiga<=2)
{
System.out.println("Plan E at $59 per month");
}
else{
System.out.println("Plan F at $65 per month");
}
}
else{
System.out.println("Sorry, no plans available for you");
}
}
}
MobileTest.java
import java.util.Scanner;
class MobileTest{
public static void main (String[] args) {
Mobile m=new Mobile();
Scanner s=new Scanner(System.in);
System.out.println("\nEnter the following details on your monthly basis:");
System.out.print("Maximum talk minutes used:");
m.talkMin=s.nextInt();
System.out.print("Text messages sent:");
m.textMes=s.nextInt();
System.out.print("Data usage in gigabytes:");
m.dataGiga=s.nextInt();
System.out.print("\nYou are advised to buy: ");
m.plan(m.talkMin, m.textMes, m.dataGiga);
}
}
Sample Output