PRG421 Week 1 Individual Coding Assignment Object-Oriented Programming Concepts

$ 10

PRG421 Week 1 Individual Coding Assignment Object-Oriented Programming Concepts

For this assignment, you will modify existing code to create a single Java™ program named BicycleDemo.java that incorporates the following:

An abstract Bicycle class that contains private data relevant to all types of bicycles (cadence, speed, and gear) in addition to one new static variable: bicycleCount. The private data must be made visible via public getter and setter methods; the static variable must be set/manipulated in the Bicycle constructor and made visible via a public getter method.
Two concrete classes named MountainBike and RoadBike, both of which derive from the abstract Bicycle class and both of which add their own class-specific data and getter/setter methods.

Read through the “Lesson: Object-Oriented Programming Concepts” on The Java™ Tutorials website.
Download the linked Bicycle class, or cut-and-paste it at the top of a new Java™ project named BicycleDemo.
Download the linked BicycleDemo class, or cut-and-paste it beneath the Bicycle class in the BicycleDemo.java file.
Optionally, review this week’s Individual “Week One Analyze Assignment,” to refresh your understanding of how to code derived classes.

Adapt the Bicycle class by cutting and pasting the class into the NetBeans editor and completing the following:
Change the Bicycle class to be an abstract class.
Add a private variable of type integer named bicycleCount, and initialize this variable to 0.
Change the Bicycle constructor to add 1 to the bicycleCount each time a new object of type Bicycle is created.
Add a public getter method to return the current value of bicycleCount.
Derive two classes from Bicycle: MountainBike and RoadBike. To the MountainBike class, add the private variables tireTread (String) and mountainRating (int). To the RoadBike class, add the private variable maximumMPH (int).
Using the NetBeans editor, adapt the BicycleDemo class as follows:
Create two instances each of MountainBike and RoadBike.
Display the value of bicycleCount on the console.
Comment each line of code you add to explain what you added and why. Be sure to include a header comment that includes the name of the program, your name, PRG/421, and the date.
Rename your JAVA file to have a .txt file extension.
Submit your TXT file to the Assignment Files tab.

package bicycledemo;

class Bicycle {
int cadence = 0;
int speed = 0;
int gear = 1;

void changeCadence(int newValue) {
cadence = newValue;
}

void changeGear(int newValue) {
gear = newValue;
}

void speedUp(int increment) {
speed = speed + increment;  
}

void applyBrakes(int decrement) {
speed = speed – decrement;
}

void printStates() {
System.out.println(“cadence:” +
cadence + ” speed:” +
speed + ” gear:” + gear);
}
}
class BicycleDemo {
public static void main(String[] args) {

// Create two different
// Bicycle objects
Bicycle bike1 = new Bicycle();
Bicycle bike2 = new Bicycle();

// Invoke methods on
// those objects
bike1.changeCadence(50);
bike1.speedUp(10);
bike1.changeGear(2);
bike1.printStates();

bike2.changeCadence(50);
bike2.speedUp(10);
bike2.changeGear(2);
bike2.changeCadence(40);
bike2.speedUp(10);
bike2.changeGear(3);
bike2.printStates();
}
}

996 in stock

SKU: PRG421W1CODING Categories: ,

Description

PRG421 Week 1 Individual Coding Assignment Object-Oriented Programming Concepts

For this assignment, you will modify existing code to create a single Java™ program named BicycleDemo.java that incorporates the following:

An abstract Bicycle class that contains private data relevant to all types of bicycles (cadence, speed, and gear) in addition to one new static variable: bicycleCount. The private data must be made visible via public getter and setter methods; the static variable must be set/manipulated in the Bicycle constructor and made visible via a public getter method.
Two concrete classes named MountainBike and RoadBike, both of which derive from the abstract Bicycle class and both of which add their own class-specific data and getter/setter methods.

Read through the “Lesson: Object-Oriented Programming Concepts” on The Java™ Tutorials website.
Download the linked Bicycle class, or cut-and-paste it at the top of a new Java™ project named BicycleDemo.
Download the linked BicycleDemo class, or cut-and-paste it beneath the Bicycle class in the BicycleDemo.java file.
Optionally, review this week’s Individual “Week One Analyze Assignment,” to refresh your understanding of how to code derived classes.

Adapt the Bicycle class by cutting and pasting the class into the NetBeans editor and completing the following:
Change the Bicycle class to be an abstract class.
Add a private variable of type integer named bicycleCount, and initialize this variable to 0.
Change the Bicycle constructor to add 1 to the bicycleCount each time a new object of type Bicycle is created.
Add a public getter method to return the current value of bicycleCount.
Derive two classes from Bicycle: MountainBike and RoadBike. To the MountainBike class, add the private variables tireTread (String) and mountainRating (int). To the RoadBike class, add the private variable maximumMPH (int).
Using the NetBeans editor, adapt the BicycleDemo class as follows:
Create two instances each of MountainBike and RoadBike.
Display the value of bicycleCount on the console.
Comment each line of code you add to explain what you added and why. Be sure to include a header comment that includes the name of the program, your name, PRG/421, and the date.
Rename your JAVA file to have a .txt file extension.
Submit your TXT file to the Assignment Files tab.

package bicycledemo;

class Bicycle {
int cadence = 0;
int speed = 0;
int gear = 1;

void changeCadence(int newValue) {
cadence = newValue;
}

void changeGear(int newValue) {
gear = newValue;
}

void speedUp(int increment) {
speed = speed + increment;  
}

void applyBrakes(int decrement) {
speed = speed – decrement;
}

void printStates() {
System.out.println(“cadence:” +
cadence + ” speed:” +
speed + ” gear:” + gear);
}
}
class BicycleDemo {
public static void main(String[] args) {

// Create two different
// Bicycle objects
Bicycle bike1 = new Bicycle();
Bicycle bike2 = new Bicycle();

// Invoke methods on
// those objects
bike1.changeCadence(50);
bike1.speedUp(10);
bike1.changeGear(2);
bike1.printStates();

bike2.changeCadence(50);
bike2.speedUp(10);
bike2.changeGear(2);
bike2.changeCadence(40);
bike2.speedUp(10);
bike2.changeGear(3);
bike2.printStates();
}
}

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.