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);
}
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