Results 1 to 2 of 2
- 03-07-2013, 11:05 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 8
- Rep Power
- 0
If statment or not an if statement
So was just wondering am doing the bug gift option and wondering how should i go about it, do i use if statment
Java Code:import java.util.Scanner; public class hardwork { public static void main(String args[]) { Scanner input = new Scanner (System.in); int giftpoints[]={2000,1200,700,200,1000}; String gifts[]={"i-pad","PS3","bike","i-pod","Laptop"}; int customerpoints[]={500,1200,300}; String names[]={"James","Joe","Danny"}; int pin[]={111,222,333}; int choices=0; boolean flag=false; int sub=0, userpin=0; String strlogin, strpin, stroption; System.out.print("---- Welcome ----"); System.out.println("\n\nPlease choose an option :\n\n1: Login \n2: Exit\n>"); strlogin=input.next(); while(!strlogin.matches("[1-2]")) { System.out.println("\nError! 1 or 2 only"); System.out.println("\nPlease choose an option :\n\n1: Login \n2: Exit\n>"); strlogin=input.next(); } //End while choices=Integer.parseInt(strlogin); //choices is not valid. do { if (choices == 1) { System.out.print("\nPlease enter Pin: "); strpin = input.next(); while(!strpin.matches("\\d+")){ System.out.println("Incorrect Pin! "); System.out.print("\nPlease enter Pin: "); strpin = input.next(); } userpin=Integer.parseInt(strpin); }//end if choice =1 else{ System.out.print("\n\n"); System.exit(0); }//end else to exit for(int i = 0; i < pin.length; i++) { if (userpin == pin[i]) { flag = true; sub = i; break; } }//end for password if (flag == false) { System.out.println("Incorrect pin!"); }//end if flag is false } while (flag == false); stroption=""; while(!stroption.equals("4")){ System.out.println("\nWelcome : " + names[sub]); System.out.println("Points : " + customerpoints[sub]); System.out.println("\n\nPlease choose an option :\n\n1: View Gifts \n2: Buy Gifts\n3: Add Points\n4: Exit\n>"); stroption=input.next(); while (!stroption.matches("[1-4]") ) { System.out.println("\nError! 1 to 4 only"); System.out.println("\n\nPlease choose an option :\n\n1: View Gifts \n2: Buy Gifts\n3: Add Points\n4: Exit\n>"); stroption=input.next(); }//end while error check choices=Integer.parseInt(stroption); if(choices ==1){ System.out.println("\nId \t Gift \t\t Gift Points:"); for (int i = 0; i < gifts.length; i++) { System.out.println(i+1 + "\t" + gifts[i] + "\t\t\t" + giftpoints[i]); }//end for }//end if else if(choices ==2){ System.out.println("Please enter gift Id"); }//end else if else if(choices ==3){ System.out.println("How many Points do you want to buy? "); int additional_point=input.nextInt(); customerpoints[sub] = customerpoints[sub]+additional_point; }//end else if else{ System.out.print("\n\n"); System.exit(0); }//end else }//end while stroption =4 }//end main method }//end class
- 03-07-2013, 11:10 PM #2
Member
- Join Date
- Feb 2013
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
java gui if statment help
By jumpman8947 in forum New To JavaReplies: 4Last Post: 02-28-2013, 06:12 AM -
Need some help on my if statment.
By ThretZ in forum New To JavaReplies: 1Last Post: 11-06-2012, 04:19 PM -
if statment not working good
By nour in forum New To JavaReplies: 3Last Post: 03-25-2012, 09:29 PM -
If statment not working:(
By Harris68 in forum NetworkingReplies: 6Last Post: 02-24-2010, 10:41 PM -
statment replay!!!
By moamen in forum New To JavaReplies: 4Last Post: 09-25-2009, 12:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks