(1) Create two files: Car.java - Class definition, object class CarTester.java - Driver program, contains main() method Build the Car class with the following specifications:

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

(1) Create two files:

  • Car.java - Class definition, object class
  • CarTester.java - Driver program, contains main() method

Build the Car class with the following specifications:

  • Private fields:
    String make - Initialized in default constructor to "none"
    int mileage - Initialized in default constructor to 0

  • Constructors:
    Default constructor with no parameter 
    Overloaded constructor with two parameters 

  • Methods:
    setMake() & getMake() 
    setMileage() & getMileage() 

(2) In your testing class, prompt the user for information to create two car objects of the Car class. Remember that the car make could contain multiple words, such as "Land Rover". Think about which method you should use in order to read in the car make information (nextLine() or next()?).
A possible problem: you might notice that your nextLine() method does not read in anything when it is called after next() or nextInt() method. To fix this, you need to call an empty scan.nextLine(); to be able to read in the user's input when nextLine() and nextInt() are called in sequence.

Ex:

Car 1

Enter the car make:

Land Rover

Enter the car mileage:

100

 

Car 2

Enter the car make:

Ford

Enter the car mileage:

150000


(3) Add toString method to Car class that returns the information of the object as a string. When you print the car1 object in main(), you will get the following output. 

Ex:

The make of the car is Land Rover, and the mileage of the car is 100.

(4) Add computeMPG method to the Car class that returns the MPG (miles per gallon) value as a double. The method should accept two parameters, one is called miles and the other is called gallons, which indicates how many gallons of gas has been used after driving those miles. Both should be int type. Set the output to 3 decimal places.

For example, when you call this method in main() for car1 with miles = 200 and gallons = 6 as actual parameters, you will get the following output.

Ex:

The MPG of your Land Rover is 33.333.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY