Permalink
- Write A Program To Create An Object Car
- Write A Class Named Car That Has The Following Fields Youtube
Join GitHub today
Windows 10 default player. GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign up Find file Copy path
AndroxxTraxxonEmployee and Car classes from MyProgramingLab42be65dMar 1, 2015
1 contributor
/* |
* Write a class named Car that has the following fields: |
• yearModel: The yearModel field is an int that holds the car's year model. |
• make: The make field is a String object that holds the make of the car. |
• speed: The speed field is an int that holds the car's current speed. |
In addition, the class should have the following methods : |
• Constructor : The constructor should accept the car's year model and make as arguments . |
These values should be assigned to the object 's yearModel and make fields. The |
constructor should also assign 0 to the speed field. |
• Accessor: The appropriate accessor methods should be implemented to access the values |
stored in the object 's yearModel, make, and speed fields. |
• accelerate: The accelerate method should add 5 to the speed field when it is called. |
• brake: The brake method should subtract 5 from the speed field each time it is called. |
Demonstrate the class by adding a main method that creates a Car object (use the year 1965 and the make 'Bat Mobile' and then calls the |
accelerate method five times. After each call to the accelerate method , get the current |
speed of the car and print it on a separate line. Then, call the brake method five times, |
each time printing the current speed of the car on a separate line. |
*/ |
publicclassCar { |
privateint yearModel; |
privateString make; |
privateint speed; |
publicCar(intyear, Stringmk){ |
yearModel = year; |
make = mk; |
speed =0; |
} |
publicstaticvoidmain(String[] args) { |
Car bat =newCar(1965, 'Bat Mobile'); |
bat.accellerate(); |
System.out.println(bat.getSpeed()); |
bat.accellerate(); |
System.out.println(bat.getSpeed()); |
bat.accellerate(); |
System.out.println(bat.getSpeed()); |
bat.accellerate(); |
System.out.println(bat.getSpeed()); |
bat.accellerate(); |
System.out.println(bat.getSpeed()); |
bat.brake(); |
System.out.println(bat.getSpeed()); |
bat.brake(); |
System.out.println(bat.getSpeed()); |
bat.brake(); |
System.out.println(bat.getSpeed()); |
bat.brake(); |
System.out.println(bat.getSpeed()); |
bat.brake(); |
System.out.println(bat.getSpeed()); |
} |
publicintgetYearModel() { |
return yearModel; |
} |
publicvoidsetYearModel(intyearModel) { |
this.yearModel = yearModel; |
} |
publicStringgetMake() { |
return make; |
} |
publicvoidsetMake(Stringmake) { |
this.make = make; |
} |
publicintgetSpeed() { |
return speed; |
} |
publicvoidsetSpeed(intspeed) { |
this.speed = speed; |
} |
publicvoidaccellerate(){ |
speed +=5; |
} |
publicvoidbrake(){ |
speed -=5; |
if (speed <0) speed =0; |
} |
} |
Copy lines Copy permalink
Week 5 (Objects) Assignment
Write A Program To Create An Object Car
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
Tiberium Pack is a mod for Zoo Tycoon: Dinosaur Digs, created by.Description:A small fan-made expansion pack that adds animals, plants and other assets from the games 'Tiberian Sun' and 'Firestorm'.This pack adds new animals and items from Tiberian Sun and Firestorm into Zoo Tycoon, allowing you to build your own Tiberium-based ecosystems for your guests' entertainment.Not only will the new Tiberium crystals and foliage make your Tiberium creatures happy, you can also experiment around and put them in other animals' exhibits, creating new and interesting Tiberium-infested worlds.
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
Write A Class Named Car That Has The Following Fields Youtube
I am listing those questions here as well for your convenience:
Question 2. Car Class
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.Question 4. RetailItem Class
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.Setup for Github
- 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