Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* * 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

More Books

Students also viewed these Databases questions

Question

=+ c. a company president deciding whether to open a new factory

Answered: 1 week ago