Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What am i doing wrong? --------Auto.java------------ public class Auto { public int modelYear; public String modelMake; public double mileage; public double tankCapacity; public final int

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

What am i doing wrong?

--------Auto.java------------

public class Auto {

public int modelYear; public String modelMake; public double mileage; public double tankCapacity; public final int CURRENT_YEAR = 2018; public final int AVG_MILES = 12000; public Auto(int modelYear, String modelMake, double mileage, double tankCapacity) { super(); this.modelYear = modelYear; this.modelMake = modelMake; this.mileage = mileage; this.tankCapacity = tankCapacity; } public Auto() { super(); } public void setModelYear(int modelYear) { this.modelYear = modelYear; } public void setModelMake(String modelMake) { this.modelMake = modelMake; } public void setMileage(double mileage) { this.mileage = mileage; } public void setTankCapacity(double tankCapacity) { this.tankCapacity = tankCapacity; } public int computeAvgMiles() { int carYear = CURRENT_YEAR - modelYear; return carYear * AVG_MILES; } public double computeRange() { return (mileage / tankCapacity); } public void displayAutoData() { System.out.println("Enter auto model year:"); System.out.println("Enter auto make and model:"); System.out.println("Enter auto mileage (in miles per gallon):"); System.out.println("Enter auto tank capacity (in gallons):"); } }

------------------AutoManager.java-------------

import java.util.Scanner;

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */

/** * Topic11part2 * @author James Burress */ public class AutoManager { public Auto createAutoWithReadData(Scanner keyboard){ System.out.println("Enter auto model year:"); int modelYear = Integer.parseInt(keyboard.nextLine()); System.out.println("Enter auto make and model:"); String makeModel = keyboard.nextLine(); System.out.println("Enter auto mileage (in miles per gallon):"); double mileage = keyboard.nextDouble(); System.out.println("Enter auto tank capacity (in gallons):"); double tankCapacity = keyboard.nextDouble(); Auto Auto = new Auto(modelYear, makeModel, mileage, tankCapacity); return Auto; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); Scanner sc1 = new Scanner(System.in); AutoManager autoManagerObj = new AutoManager(); Auto autoObj1 = autoManagerObj.createAutoWithReadData(sc); System.out.println(); autoObj1.displayAutoData(); System.out.println(); System.out.println("On average, "+ autoObj1.modelYear + " cars have approximately " + autoObj1.computeAvgMiles() + " miles on the odometer"); System.out.println(autoObj1.modelYear + " " + autoObj1.modelMake + " has a " + autoObj1.tankCapacity + " gallon tank and gets " + autoObj1.mileage + " miles per gallon"); System.out.println("Range is " + (int)(autoObj1.mileage * autoObj1.tankCapacity) + " miles"); System.out.println(); Auto autoObj2 = autoManagerObj.createAutoWithReadData(sc1); autoObj2.displayAutoData(); System.out.println(); System.out.println("On average, "+ autoObj2.modelYear + " cars have approximately " + autoObj2.computeAvgMiles() + " miles on the odometer"); System.out.println(autoObj2.modelYear + " " + autoObj2.modelMake + " has a " + autoObj2.tankCapacity + " gallon tank and gets " + autoObj2.mileage + " miles per gallon"); System.out.println("Range is " + (int)(autoObj2.mileage * autoObj2.tankCapacity) + " miles"); System.out.println(); if ((autoObj1.mileage * autoObj1.tankCapacity) > (autoObj2.mileage * autoObj2.tankCapacity)) System.out.println(autoObj1.modelYear + " " + autoObj1.modelMake + " " + "has a longer range"); else System.out.println(autoObj2.modelYear + " " + autoObj2.modelMake + " " + "has a longer range"); } }

Program Requirements The program will be written in NetBeans Start with a copy of your project from 11.13 (so you won't lose your work from 11.13) Copy the project folder: to a new project folder named Topicl1partl Topic11part2 * Open the project in the Topic11part2 folder in NetBeans . Click on the Projects tab . Right-click the Project name at the top of the projects window. . Select "Rename", and rename the project to Topic11part2 to match the folder Within the Auto class (used to create Auto type objects): . Include top of file comments with descriptions and an @author tag Add a second constructor that: Has parameters for each data field/member of the class (model year, make/model, mileage, and tank capacity, in that order) Uses the parameter values to initialize the data fields o o Add the following additional methods to the Auto class (must use these exact method names) o computeAvgMiles ) public method to compute average miles on a car for its age . . Create a constant to hold the current year (2018) . Create a constant to hold the average of 12,000 miles per year old . Use the model year to compute the car's age and then use the age to compute the car's average miles for its age This method will have no parameters, and will return the car's avg miles for its age o computeRange ) - public method to compute the car's range (miles per tank) This method will have no parameters, and will return the car's range o displayAutoData() - public method to all display the data field values, formatted as in Topic11partl This method will have no parameters and will not return anything Include method comments above each method, with method descriptions, @return tags, and @param tags

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

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions