Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

    Default help with switch statement

    this is part of my statement, the problem is that it just runs through the whole statement not allowing me to insert the reference number or the amount to add

    case 2: // the second case statement will add points to a customers account

    System.out.printf("%-45s %n %n", "********************************************* ");

    System.out.printf("%35s %n %n", " Adding Points");

    System.out.printf("%-45s %n %n", "********************************************* ");

    System.out.println("Please input your customer reference number");
    System.out.println("Please input the amount of money spent in store in pounds");

    int refNumber = 234561;
    if (refNumber == c2.getrefNumber());{

    System.out.println("Number of points held before update:" + c2.currentPoints);
    System.out.println("Number of points held after update:" + newTot);
    }
    if(refNumber == c3.getrefNumber());{
    System.out.println("Number of points held before update:" + c3.currentPoints);
    System.out.println("Number of points held after update:" + newTot);
    }
    if (refNumber == c1.getrefNumber());{
    System.out.println("Number of points held before update:" + c1.currentPoints);
    System.out.println("Number of points held after update:" + newTot);
    }

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Well, I don't see where you are actually attempting to get it. I see where you "ask" for it, but you never attempt to read any user intput.

  3. #3
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    You need a loop to check if there's been any input - it never 'pauses' here, just runs through, as you said.
    I die a little on the inside...
    Every time I get shot.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    MClairine's Avatar
    MClairine is offline Member
    Join Date
    Mar 2009
    Location
    Indonesia
    Posts
    1
    Rep Power
    0

    Lightbulb You must make Input Buffer

    I think this sample code, can solve your problem

    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.IOException;

    /**
    * Created by IntelliJ IDEA.
    * User: michael
    * Date: Mar 19, 2009
    * Time: 7:51:12 PM
    * To change this template use File | Settings | File Templates.
    */
    public class JavaInput {
    public void JavaInput() throws IOException
    {


    System.out.println("Please input your customer reference number");
    System.out.println("Please input the amount of money spent in store in pounds");

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String getrefNumber = br.readLine();
    int getrefNumberInt = Integer.parseInt(getrefNumber);


    int refNumber = 234561;
    if (refNumber == getrefNumberInt)
    {
    System.out.println("same");
    }
    else if(refNumber == getrefNumberInt)
    {
    System.out.println("not same");
    }


    }

    public static void main(String args[])
    {
    JavaInput ji = new JavaInput();
    try
    {
    ji.JavaInput();
    }
    catch(Exception ex)
    {

    }
    }
    }


    thanx

Similar Threads

  1. Demonstration of the switch statement
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 08:08 PM
  2. Method in a Switch Statement
    By cart1443 in forum New To Java
    Replies: 6
    Last Post: 03-14-2008, 03:48 AM
  3. Switch Statement Help
    By bluegreen7hi in forum New To Java
    Replies: 6
    Last Post: 02-06-2008, 05:16 AM
  4. Replies: 0
    Last Post: 01-04-2008, 09:32 AM
  5. Help with gigantamous switch statement
    By trill in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 08:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •