I am new to Java. How do I make a condition that could possibly combine the said "plans" in the program and add their prices? For now the program is only set for one plan and price. Which can only output one plan, and price.
Like for example if I input:
Enter number of talk minutes: 125
Enter number of text messages sent: 225
Enter number of gigabytes used: 1.3
The outcome should be like
Recommended Cellular Plans: Plan B and Plan E Total Bill: $134.00
import java.text.DecimalFormat;
import java.util.Scanner;
public class HorizonPhones {
public static void main (String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter number of talk minutes: ");
int minutes = scanner.nextInt();
System.out.print("Enter amount of text messages sent: ");
int texts = scanner.nextInt();
System.out.print("Enter amount of gigabytes used: ");
double gigaBytes = scanner.nextDouble();
double planA = 49.00;
double planB = 55.00;
double planC = 61.00;
double planD = 70.00;
double planE = 79.00;
double planF = 87.00;
if (minutes <= 500 && texts == 0 && gigaBytes == 0 ) {
System.out.println("Recommended Cellular Plans: Plan A");
System.out.println("Total Bill: " + planA);
return;
}
if (minutes < 500 && texts > 1 && gigaBytes == 0) {
System.out.println("Recommended Cellular Plans: Plan B");
System.out.println("Total Bill: " + planB);
return;
}
if (minutes > 500 && texts <= 100 && gigaBytes == 0) {
System.out.println("Recommended Cellular Plans: Plan C");
System.out.println("Total Bill: " + planC);
return;
}
if (minutes > 500 && texts >= 100 && gigaBytes == 0) {
System.out.println("Recommended Cellular Plans: Plan D");
System.out.println("Total bill: " + planD);
return;
}
if (minutes > 500 && texts >= 1 && gigaBytes < 2) {
System.out.println("Recommended Cellular Plans: Plan E");
System.out.println("Total bill: " + planE);
return;
}
if (minutes > 500 && texts > 1 && gigaBytes > 2) {
System.out.println("Recommended Cellular Plans: Plan F");
System.out.println("Total bill: " + planF);
return;
}
}
}
Aucun commentaire:
Enregistrer un commentaire