Code:   interface Bicycle{ //interface for bicycle     void changeGear(int val); //abstract methods     void changeSpeed(int inc);     void applyBrakes(int dec);     void ringBell(int count);

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Code:

 

interface Bicycle{ //interface for bicycle

    void changeGear(int val); //abstract methods

    void changeSpeed(int inc);

    void applyBrakes(int dec);

    void ringBell(int count);   

}

 

class NewCycle implements Bicycle{ //class for a new cycle

   

    int speed=0; //stores the speed value

    int gear=0; //stores the gear value

   

    @Override

    public void changeGear(int val) { //method to change the gear

        gear=val;

    }

 

    @Override

    public void changeSpeed(int inc) { //method to change the speed

        speed=speed+inc;

    }

 

    @Override

    public void applyBrakes(int dec) { //method to apply brakes

        speed=speed-dec;

    }

 

    @Override

    public void ringBell(int count) { //method to ring the bell

        for(int i=0;i<count;i++){

            System.out.print("Clang!!"+"  ");

        }

        System.out.println("");

    }

    public void printState(){ //method to print the states

        System.out.println("Ring bell, Speed, Gear, Brake, Ring Bell, Ring Bell");

    }

   

}

 

public class BicycleDemo { //application class

    public static void main(String args[]){ //main method

        NewCycle obj=new NewCycle(); //object creation

       

        obj.ringBell(1); //method call to ring the bell

       

        obj.changeSpeed(3); //method call for changing the speed

        System.out.println("Speed of bicycle: "+obj.speed);

       

        obj.changeGear(2); //method call for changing the gear

        System.out.println("Gear of bicycle: "+obj.gear);

       

        obj.applyBrakes(1); //method call for applying brakes

        System.out.println("Speed of bicycle: "+obj.speed);

       

        obj.ringBell(2); //method call to ring the bell

       

        obj.printState(); //method call for printing the states

       

    }

}

Instructions:

Continue the above code(program):

Also:

  • A subclasss of you bicycle class for a mountain bicycle, as described in the section: Classes
  • Your  brand comes with a water bottle (both the generic and mountain type). Add a new field that will keep the percentage of water remaining in the bottle (1 full, 0 emptty, 0.5 half empty), as described in the section: Declaring member variables. The water bottle is emptty by default.
  • Declare a method to completely fill the water bottle. Declare a method to completely drink the water. No parameters needed. See: Defining methods.
  • Declare a method that will specify how much to fill the water bottle, as a percentage. If the bottle has already that quantity, do nothing. The method must have the same name as above. A parameter is needed.
  • Declare a method that will specify how much to drink from the water as a percentage. The method must have the same name as above. A parameter is needed. 
  • Create a new constructor that will specify the initial cadence, gear and water level. See: Providing Constructors for Your Classes
  • Create another class, with a main method, in which you will take a trip aroound your house in your mountain bicycle, changing your bicycle attributes, starting and ending from a complete stop, and ringing the bell twice at start and once at the end. You must start with 3/4 filled water bottle, and dring some water once.
  • Your trip must have at least 5 different parts in which you change your bicycle state and print its state (starting and ending from a rest state).
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education