Programming Exercise 5-4 | Instructions CellPhoneServi+ 1 import java.util.* 2 p
ID: 3747840 • Letter: P
Question
Programming Exercise 5-4 | Instructions CellPhoneServi+ 1 import java.util.* 2 public class CellPhoneService Write a program for Horizon Phones, a provider of cellular phone service. Prompt a 3public static void main (String args[]) 4 // Write your code here 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 500 minutes of talk and no text or data should accept Plan A at $49 per month A customer who needs fewer than 500 minutes of talk and any text messages should accept Plan B at $55 per month A customer who needs 500 or more minutes of talk and no data should accept either Plan C for up to 100 text messages at $61 per month or Plan D for 100 text messages or more at $70 per month. A customer who needs any data should accept Plan E for up to 3 gigabytes at $79 or Plan F for 3 gigabytes or more at $87Explanation / Answer
import java.util.*;
public class CellPhoneService{
public static String calculateBestPlan(int talkMinCount, int textMesCount, float dataCount){
if(talkMinCount<500){ //fewer than 500 minutes of talk
if(textMesCount==0 || dataCount==0){ // No text or data (interpreted as "OR")
return "Recommend Plan is A at $49 per month";
}else if(textMesCount>0){ // any text messages needed
return "Recommend Plan is B at $55 per month";
}
}else{
if( dataCount==0){ //No data needed
if(textMesCount<100)
return "Recommend Plan is C at $61 per month"; // upto 100 messages
else
return "Recommend Plan is D at $70 per month";//more than 100 messages
}else{
if(dataCount<3){
return "Recommend Plan is E at $79 per month"; //data GB count
}else{
return "Recommend Plan is F at $87 per month";
}
}
}
return "Thank you for using our services!!!";
}
public static void main(String[] args) {
try{
// create a scanner so we can read the command-line input
Scanner scanner = new Scanner(System.in);
// prompt for the user for max monthly values for talk minutes used
System.out.print("Enter your maximum monthly values for talk minutes used ");
int talkMinCount = scanner.nextInt();
// prompt for text messages sent
System.out.print("Enter how many text messages you send every month ");
int textMesCount = scanner.nextInt();
// prompt for GB of data used
System.out.print("Enter how much data you use, in gigabytes ");
float dataCount = scanner.nextFloat();
System.out.println(calculateBestPlan(talkMinCount,textMesCount,dataCount));
}catch(Exception e){}
System.out.println("Please give correct values!!!");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.