//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.
import java.io.*;
class Flipkart{
Boolean ifLogged=false; //to check if logged.
static String keyName,keyPassword,name,password,address;//passwords and keys
Flipkart(String keyName, String keyPassword){
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 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)
System.exit(2);
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);
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) {
e.printStackTrace();
System.out.println("Enter only \' 1 \' or \'0\'");
}
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\n 3. Exit\n Enter a Value: ");
int a= Integer.parseInt(b.readLine());
if(a==1) {
login();
Shop();
}
else if (a==2)
Shop();
else
System.exit(1);
}
public static void main(String s[]) throws Exception {
Flipkart f = new Flipkart("12ka4","42ka1");
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.