Question: /* * Bicycle class * This class models basic state and behavior * for Bicycles. The class contains: * - 2 example private members, speed

 /* * Bicycle class * This class models basic state and behavior * for Bicycles. The class contains: * - 2 example private members, speed and gear * - 2 constructors * - Accessor methods * - Mutator methods * - Other general purpose methods * * */ public class Bicycle { /* * members */ private int speed = 0; private int gear = 1; /* * constructors */ // no argument constructor public Bicycle() { } public Bicycle( int sp, int gr) { this.speed = sp; this.gear = gr; } /* * Methods */ public void speedUp(int amount) { speed = speed + amount; } public void slowDown(int amount) { speed = speed - amount; } /* * accessor methods */ public int getSpeed() { return speed; } public int getGear() { return gear; } /* * mutator methods */ public void setGear(int newValue) { this.gear = newValue; } public void setSpeed(int newSpeed) { this.speed = newSpeed; } } ///~

Create a class that uses the Bicycle class (download Bicycle.java from above )

Call the class BicycleDemo.java

This class will contain the main method

BicycleDemo.java must be in the same directory as Bicycle.java from above

Compile with javac *.java

Create two new Bicycle objects using constructors

Use the no-arg constructor

Use the constructor with arguments

Use accessors and mutators

set gear and speed of bike 1

set gear and speed of bike 2

get gear and speed of bike 1 and print

get gear and speed of bike 2 and print

Attempt to access members directly from demo program. What happens?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!