You are on page 1of 7
import java.io.*; interface information { public void info1(); } class dis implements information { public String s,admin; public final String PWD="vehicle"; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); public void set() { admin="admin"; System.out.println(admin); } public String get() { return admin; } public String toString() //toString { } return PWD; public void info1() { try { System.out.print("Enter a Password :"); s=br.readLine(); if(s.equals(PWD)) { System.out.println("User logged in successfully!"); } else { System.out.println("Wrong password!"); System.exit(0); } } catch(Exception e) { } finally { REGISTRATION"); } } abstract class Vehicle { public static String vehicle_type, reg_date, mfg_date, reg_no, chassis_no, eng_no, owner_name, owner_addr, makers_name, makers_class, color,reg_upto, fuel_cap, weight; public static int no_cylinder,seating_cap,cubic_cap; public void AcceptInfo() throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter Registration No:"); reg_no = in.readLine(); System.out.println("Enter registration date"); reg_date=in.readLine(); System.out.println("Enter Chassis No:"); chassis_no = in.readLine(); System.out.println("Enter Engine No::"); eng_no = in.readLine(); System.out.println("Enter Owner Name:"); owner_name = in.readLine(); System.out.println("Enter Owner Address:"); owner_addr = in.readLine(); System.out.println("Enter Makers Name:"); makers_name = in.readLine(); System.out.println("Enter Makers Class:"); makers_class = in.readLine(); System.out.println("Enter manufacturing Date"); mfg_date = in.readLine(); System.out.println("Enter Color:"); color = in.readLine(); System.out.println("Enter No. of Cylinders:"); no_cylinder = Integer.parseInt(in.readLine()); } System.out.println("WELCOME TO VEHICLE try{ System.out.println("Enter Fuel Capacity::"); fuel_cap = in.readLine(); System.out.println("Enter Weight:"); weight = in.readLine(); System.out.println("Enter Seating Capacity:"); seating_cap = Integer.parseInt(in.readLine()); System.out.println("Enter Cubic Capacity:"); cubic_cap = Integer.parseInt(in.readLine()); } catch(NumberFormatException n) { System.out.println("Enter numbers only"); } System.out.println("Enter Registered Upto:"); reg_upto = in.readLine(); } public void DisplayInfo() { System.out.println("Vehicle Type:" + vehicle_type); System.out.println("Registration No:" + reg_no); System.out.println("Chasis No:" + chassis_no); System.out.println("Engine No::" + eng_no); System.out.println("Owner Name:" + owner_name); System.out.println("Owner Address:" + owner_addr); System.out.println("Makers Name:" + makers_name); System.out.println("Makers Class:" + makers_class); System.out.println("Color:" + color); System.out.println("No. of Cylinders:" + no_cylinder); System.out.println("Fuel Capacity::" + fuel_cap); System.out.println("Weight:" + weight); System.out.println("Seating Capacity:" + seating_cap); System.out.println("Cubic Capacity:" + cubic_cap); System.out.println("Registered Upto:" + reg_upto); } abstract public void done(); } class Twowheeler extends Vehicle { int age; String s; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); public void AgeTwo() throws IOException { try { if (age < 16) { System.out.println("Cannot Register for 2 wheeler"); } } catch (Exception e) { System.out.println("Exception Catched" + e); } } public void Accepttwo() throws IOException { AcceptInfo(); } public void Disptwo() { DisplayInfo(); } public void done() { s="Done with two wheeler registration"; System.out.println(s); } } class Fourwheeler extends Twowheeler { public static int age; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); /* public String toString() { return age; }*/ public void AgeFour() { try { if (age < 21) { System.out.println("Cannot Register for 4 wheeler"); } } catch (Exception e) { System.out.println("Exception Catched" + e); } } public void Acceptfour() throws IOException { } Accepttwo(); public void Dispfour() { } Disptwo(); public void done() { String a="Done with four wheeler registration"; } public void done(String a) { System.out.println("You will receive registration card "+a); } } class Myexp extends Exception { Myexp(String Message) { super(Message); } } class VehicleMain { public static void main(String args[]) throws IOException { int ch; int ch1; int age; String c; Fourwheeler ob = new Fourwheeler(); dis p =new dis(); dis d1 = new dis(); do { d1.info1(); p.set(); c=p.get(); System.out.println(c); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Vehicle Types->"); System.out.println("1.Two Wheeler\n2.Four Wheeler\n3.Exit"); System.out.println("\nEnter Vehicle Type:"); ch = Integer.parseInt(in.readLine()); switch (ch) { case 1: System.out.println("\nEnter type"); System.out.println("1.Without gear"); System.out.println("2.With gear"); ch1=Integer.parseInt(in.readLine()); switch (ch1) { case 1: System.out.println("Enter the age"); age = Integer.parseInt(in.readLine()); if (age >16) { System.out.println("\nTwo Wheeler Details:"); ob.Accepttwo(); ob.Disptwo(); } else { allowed to register"); } System.exit(0); break; System.out.println("\nEnter the age:"); age=Integer.parseInt(in.readLine()); if(age<18) { throw new Myexp("Not allowed to register"); } else { Wheeler Details:"); try { throw new Myexp("Not case 2: System.out.println("\nTwo ob.Accepttwo(); ob.Disptwo(); } System.exit(0); break; } } catch (Myexp e) { System.out.println(e.getMessage()); } catch(NumberFormatException n) { System.out.println("Enter numbers only"); } break; case 2: System.out.println("\nFour Wheeler Details:"); ob.Acceptfour(); ob.Dispfour(); ob.done(); ob.done("within a month"); break; case 3: System.exit(0); break; } }while(ch!=3); } }