WEB java help

Discussion in 'OT Technology' started by airbball23, Nov 5, 2009.

  1. airbball23

    airbball23 Rent this Space only $5/mnth

    Joined:
    Jan 13, 2007
    Messages:
    1,489
    Likes Received:
    0
    i posted this in the computer and programming subsection but i'm not getting any responses - i was hoping i can get a responds here :x:

    i'm having issues with the confirming if it's okay to proceed with x price:

    Code:
    import java.util.Scanner;
    
    public class ts709 {
        public static final int COST_1 = 200;
        public static final int COST_2 = 100;
        public static final int COST_3 = 75;
        public static final int COST_4 = 125;
    
    public static void main(String[] args) {
                int Chicagotix = 0;
                int IndianapolisTix = 0;
                int SouthBendTix = 0;
                int BloomingtonTix = 0;
                int Totalcost = 0;
                int choicemm, choicedest, choicett = 0, choiceconf;
    Scanner in = new Scanner(System.in);
    
       System.out.println("Welcome to OT Express Train Station!\n");
    
       System.out.println("What would you like to do:");
       System.out.println("  1. Buy Train Ticket(s)");
       System.out.println("  2. Return Train Ticket(s)");
       System.out.println("  3. Print Info");
       System.out.println("  4. Exit\n");
    
    choicemm = in.nextInt();
    
    while (choicemm != 4){
    
    switch(choicemm) {
    case 1: {
       System.out.println("Buy ticket to:");
                System.out.println("  1. Chicago");
                System.out.println("  2. Indianapolis");
                System.out.println("  3. South Bend");
                System.out.println("  4. Bloomington");
    
                choicedest = in.nextInt();
                switch (choicedest){
                    case 1: {
                    System.out.println("Make a selection:");
                    System.out.println("  1. One Way");
                    System.out.println("  2. Round Trip");
    
                    choicett = in.nextInt();
                            switch (choicett) {
                                case 1:
                                    System.out.printf("Cost is $%d. Would you like to purchase?\n", COST_1);
                                    System.out.println("   1. Yes");
                                    System.out.println("   2. No");
                                    choiceconf = in.nextInt();
    
                                    if (choiceconf == 1) {
                                        Chicagotix = Chicagotix +1;
                                        Totalcost = Totalcost +COST_1;
                                    }
    
                    choicett = in.nextInt();
                                    break;
    
                                case 2:
                                {
                                    System.out.printf("Cost is $%d. Would you like to purchase?\n", COST_1*2);
                                    System.out.println("   1. Yes");
                                    System.out.println("   2. No");
                                    choiceconf = in.nextInt();
                                    if (choiceconf == 2) {
                                        Chicagotix = Chicagotix +1;
                                        Totalcost = Totalcost +COST_1*2;
                                    }
                                    break;
                                }
                            }
    
                    }
    break;
                    case 2:
                        System.out.println("Make a selection:");
                        System.out.println("  1. One Way");
                        System.out.println("  2. Round Trip");
                        choicett = in.nextInt();
    
                            switch (choicett) {
                                 case 1:
    
                                    System.out.printf("Cost is $%d. Would you like to purchase?\n", COST_2);
    
                                    System.out.println("   1. Yes");
    
                                    System.out.println("   2. No");
    
                                    choiceconf = in.nextInt();
    
                                    if (choiceconf == 1) {
    
    
                                        IndianapolisTix = IndianapolisTix +1;
    
    
                                        Totalcost = Totalcost +COST_2;
    
                                    }
    
                    break;
    
                    case 2:
    
                    {
    
                        System.out.printf("Cost is $%d. Would you like to purchase?\n", COST_2*2);
    
                        System.out.println("   1. Yes");
    
                        System.out.println("   2. No");
    
                        choiceconf = in.nextInt();
    
                        if (choiceconf == 2) {
                            IndianapolisTix = IndianapolisTix +1;
                            Totalcost = Totalcost +COST_2*2;
                        }
                        break;
                    }
                            }
                            }
    
                        switch (choicett) { //new switch
                                  case 1:
    
                                    System.out.printf("Cost is $%d. Would you like to purchase?\n", COST_3);
    
                                    System.out.println("   1. Yes");
    
                                    System.out.println("   2. No");
    
                                    choiceconf = in.nextInt();
    
                                    if (choiceconf == 1) {
    
    
                                        SouthBendTix = SouthBendTix +1;
    
    
                                        Totalcost = Totalcost +COST_3;
    
                                    }
    
                    break;
    
                    case 2:
    
                    {
    
                        System.out.printf("Cost is $%d. Would you like to purchase?\n", COST_3*2);
    
                        System.out.println("   1. Yes");
    
                        System.out.println("   2. No");
    
                        choiceconf = in.nextInt();
    
                        if (choiceconf == 2) {
    
                            SouthBendTix = SouthBendTix +1;
    
                            Totalcost = Totalcost +COST_3*2;
    
                        }
    
                        break;
                    }
                            }
                            }
    
                        switch (choicett) {
                                    case 1:
                                    System.out.printf("Cost is $%d. Would you like to purchase?\n", COST_4);
                                    System.out.println("   1. Yes");
                                    System.out.println("   2. No");
                                    choiceconf = in.nextInt();
                                    if (choiceconf == 1) {
                                        BloomingtonTix = BloomingtonTix +1;
                                        Totalcost = Totalcost +COST_4;
    
                                    }
    
                    break;
    
                    case 2:
    
                    {
    
                        System.out.printf("Cost is $%d. Would you like to purchase?\n", COST_1*2);
    
                        System.out.println("   1. Yes");
    
                        System.out.println("   2. No");
    
                        choiceconf = in.nextInt();
    
                        if (choiceconf == 2) {
    
                            BloomingtonTix = BloomingtonTix +1;
    
                            Totalcost = Totalcost +COST_1*2;
    
                        }
    
                        break;
                    }
                            }
    
    
                case 2: {
                System.out.println("Return (sell back) ticket to:");
                System.out.println("  1. Chicago");
                System.out.println("  2. Indianapolis");
                System.out.println("  3. South Bend");
                System.out.println("  4. Bloomington");
                choicemm = in.nextInt();
                System.out.printf("Ticket Returned.",COST_1);
    
                break;// return train tickets
    }
    
                case 3: {
                 System.out.printf("Chicago: %d tickets.\n", Chicagotix);
                 System.out.printf("Indianpolis: %d tickets.\n",IndianapolisTix);
                 System.out.printf("South Bend: %d tickets.\n",SouthBendTix);
                 System.out.printf("Bloomington: %d tickets.\n",BloomingtonTix);
                 System.out.printf("Total Cost: %d tickets.\n", Totalcost);
    }
    
       System.out.println("\nWhat would you like to do:");{
    
       System.out.println("  1. Buy Train Ticket(s)");
    
       System.out.println("  2. Return Train Ticket(s)");
    
       System.out.println("  3. Print Info");
    
       System.out.println("  4. Exit\n");
    
                choicemm = in.nextInt();
       }
    
    break;//
    
    }
    }
    }
    }
    
    
    this is what happens:

    I just want it to be like this though:

     
  2. hsmith

    hsmith OT Supporter

    Joined:
    Feb 24, 2002
    Messages:
    124,469
    Likes Received:
    564
    Location:
    Your mother.
    methods are your friend
     
  3. Phasm

    Phasm OT Supporter

    Joined:
    Sep 20, 2005
    Messages:
    9,680
    Likes Received:
    0
    Location:
    Michigan
    I'm taking a java class and fucking hate the language :madfawk:
     
  4. airbball23

    airbball23 Rent this Space only $5/mnth

    Joined:
    Jan 13, 2007
    Messages:
    1,489
    Likes Received:
    0
    welcome to my life mang. welcome to my life.

    btw guys - n/m i figured it out. thanks anyways.

    phasm - i found some helpful videos on youtube:
    http://www.youtube.com/view_play_list?p=FE2CE09D83EE3E28

    check it out :bowdown:
     
  5. Phasm

    Phasm OT Supporter

    Joined:
    Sep 20, 2005
    Messages:
    9,680
    Likes Received:
    0
    Location:
    Michigan

    niceee! will check out :coold: are you pretty decent with java? I'm having some trouble with some of the shit in my class (namely servlets right now) and could use someone that I can pester :o
     
  6. ge0

    ge0 New Member

    Joined:
    Oct 31, 2005
    Messages:
    8,398
    Likes Received:
    0
    Location:
    JERSEY
    use Methods to create your menus... JAVA is OOP... The point of OOP is to reuse your code as much as possible. If you don't use JAVA in its intended purpose then theres no point in using java at all.
     
  7. airbball23

    airbball23 Rent this Space only $5/mnth

    Joined:
    Jan 13, 2007
    Messages:
    1,489
    Likes Received:
    0
    i dont know how to use methods :hs: i guess it might be too late to redo everything and put them in methods
     
  8. airbball23

    airbball23 Rent this Space only $5/mnth

    Joined:
    Jan 13, 2007
    Messages:
    1,489
    Likes Received:
    0
    i'm horrible at java. most of the stuff here OT helped me and my professor helped me and i tried ot piece together everything and try to figure out what to do and try to come up with the rest. :hsugh:
     
  9. airbball23

    airbball23 Rent this Space only $5/mnth

    Joined:
    Jan 13, 2007
    Messages:
    1,489
    Likes Received:
    0
    i'm having one issue now. i'm using the int choicemm for the main menu but it's not working for me?

    i.e.:

    Code:
      switch (choicett) {
                                case 1: {
                                    System.out.printf("Cost is $%d. Would you like to purchase?\n", COST_1);
                                    System.out.println("   1. Yes");
                                    System.out.println("   2. No");
                                    choiceconf = in.nextInt();
    
                                    if (choiceconf == 1) {
                                        Chicagotix = Chicagotix +1;
                                        Totalcost = Totalcost +COST_1;
                                    }
                                }
                                System.out.println("\nWhat would you like to do:");
                                System.out.println("  1. Buy Train Ticket(s)");
                                System.out.println("  2. Return Train Ticket(s)");
                                System.out.println("  3. Print Info");
                                System.out.println("  4. Exit\n");
                    choicemm = in.nextInt();
                                    break;
    i get this:

    Code:
    What would you like to do:
      1. Buy Train Ticket(s)
      2. Return Train Ticket(s)
      3. Print Info
      4. Exit
    
    1
    Buy ticket to:
      1. Chicago
      2. Indianapolis
      3. South Bend
      4. Bloomington
    1
    Make a selection:
      1. One Way
      2. Round Trip
    1
    Cost is $200. Would you like to purchase?
       1. Yes
       2. No
    2
    
    What would you like to do:
      1. Buy Train Ticket(s)
      2. Return Train Ticket(s)
      3. Print Info
      4. Exit
    
    1
    Make a selection:
      1. One Way
      2. Round Trip
    
    but it goes back to make a selection :hsugh:
     

Share This Page