Assignment 5
Assignment 5
//Problem Statement::
/*
Design and develop a context for given case study and implement an
car and bike. All Vehicles have common functionalities such as Gear Change,
Speed up and apply breaks. Make an interface and put all these common functionalities.
Bicycle, Bike, Car classes should be implemented for all these functionalities in their
*/
import java.util.*;
void speed_up();
void apply_brakes();
void display();
//BICYCLE CLASS
int gear,speed;
gear=gearex;
else
speed+=5;
else
int x;
x=sc.nextInt();
if(x==1)
else {
speed=0;
gear=0;
speed=0;
gear=0;
}
class car implements vehicle
int gear,speed;
car()
this.gear=gearex;
else
speed+=20;
}
else
int x;
x=sc.nextInt();
if(x==1)
else {
speed=0;
gear=0;
if(x==2)
speed=0;
gear=0;
}
public void display() //displays current status of car
//BIKE CLASS
bike()
gear=gearex;
else
}
public void speed_up()
speed+=20;
else
int x;
x=sc.nextInt();
if(x==1)
else {
speed=0;
gear=0;
System.out.println("Bike stopped Successfully \n");}
if(x==2)
speed=0;
gear=0;
System.out.println("===========================================================
===========");
do {
System.out.print(" SELECT VEHICLE \n\t1.BICYCLE \n\t2.CAR \n\t3.BIKE
\n\t4.Exit \nChoice::");
y=sc.nextInt();
System.out.println("=================================================================
=====");
if(y==1)
else if(y==2)
else if(y==3)
else if(y==4)
else
System.out.println("INVALID INPUT");
System.out.println("===========================================================
===========");
if(0<y&&y<4) {
do {
int z=sc.nextInt();
System.out.println("===========================================================
===========");
switch(z)
{
case 1:
v.speed_up();
System.out.println("===========================================================
===========");
break;
case 2:
int a=sc.nextInt();
v.gear_change(a);
System.out.println("===========================================================
===========");
break;
case 3:
v.apply_brakes();
System.out.println("===========================================================
===========");
break;
case 4:
v.display();
System.out.println("===========================================================
===========");
break;
case 5:
default:
System.out.println("Invalid Input");
}
}while(true);
/*
##OUTOUT##
======================================================================
SELECT VEHICLE
1.BICYCLE
2.CAR
3.BIKE
4.Exit
Choice::1
======================================================================
======================================================================
Press 1. Speed Up
Choice::1
======================================================================
current speed is 15
======================================================================
Press 1. Speed Up
Choice::1
======================================================================
current speed is 20
======================================================================
Press 1. Speed Up
Choice::2
======================================================================
Current Gear Is 3
======================================================================
Press 1. Speed Up
Press 2. Change gear
Choice::3
======================================================================
1. DECREASE SPEED
2. STOP BICYCLE
======================================================================
Press 1. Speed Up
Choice::3
======================================================================
1. DECREASE SPEED
2. STOP BICYCLE
======================================================================
Press 1. Speed Up
Choice::3
======================================================================
1. DECREASE SPEED
2. STOP BICYCLE
======================================================================
Press 1. Speed Up
Choice::4
======================================================================
======================================================================
Press 1. Speed Up
Choice::5
======================================================================
SELECT VEHICLE
1.BICYCLE
2.CAR
3.BIKE
4.Exit
Choice::2
======================================================================
======================================================================
Press 1. Speed Up
Choice::1
======================================================================
======================================================================
Press 1. Speed Up
Choice::1
======================================================================
======================================================================
Press 1. Speed Up
Choice::2
======================================================================
======================================================================
Press 1. Speed Up
Choice::2
======================================================================
Current Gear is 4
======================================================================
Press 1. Speed Up
Choice::3
======================================================================
1. TO DECREASE SPEED
2. TO STOP CAR
======================================================================
Press 1. Speed Up
Choice::3
======================================================================
1. TO DECREASE SPEED
2. TO STOP CAR
======================================================================
Press 1. Speed Up
Choice::4
======================================================================
======================================================================
Press 1. Speed Up
Choice::5
======================================================================
SELECT VEHICLE
1.BICYCLE
2.CAR
3.BIKE
4.Exit
Choice::3
======================================================================
======================================================================
Press 1. Speed Up
Choice::1
======================================================================
======================================================================
Press 1. Speed Up
Choice::2
======================================================================
which gear you want? 6
======================================================================
Press 1. Speed Up
Choice::2
======================================================================
Current Gear IS 3
======================================================================
Press 1. Speed Up
Choice::3
======================================================================
1. TO DECREASE SPEED
2. TO STOP bike
======================================================================
Press 1. Speed Up
Press 2. Change gear
Choice::4
======================================================================
======================================================================
Press 1. Speed Up
Choice::3
======================================================================
1. TO DECREASE SPEED
2. TO STOP bike
======================================================================
Press 1. Speed Up
Choice::5
======================================================================
SELECT VEHICLE
1.BICYCLE
2.CAR
3.BIKE
4.Exit
Choice::6
======================================================================
INVALID INPUT
======================================================================
SELECT VEHICLE
1.BICYCLE
2.CAR
3.BIKE
4.Exit
Choice::4
======================================================================
*/