Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with this code Create a class named Car that contains the following data fields: make of type String model of type String

Please help me with this code

  1. Create a class named Car that contains the following data fields:
  • make of type String
  • model of type String
  • year of type int
  • miles of type int
  • msrp of type double
  1. Include get and set methods for these fields. The methods should be prefixed with 'get' or 'set' respectively, followed by the field name using camel case. For example, setMake.
  2. Include 2 constructors.
    1. The first constructor should have no arguments and sets the data fields to default values.
    2. The second should have 5 arguments that set the values of all the data fields.
  3. Write a class named TestCar that contains a main method, which instantiates two car objects.
    1. The first car object should be instantiated by calling the overloaded constructor from step 3b.
    2. The second car object should be instantiated by calling the default constructor. The values of the second cars data fields should be set using the set methods. (Refer to example TestSandwich programming exercise 3-11)
  4. In TestCar, create a static method called calculatePrice that takes in 5 argumets: (1) make, (2) model, (3) year, (4) miles, and (5) msrp, then displays the price for each car. Your output should look like:

A 2016 Chevrolet Camaro with 24500.0$ msrp driven for 50 miles sells for 19600.0$.

A 2012 Toyota RAV4 with 22500.0$ msrp driven for 130 miles sells for 10800.0$.

The current price of the car is based off the percentage of the remaining miles. If a car can run up to 250 miles, the current price of the car, p = msrp [(miles/250) * msrp].

  1. In the main method, call calculatePrice twice. Once using all get methods from the first car object, and the second using all get methods from the second car object. The get methods calls should be inserted as arguments for calculatePrice. (Refer to example TestSandwich programming exercise 3-11)
  2. Comment your codes thoroughly.
    1. The main class header should have the following document comment, and filled:

/**

* Homework#

* Author:

* Date:

* Description:

*/

  1. Each method and class header should have comments that follow or be as close as possible to the Java documentation.

Each variable declaration, method call, and mathematical assignment should be preceded by a single line comment explaining what the line of code is meant to do

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

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions

Question

What is meant by 'Wealth Maximization ' ?

Answered: 1 week ago