Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Orignal Java Code....need help for part 2 import java.util.Scanner; /* * To chan

ID: 3713999 • Letter: O

Question

Orignal Java Code....need help for part 2

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.
*/

/**
* Topic11part1
* @author
*/
public class AutoManager {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
       
       //Creating an instance of Auto class
        Auto auto=new Auto();
        //calling the method
        readAutoData(sc,auto);
        System.out.println();
        //Displaying the output
        System.out.printf("%d %s has a %.1f gallon tank and gets %.1f miles per gallon ",auto.getModelYear(),auto.getMakeModel(),auto.getTankCapacity(),auto.getMileage());

        }
        //This method will read the input entered by the user
        private static void readAutoData(Scanner sc, Auto auto) {
        System.out.print("Enter auto model year :");
        int year=sc.nextInt();
        sc.nextLine();
        System.out.print("Enter auto make and model :");
        String make=sc.nextLine();
        System.out.print("Enter auto mileage (in miles per gallon) :");
        double mileage=sc.nextDouble();
        System.out.print("Enter auto tank capacity (in gallons) :");
        double gallons=sc.nextDouble();
        //calling the setters
        auto.setModelYear(year);
        auto.setMakeModel(make);
        auto.setMileage(mileage);
        auto.setTankCapacity(gallons);
    }
}
       

part 2

/*
* 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.
*/

/**
*
* @author
*/
class Auto {
    // Declaring instance variables
        private int modelYear;
        private String makeModel;
        private double mileage;
        private double tankCapacity;
        // Zero argumented constructor
        public Auto() {
        this.modelYear = 0;
        this.makeModel = "unknown";
        this.mileage = 0.0;
        this.tankCapacity = 0.0;
        }
        // getters and setters
        public int getModelYear() {
        return modelYear;
        }
        public void setModelYear(int modelYear) {
        this.modelYear = modelYear;
        }
        public String getMakeModel() {
        return makeModel;
        }
        public void setMakeModel(String makeModel) {
        this.makeModel = makeModel;
        }
        public double getMileage() {
        return mileage;
        }
        public void setMileage(double mileage) {
        this.mileage = mileage;
        }
        public double getTankCapacity() {
        return tankCapacity;
        }
        public void setTankCapacity(double tankCapacity) {
        this.tankCapacity = tankCapacity;
        }
        }

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 .

Explanation / Answer

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)

{

this.modelYear = modelYear;

this.modelMake = modelMake;

this.mileage = mileage;

this.tankCapacity = tankCapacity;

}

public Auto() {

this.modelYear = 0;

this.modelMake = "unknown";

this.mileage = 0.0;

this.tankCapacity = 0.0;

}

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.printf("%d %s has a %.1f gallon tank and gets %.1f miles per gallon ",modelYear,modelMake,tankCapacity,mileage);

}

}

________________

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.

*/

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 int computerRange(Auto autoObj)

{

return (int)(autoObj.mileage * autoObj.tankCapacity);

}

public static String computeAvgMiles(Auto autoObj)

{

return "On average, "+ autoObj.modelYear + " cars have approximately " + autoObj.computeAvgMiles() + " miles on the odometer";

}

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();

Auto autoObj2 = autoManagerObj.createAutoWithReadData(sc1);

  

autoObj1.displayAutoData();

System.out.println();

  

System.out.println(computeAvgMiles(autoObj1));

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 " +computerRange(autoObj1)+ " miles");

System.out.println();

  

autoObj2.displayAutoData();

System.out.println();

System.out.println(computeAvgMiles(autoObj2));

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 " +computerRange(autoObj2) + " 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");

}

}

__________________

Output:

Enter auto model year:
2010
Enter auto make and model:
Honds Accord
Enter auto mileage (in miles per gallon):
27.5
Enter auto tank capacity (in gallons):
15.5

Enter auto model year:
2014
Enter auto make and model:
Chevrolet Tahoe
Enter auto mileage (in miles per gallon):
19.2
Enter auto tank capacity (in gallons):
26.1
2010 Honds Accord has a 15.5 gallon tank and gets 27.5 miles per gallon

On average, 2010 cars have approximately 96000 miles on the odometer
2010 Honds Accord has a 15.5 gallon tank and gets 27.5 miles per gallon
Range is 426 miles

2014 Chevrolet Tahoe has a 26.1 gallon tank and gets 19.2 miles per gallon

On average, 2014 cars have approximately 48000 miles on the odometer
2014 Chevrolet Tahoe has a 26.1 gallon tank and gets 19.2 miles per gallon
Range is 501 miles

2014 Chevrolet Tahoe has a longer range

_______________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote