Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE HELP!! Here is code for chapter 5: package com.java; import java.util.Locale; import java.util.Scanner; public class VehicalRentingApp { private static Scanner sc = new Scanner(System.in);

PLEASE HELP!! image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Here is code for chapter 5:
package com.java;
import java.util.Locale;
import java.util.Scanner;
public class VehicalRentingApp
{
private static Scanner sc = new Scanner(System.in);
// Get First name and return the value entered by user
public static String inputFirstName(String messagePassed) {
System.out.println(messagePassed);
return sc.nextLine();
}
// get last name from user and return the entered value
public static String inputLastName(String messagePassed) {
System.out.println(messagePassed);
return sc.nextLine();
}
// Get the make of vehicle from user and return it
public static String inputMake(String messagePassed) {
System.out.println(messagePassed);
return sc.nextLine();
}
// Get vehicle model and return it
public static String inputModel(String messagePassed) {
System.out.println(messagePassed);
return sc.nextLine();
}
// Get the vehicle year. It shud be between lower limit and upper limit
public static int inputVehicleYear(String messagePassed, int lowerLimitPassed, int upperLimitPassed) {
int userInput;
do {
System.out.println(messagePassed);
userInput = sc.nextInt();
if (userInput > lowerLimitPassed && userInput
return userInput;
}
} while (true);
}
// Get Vehicle price from user it should be less than limitPassed
public static int inputVehiclePrice(String messagePassed, double limitPassed) {
int userInput;
do {
System.out.println(messagePassed);
userInput = sc.nextInt();
if (userInput > limitPassed) {
return userInput;
}
} while (true);
}
// Get interest rate and get its percentage by divide it by divisorPassed
public static double inputInterestRate(String messagePassed, double lowerLimitPassed, double upperLimitPassed,
int divisorPassed) {
double userInput;
do {
System.out.println(messagePassed);
userInput = sc.nextDouble();
if (userInput > lowerLimitPassed) {
if (userInput > upperLimitPassed) {
userInput = userInput / divisorPassed;
return userInput;
}
}
} while (true);
}
// Get downpayment from user. and vehicle shoule be old and value of downpayment
// should be in limit
public static double inputDownPayment(String messagePassed, double valuePassed, double limitPassed,
double percentagePassed, boolean testConditionPassed) {
double userInput;
do {
System.out.println(messagePassed);
userInput = sc.nextDouble();
if (userInput > limitPassed && !testConditionPassed) {
return userInput;
} else {
int k = (int) (valuePassed * percentagePassed);
if (userInput >= k) {
return userInput;
}
}
} while (true);
}
// Get avg miles per gallon. value Should be > limitPassed
public static double inputMilesPerGallon(String messagePassed, double limitPassed) {
double userInput;
do {
System.out.println(messagePassed);
userInput = sc.nextDouble();
if (userInput > limitPassed) {
return userInput;
}
} while (true);
}
// get Cost per gallon.
public static double inputCostGallonFuel(String messagePassed, double limitPassed) {
double userInput;
do {
System.out.println(messagePassed);
userInput = sc.nextDouble();
if (userInput > limitPassed) {
return userInput;
}
} while (true);
}
// get avg miles driven for the vehicle
public static int inputMilesPerYear(String messagePassed, int limitPassed) {
int userInput;
do {
System.out.println(messagePassed);
userInput = sc.nextInt();
if (userInput > limitPassed) {
return userInput;
}
} while (true);
}
// Get from user if it is a new vehicle
public static boolean inputVehicleNew(String messagePassed) {
Boolean userInput;
System.out.println(messagePassed);
userInput = sc.nextBoolean();
return userInput;
}
// get from user how much years of driving exp user has
public static int inputNumberOfYearsYouHaveBeenDriving(String messagePassed, int limitPassed) {
int userInput;
do {
System.out.println(messagePassed);
userInput = sc.nextInt();
if (userInput > limitPassed) {
return userInput;
}
} while (true);
}
// get surchargable points from user
public static int inputNumberOfSurchargablePoints(String messagePassed, int limitPassed) {
int userInput;
do {
System.out.println(messagePassed);
userInput = sc.nextInt();
if (userInput > limitPassed) {
return userInput;
}
} while (true);
}
// get Number of years driven without any surchargable points from user
public static int inputNumberOfConsecutiveYearsWithZeroSurchargablePoints(String messagePassed, int limitPassed) {
int userInput;
do {
System.out.println(messagePassed);
userInput = sc.nextInt();
if (userInput > limitPassed) {
return userInput;
}
} while (true);
}
// Get the vehicle code from user from the given table
public static char inputVehicleCode(String messagePassed) {
char userInput;
System.out.println(messagePassed);
String table = "Code \t\t Desciption \t\t Weight";
String tableRow1 = "A \t\t Passenger\t\t1,500 - 1,999 lb";
String tableRow2 = "B \t\t Passenger\t\t2,000 - 2,499 lb";
String tableRow3 = "C \t\t Passenger\t\t2,500 - 3,499 lb";
String tableRow4 = "D \t\t Passenger\t\t3,500 lb - over";
String tableRow5 = "E \t\t Passenger\t\t3,500 lb - over";
String tableRow6 = "F \t\t SUV\t\t\t na";
String tableRow7 = "G \t\t Pickup\t\t\t na";
String tableRow8 = "H \t\t Van\t\t\t\t na";
System.out.println(table);
System.out.println(tableRow1);
System.out.println(tableRow2);
System.out.println(tableRow3);
System.out.println(tableRow4);
System.out.println(tableRow5);
System.out.println(tableRow6);
System.out.println(tableRow7);
System.out.println(tableRow8);
userInput = sc.next().charAt(0);
return userInput;
}
// Get vehicle description
public static String inputVehicleDescription(String messagePassed) {
String userInput;
System.out.println(messagePassed);
userInput = sc.next();
return userInput;
}
// In main we will get all the inputs from user and display it back
public static void main(String args[]) {
sc.useLocale(Locale.US);
String fName = inputFirstName("Please enter your first Name");
String lName = inputLastName("Please enter your last Name");
int vehicalYear = inputVehicleYear("Please enter the Vehicle year/ must be >=1886 and
sc.nextLine();
String make = inputMake("Please enter the make of your vehicle");
String model = inputModel("Please enter the model of your vehicle");
double vehicalPrice = inputVehiclePrice("Please enter vehical price. must be >=0", 0);
double interestRate = inputInterestRate("Please enter interest rate price. must be >=0 and
System.out.println(interestRate);
boolean isNew = inputVehicleNew("Is the vehicle new, please enter true or false");
double downpayment = inputDownPayment("Please enter downpayment you will make, must be >=0 and >=20000 ",
vehicalPrice, 0, 0.20, isNew);
double milesPerGallon = inputMilesPerGallon("Please enter miles per galon ,must be >=0", 0);
double costPerGallon = inputCostGallonFuel("Please enter cost per gallon of fuel, must be >=0", 0);
double avgMilesDriven = inputMilesPerYear("Please enter the total miles driven per year must be>=0", 0);
int drivingExp = inputNumberOfYearsYouHaveBeenDriving(
"Please enter the number of years you have been driving, must be >=0", 0);
int surchargeablePoints = inputNumberOfSurchargablePoints("Please enter surchargeable points, must be>=0", 0);
int yearWithoutChargablePoints = inputNumberOfConsecutiveYearsWithZeroSurchargablePoints(
"Please enter the number of consecutive years without surcharge able points, must be >=0", 0);
char vehicalCode = inputVehicleCode("Please enter vehicle code using the chart below:");
System.out.println("Cost Analysis prepared for " + fName + " " + lName);
System.out.println(
"The cost of buying and owning a " + vehicalYear + " " + make + " " + model + " are as follows: ");
System.out.println("Purchased for $" + vehicalPrice + " with downpayment of $" + downpayment);
System.out.println(" and an interest rate of " + interestRate + " on loan of ");
System.out.println(" The montly loan payment will be ");
}
}
CHAPTER: 7 (Section 1) FILE NAME: CPC7 S2018 _your initials.java Summary: A program that will calculate the cost of a gasoline/diesel powered vehicle. Description: You will be working on a comprehensive problem throughout the semester. The program you will be writing will calculate the cost of a vehicle for the user and will become more complex as the semester progresses.Your solution to the problem will incorporate the Java capabilities you leam with each chapter. You are to integrate the code required as below into your Chapter 5 solution code CPC4 S2018_your initials java) ie. make of duplicate of your Chapter 5 code (CPC5_S2018 your initials java), rename it CPC7 $2018 your initials java and integrate the code required below into your submission (CPC7 $2018_your initials java). You are to remove any Chapter 5 code that is rendered unnecessary by the requirements below: Chapter 7 Specifications: 1. Develop the methods as specific below: Method declaration: public static int inputYears(String messagePassed, in limitPassed) Method description: Declare a variable int userinput. Use a do/while loop to print to the screen the value of messagePassed and to save the value entered by the user in userinput, you are to trap the user (repeating the request for and saving of userinput) if uselnput secondLimitPassed. Return userinput 2. Declare the following variables (declare all variables at the beginning of your program): int years; int loanLength; 3. Call the methods above as follows and save the retumed values as to to the variables noted: A Method to call: public static int inputYears(String messagePassed, int limitPassed) Values to pass: messagePassed: "Please enter the number of years you plan to keep the vehicle, must be a whole number > 0. limitPassed: 0 Save returned value to: years B. Method to call: public static int inputLoanLength(String messagePassed, int firstLimitPassed, int secondLimitPassed) Values to pass: messagePassed: "Please enter the length of your loan in years, must be must be a whole number>0 and the number of years you plan to keep the vehide firstLimitPassed: 0 secondLimitPasssed: years CHAPTER: 7 (Section 1) FILE NAME: CPC7 S2018 _your initials.java Summary: A program that will calculate the cost of a gasoline/diesel powered vehicle. Description: You will be working on a comprehensive problem throughout the semester. The program you will be writing will calculate the cost of a vehicle for the user and will become more complex as the semester progresses.Your solution to the problem will incorporate the Java capabilities you leam with each chapter. You are to integrate the code required as below into your Chapter 5 solution code CPC4 S2018_your initials java) ie. make of duplicate of your Chapter 5 code (CPC5_S2018 your initials java), rename it CPC7 $2018 your initials java and integrate the code required below into your submission (CPC7 $2018_your initials java). You are to remove any Chapter 5 code that is rendered unnecessary by the requirements below: Chapter 7 Specifications: 1. Develop the methods as specific below: Method declaration: public static int inputYears(String messagePassed, in limitPassed) Method description: Declare a variable int userinput. Use a do/while loop to print to the screen the value of messagePassed and to save the value entered by the user in userinput, you are to trap the user (repeating the request for and saving of userinput) if uselnput secondLimitPassed. Return userinput 2. Declare the following variables (declare all variables at the beginning of your program): int years; int loanLength; 3. Call the methods above as follows and save the retumed values as to to the variables noted: A Method to call: public static int inputYears(String messagePassed, int limitPassed) Values to pass: messagePassed: "Please enter the number of years you plan to keep the vehicle, must be a whole number > 0. limitPassed: 0 Save returned value to: years B. Method to call: public static int inputLoanLength(String messagePassed, int firstLimitPassed, int secondLimitPassed) Values to pass: messagePassed: "Please enter the length of your loan in years, must be must be a whole number>0 and the number of years you plan to keep the vehide firstLimitPassed: 0 secondLimitPasssed: years

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

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

What is dividend payout ratio ?

Answered: 1 week ago

Question

Explain the factors affecting dividend policy in detail.

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago