#Why my else if's aren't working

12 messages · Page 1 of 1 (latest)

stray crypt
#

Hi again. I've been working on an assignment and it's been driving me crazy. No matter what I do, I can't seem to get the else if statements to print out. I feel like I'm walking in circles and not getting anywhere.

Basically what' I'm trying to do is get Plan E and Plan F statements to print out. Every time I do, it comes out as Plan D instead.

If someone can please help me, I would gladly appreciate it

Here is the code.

#
import java.util.*;

public class CellPhoneService {
    public static void main(String args[]) {
        int talkMinutes, textMessages, gigabytes, price;

        String set_plan;
        final int MINUTES = 500;
        final int MESSAGES = 100;
        final int DATA = 3;
        final int PRICEA = 49;
        final int PRICEB = 55;
        final int PRICEC = 61;
        final int PRICED = 70;
        final int PRICEE = 79;
        final int PRICEF = 87;

        Scanner input = new Scanner(System.in);
        System.out.println("Enter talk minutes needed");
        talkMinutes = input.nextInt();
        System.out.println("Enter text messages needed");
        textMessages = input.nextInt();
        System.out.println("Enter gigabytes of data needed");
        gigabytes = input.nextInt();
#

  if (talkMinutes < MINUTES) {
    if (textMessages == 0 && gigabytes == 0) {
  set_plan = "Plan A";
  price = PRICEA;
                System.out.println(set_plan + " " + talkMinutes + " " + textMessages + " " + gigabytes);
            } 
else {
 set_plan = "Plan B";
 price = PRICEB;
                System.out.println(set_plan + " " + talkMinutes + " " + textMessages + " " + gigabytes);
  }
} 
        
else if (talkMinutes >= MINUTES) {
 if (textMessages < MESSAGES) {
 set_plan = "Plan C";
 price = PRICEC;
                System.out.println(set_plan + " " + talkMinutes + " " + textMessages + " " + gigabytes);
} else {
set_plan = "Plan D";
price = PRICED;
                System.out.println(set_plan + " " + talkMinutes + " " + textMessages + " " + gigabytes);
 }
} 
        
else (gigabytes <= DATA) {
 if (gigabytes <= DATA) {
 set_plan = "Plan E";
 price = PRICEE;
                System.out.println(set_plan + ": $" + price + " per month");
} 
  else {
set_plan = "Plan F";
price = PRICEF;
                System.out.println(set_plan + ": $" + price + " per month");

            }
        }
    }
}
pale forge
#

Check data first.

#

and then the other plans

#
if (gigabytes >= DATA) {
  *check between plan E and F*


} else {

  if (talkMinutes ...) {

#

in this format.

stray crypt
#

 if (gigabytes >= DATA) {
  set_plan = "Plan E";
  price = PRICEE;
                System.out.println(set_plan + ": $" + price + " per month");
} 

else {
  if (gigabytes < DATA) {
  set_plan = "Plan F";
  price = PRICEF;
                System.out.println(set_plan + ": $" + price + " per month");
}

#

Is there a reason why it's printing two plans?

azure skiff
#

Yes if the if conditions are true for 2 plans then it will print them both

gleaming crest
#

just you gotta use labels