Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description: In this assignment, we will learn about Object Oriented Programming by creating an application that uses Java classes to manage multiple cars and their

Description:

In this assignment, we will learn about Object Oriented Programming by creating an application that uses Java classes to manage multiple cars and their gas mileage.

Requirements:

You should not use static/global variables or methods anywhere in this assignment.

Step 1:

Create a new Java project in NetBeans called Assignment2

Create a new Java Class in that project called "Car"

Step 2:

Implement a properly encapsulated "Car" class that has the following attributes:

The brand of the car (e.g. Honda)

Odometer reading (distance traveled since new)

Total fuel consumed since new

and methods to perform the following tasks:

Set the brand of the car

Set the odometer reading

Set the total fuel consumed since new

Return all info about the car (you may want to call this method getInfo())

Robustly calculate (and return) Average MPG since new (properly function with zeros as input, and return -1 if input is otherwise invalid). Use exception handling as discussed in class.

Step 3:

Create a three argument constructor that lets you set the brand of the car, odometer reading, and fuel consumed since new.

Create a no argument constructor that sets the brand of the car to "none" and sets the odometer reading and fuel consumed to zero.

Step 4:

In your main method:

Create an instance of your Car class using your three argument constructor. You may assign any values you like for brand, odometer reading, and total fuel consumed.

Create another instance of your Car class using your no argument constructor. Then call your setter methods to assign any values you like for brand, odometer reading, and total fuel consumed.

Display the info for both Cars.

For both Car objects that you created, call the method to calculate average MPG since new, and display this value.

Step 5:

Export your NetBeans project to a Zip file named Assign2_YourLastName.zip, and upload to Canvas.

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

Step: 3

blur-text-image

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

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

6. What questions would you suggest should be included?

Answered: 1 week ago