0% found this document useful (0 votes)
15 views3 pages

Oop 5

SPPU SE IT OOP 5th Practical

Uploaded by

dhonevaibhav785
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Oop 5

SPPU SE IT OOP 5th Practical

Uploaded by

dhonevaibhav785
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment No.

05

Name:
Roll.No.:

/* Design and develop a context for given case study and implement an interface for Vehicles Consider
the example of vehicles like bicycle, 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 own class in their
own way. */

Source Code :
import java.util.*;
interface Vehicles
{
void speedUp();
void applyBreaks();
void gearChange();
}

class Bycicle implements Vehicles{


public void gearChange()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter Gear :");
int a=sc.nextInt();
if(a!=0)
{
a++;
}
System.out.println("Gear changed of Bycicle:" + a);
}
public void speedUp(){
Scanner sc=new Scanner(System.in);
System.out.println("Enter speed :");
int a=sc.nextInt();
if(a!=50)
{
a=a+10;
}
System.out.println("Speed of Bycicle is changed to :" + a);
}
public void applyBreaks(){
System.out.println("Applied breaks of Bycicle");
}
}

class Bike implements Vehicles{


public void gearChange()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter Gear :");
int a=sc.nextInt();
if(a!=0)
{
a++;
}
System.out.println("Gear changed of Bike to :" +a);
}
public void speedUp(){
Scanner sc=new Scanner(System.in);
System.out.println("Enter speed :");
int a=sc.nextInt();
if(a!=50)
{
a=a+10;
}
System.out.println("Speed of Bike is changed to:"+a);
}
public void applyBreaks(){
System.out.println("Applied breaks of Bike");
}
}

class Car implements Vehicles{


public void gearChange()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter Gear :");
int a=sc.nextInt();
if(a!=0)
{
a++;
}
System.out.println("Gear changed of Car:" +a);
}
public void speedUp(){
Scanner sc=new Scanner(System.in);
System.out.println("Enter speed :");
int a=sc.nextInt();
if(a!=50)
{
a=a+10;
}
System.out.println("Speed of Car is changed to:"+a);
}
public void applyBreaks(){
System.out.println("Applied breaks of Car");
}
}

class Interfaces
{
public static void main(String[] args) {
Vehicles v;
v= new Bycicle();
System.out.println("--Bycicle--");
v.gearChange();
v.speedUp();
v.applyBreaks();

v= new Bike();
System.out.println("--Bike--");
v.gearChange();
v.speedUp();
v.applyBreaks();

v= new Car();
System.out.println("--Car--");
v.gearChange();
v.speedUp();
v.applyBreaks();
}
}

Output :
--Bycicle--
Enter Gear : 1
Gear changed of Bycicle:2
Enter speed : 20
Speed of Bycicle is changed to :30
Applied breaks of Bycicle

--Bike--
Enter Gear : 2
Gear changed of Bike to :3
Enter speed : 60
Speed of Bike is changed to: 70
Applied breaks of Bike

--Car--
Enter Gear : 3
Gear changed of Car: 4
Enter speed : 80
Speed of Car is changed to:90
Applied breaks of Car

Process finished with exit code 0

You might also like