This week to assure that we all have the opportunity to uniformly create the same work so we can focus on best practices when creating objects in Java I am opting to use 2 questions from your book's Programming Challenges section for chapter 6. Questions 2 and 4 on pg 396
Please follow the design rules we identified in class so do not create set style methods unless asked to. The book references these as "mutator" methods we have been calling them "setters". Also order you class in the standard format:
- Fields
- Constructor
- Accessor/Mutators
- Public API
- Private API
I will be grading these more specifically for adherence to design and style so keep that in mind and try to point these mistakes out to your peers in review.
My rubric is:
- proper indentation
- proper order of elements
- well documented classes and methods
I am listing those questions here as well for your convenience:
Write a class named Car that has the following fields:
- yearModel. The
yearModel
field is anint
that holds the car's year model. - make. The
make
field references aString
object that holds the make of the car. - speed. The
speed
field is anint
that holds the car's current speed. In addition, the class should have the following constructor and other methods. - Constructor. The constructor should accept the car's
yearModel
andmake
fields. The constructor should also assign0
to thespeed
field. - Accessors. Appropriate
accessor
methods shouldget
values stored in an object'syearModel
,make
, andspeed
fields. - accelerate. The
accelerate
method should add5
to the speed field each time it is called. - brake. The
brake
method should subtract5
from thespeed
feild each time it is called.
Demonstrate the class in a program that creates a Car
object, and then calls the accelerate
method 5 times. After each call to accelerate
method, get the current speed of the car and display it. Then call the brake
method 5 times. After each call to the brake
method, get the current speed of the car and display it.
Write a class
named RetailItem
that holds data about an item in a retail store. The class should have the following fields.
- description. The
description
field references aString
object that holds a brief description of the item. - unitsOnHand. The
unitsOnHand
field is anint
variable that holds the number of units currently in the inventory. - price. The price field is a
double
that holds the item's retail price.
Write a constructor that accepts arguments for each field, appropriate mutator
methods that store values in these fields, and accessor
methods that return the values in these fields. Once you have written the class, write a separate program that creates 3 RetailItem
objects and stores any appropriate data you like in them.
- Fork the repo to your personal account
- Clone your fork to your local computer
- From Github Desktop
- click the + on the top left
- select clone then search for
CPT-163-27-F2015-Assignment-5-objects
use the one under the section with your github name
- From Command Line
- Copy the
https
link from your fork on github.com (its below the settings button on the right hand side of the page) - run
git clone <copied url>
(this will create a folder the same name as the repo in the directory you ran this command)
- Copy the
- From Github Desktop
- Create a branch on your fork of the Assignment-5 Repo using the format /<feature_description>
- From Github Desktop
- Click the
Add a Branch
button (It should be the button next to the dropdown that saysmaster
) - Make sure you create your branch from master
- Click the
- From Command Line
- run
git checkout -b <branch_name>
- run
- From Github Desktop
- In Netbeans create a new project and set the Project Directory to the folder that was created when you cloned your fork.
- Write Code!
- Create a commit
- From Github Desktop
- Select your fork and fill-in the commit summary
- Click
Sync
- From Command Line
- run
git add .
- run
git commit -m "<your commit message>"
- run
git push origin <your_branch_name>
- run
- From Github Desktop
- Go to Github.com and open your PR by clicking on
Compare and Open Pull Request