Myntra problem

//exit code 1: when self exit from main menu! //exit code 2: when self exit from shopp menu! //exit code 3: when invalid login credentials given. //exit code 4: when invalid login credentials given. import java.io.*; class Flipkart{ int deliveryCharge; Boolean ifLogged=false; //to check if logged. static String keyName,keyPassword,name,password,address,city,city1,city2,city3;//passwords and keys Flipkart(String keyName, String keyPassword){ city1="Hyderabad"; city2="Bangalore"; city3="Chennai"; this.keyName= keyName; this.keyPassword= keyPassword; address="6 No.,malakpet,USA";// malakpet oldcity me aata new city me aata?... } void login() throws IOException{ InputStreamReader i = new InputStreamReader(System.in); BufferedReader b = new BufferedReader(i); System.out.println("To login ......"); System.out.println("Enter Your City : "); System.out.println("1. "+city1); System.out.println("2. "+city2); System.out.println("3. "+city3); System.out.println("4. Exit"); int a= Integer.parseInt(b.readLine()); if (a==1) { city = city1; deliveryCharge=149; } else { if (a == 2) { city = city2; deliveryCharge=49; } else { if (a == 3) { city = city3; deliveryCharge = 249; } else if (a == 4) { System.exit(4); } } } System.out.println("Enter Name : "); try { name=new String(b.readLine()); } catch (IOException e) { e.printStackTrace(); System.out.println("Enter a valid Username!"); } System.out.println("Enter Password!"); try { password=new String(b.readLine()); } catch (IOException e) { e.printStackTrace(); System.out.println("Enter a valid password!"); } // System.out.println(name +" "+keyName+" "+password+" "+keyPassword ); //System.out.println((password.equals(keyPassword)) && (name.equals(keyName)) ); if((password.equals(keyPassword)) && (name.equals(keyName))){ //validating with keys... ifLogged = true; } else{ System.out.println("Invalid login credentials...\n Try again.."); System.exit(3); } } } class Myntra extends Flipkart{ String m1,m2,m3,item; Myntra(String m1, String m2, String m3){ super(keyName,keyPassword); this.m1=m1; this.m2=m2; this.m3=m3; } void Shop() throws Exception{ InputStreamReader i = new InputStreamReader(System.in); BufferedReader b = new BufferedReader(i); System.out.println("Let's Shop!!"); System.out.println("1. "+m1); System.out.println("2. "+m2); System.out.println("3. "+m3); System.out.println("4. Exit"); System.out.println("Enter choice !"); int a= Integer.parseInt(b.readLine()); if (a==1) item=m1; else if(a==2) item=m2; else if (a==3) item=m3; else if (a==4) { TheMenu(); System.exit(5); } else if (a==5) { System.out.println("THANKS FOR SHOPPING AT US...."); System.exit(3); } if(ifLogged) checkout(); else{ System.out.println("First Login!"); login(); checkout(); } } void checkout() throws Exception { int confirm=0; System.out.println("The item "+item+" will be shipped for \n"+name+"\n at "+address+"\n and the deliver charges are "+deliveryCharge); InputStreamReader i = new InputStreamReader(System.in); BufferedReader b = new BufferedReader(i); System.out.println("To Confirm Enter 1/0..."); try { confirm = Integer.parseInt(b.readLine()); } catch (IOException e) { System.out.println("Enter only \' 1 \' or \'0\'"); e.printStackTrace(); } if (confirm ==1) System.out.println("Confirmed!!"); else { System.out.println("Order Cancelled"); } Shop(); } void TheMenu() throws Exception { InputStreamReader i = new InputStreamReader(System.in); BufferedReader b = new BufferedReader(i); System.out.println("MENU\n1. Login\n 2. Shop \n3. Logout \n 4. Exit\n Enter a Value: "); int a= Integer.parseInt(b.readLine()); if(a==1) { login(); Shop(); } else if (a==2) Shop(); else if(a==3){ ifLogged=false; System.out.println("You have sucessfully logged out..."); TheMenu(); } else System.exit(1); } public static void main(String s[]) throws Exception { Flipkart f = new Flipkart("omer","professional"); Myntra m =new Myntra("Shoe","jeans","Shirts"); m.TheMenu(); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.