Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Java

Hi guys , I'm Working on this exercices , just for you to check and help wherever you can, it's also good practice for beginners like me: HERE: Stage 1 – Basic Equipment Hire Booking System (25 marks) To begin with the program should prompt the user to enter basic information about the customer, as well as basic details about the equipment hire itself as described below, read the user's input into the program (using a Scanner is recommended but is not compulsory) and store that information in variables of an appropriate type for each input value (suggested input types for each group of variables are shown in brackets):  The customer’s name, address, phone number and drivers licence number (String)  The customer’s credit card number and expiry date (String)  The booking length (number of days) the customer requires the equipment for (int)  The type of equipment to be hired (String)  The daily hire rate that applies to the equipment hire (double) The program should prompt the user to enter these values and then read them into the program from the keyboard and store them in appropriately-typed variables for later use. Note that your program must prompt the user to enter these values in the order specified above - you will lose marks for changing the input sequence described above so that your program reads input in a different order, as one aspect of this task will be dealing with trailing newlines after reading numeric inputs (if you are using a Scanner to read input). You may assume that the user will enter valid input values of the correct type and within the specified range where such a range applies - there is no requirement to validate input in any way, shape or form here in Stage 1. Once all required values have been entered you will need to calculate the base hire charge as follows and store it in an appropriately typed variable for later reference: basic hire charge = booking length * daily hire rate After the program has gathered the required input values from the user and has performed the required calculations it should display the equipment hire invoice details in a tabulated format (ie. with values aligned/justified in columns) as shown in the sample execution run on the next page. You must use field width modifiers appropriately in System.out.printf() to align/justify the output when displaying the equipment hire invoice details – Remember that you must also use appropriately named variables to store the relevant values that need to be gathered from the user as well as store the results for any calculations you perform.

My Code is the following:

package com.company; import java.util.Scanner; public class Main {

public static void main(String[] args) {
    // write your code here

   // Data collection from client...Assignment Part1

    System.out.print("Please Enter your full name");
    Scanner fullName = new Scanner(System.in);
    String clientName = fullName.nextLine();

    System.out.print("Please Enter your Address");
    Scanner address = new Scanner(System.in);
    String clientAddress = address.nextLine();

    System.out.println("What is your phone number?");
    Scanner phoneNumber = new Scanner(System.in);
    String tel = phoneNumber.nextLine();

    System.out.println("What is your License number?");
    Scanner license = new Scanner(System.in);
    String clientLicense = license.nextLine();

    System.out.println("Enter you Credit card Number");
    Scanner creditCardNum = new Scanner(System.in);
    String clientCCard = creditCardNum.nextLine();

    System.out.println("Your Credit Card expiry date");
    Scanner cCardExDate = new Scanner(System.in);
    String expiryDate = cCardExDate.nextLine();

    System.out.println("How many days are you Hiring it for?");
    Scanner daysNum = new Scanner(System.in);
    Integer howLong = daysNum.nextInt();

    System.out.println("Witch Equipement do you want to hire?");
    Scanner equiHire = new Scanner (System.in);
    String whatEquipment = equiHire.nextLine();

    System.out.println("Our base rate is");
    Scanner initialDailyValue = new Scanner (System.in);
    Double baseRateHirePerDay = initialDailyValue.nextDouble();

    //Hiring Cost:

    double basicHireCharge = (double)howLong * baseRateHirePerDay;



    //Outputs
    System.out.println("Customer Details");
    System.out.println("----------------");
    System.out.printf("Full Name: %20s%n", clientName);
    System.out.printf("Address: %20s%n", clientAddress);
    System.out.printf("Phone Number: %20s%n", tel);
    System.out.printf("License number: %20s%n ", clientLicense);
    System.out.printf("Card Number: %20s%n ",clientCCard);
    System.out.printf("Booking Length: %20d%n",howLong);
    System.out.printf("Equipment Type: %20s%n",whatEquipment);
    System.out.printf("Basic Daily rate: %20f%n",baseRateHirePerDay);
    System.out.printf("Basic Charge:%20f%n", basicHireCharge);




}

}

The second part is where I need a bit of help. How would you change this the previous code to do this:

Looking back on the equipment hire system scenario in stage 1 it wasn’t all that “realistic” in that other factors such as having different daily hire rates for different types of earthmoving equipment, as well as a discounts for longer term hires will also need to be incorporated into the final equipment hire charge. In this stage the equipment hire invoicing system calculations will need to incorporate variable daily equipment hire fee rates, based on the equipment type that the customer has requested (this will replace the user- entered daily hire fee from stage 1). The daily hire rates for different equipment types are listed below: Equipment Hire Fee Schedule Note: correction made to equipment type from “Kubota Light Excavator” to “Kubota Light Excavator” (08/06/2017) The system calculations will also need to factor in the discounts for longer-term hires - the schedule for daily hire rate discounts based on the booking length for the equipment hire is listed below: Long-term Hire Discount Schedule The system will also need to record whether the equipment has been refuelled prior to being returned, as a surcharge for refuelling may also apply for equipment that needs refuelling after being returned. Changes to the previous program In this stage you will need to update and extend the functionality of the existing program from Stage 1 to allow for the handling of different equipment types, discounts for longer hires and refuelling surcharges, in order to reflect a more realistic scenario for an equipment hire company - this will require you to declare additional appropriately-typed variables for the discount rate (double) and "refuelled" status (boolean). After reading in the basic customer details (as described in stage 1), the prompt to enter the equipment type should be amended to request an equipment code instead, which you may assume will be one of the equipment codes listed above. You will then need to use an appropriate decision structure to identify the corresponding equipment type and daily hire rate, based on the equipment code that was entered, and store the applicable equipment type and daily hire rate in the corresponding variables for later reference. You will also need to use a (separate) decision structure to determine the long-term hire discount that applies (if any), based on the booking length, and store that discount for later reference in the final equipment hire calculations. Once the applicable equipment type / hire rate and long-term hire discount details have been noted the program should request the user to indicate whether the equipment has been refuelled (as a "Y / N" prompt)
DML Dingo Mini Loader $300 per day BSL Bobcat Skid Steer Loader $400 per day
KMX Kubota 1.7T Mini Excavator $450 per day KLX,$550 per day
5T 5.5T Days hired Long-term hire discount 1-4 N/A 5 - 14

10% of the applicable daily hire rate 15+

30% of the applicable daily hire rate and, based on the user's response, set the "refuelled" status variable appropriately for later reference (ie. if the user enters "Y" the refuelled status should be set to true, otherwise it should be set to false). You may assume that the user will enter valid input values of the correct type and within the specified range where such a range applies - there is no requirement to validate input in any way, shape or form here in Stage 2. At this point you should perform the following calculations and store the result for each in appropriately typed variables:  The base hire charge (booking length * daily hire rate)  The long-term hire discount (base hire charge * discount rate)  The fuel surcharge (which is a set figure of $200 if the equipment has not been refuelled)  The discounted hire charge ((base hire charge - long-term hire discount) + refuelling surcharge) Once all required calculations have been performed you will need to amend the displaying of the equipment hire invoice details to include the new values listed above - below - remember that you must use field width modifiers appropriately in System.out.printf() to align/justify the output when displaying the (additional) equipment hire invoice details. A number of execution runs showing how the program should function in a different scenarios are shown below.

Example 3 - Equipment hire invoice for 7-day bobcat with no fuel surcharge *** Stage 2 Equipment Hire Invoice System *** Enter Customer Name: Digger Dan Enter Customer Address: 23 Pitt Crescent, Pittville Enter Customer Phone No: 0412 345 678 Enter Customer Licence No: LE10436V Enter Credit Card No: 4123 4567 8901 2345 Enter Expiry Date: 12/2017 Enter Booking Length (in days): 7 Enter Equipment Code: BSL Equipment fully refuelled (Y/N)? Y

Customer Details

Name: Address: Phone Number: Licence No: Credit Card No: Expiry Date:

Equipment Hire Details

Equipment Description: Booking Length (days): Daily Hire Rate: Base Hire Charge: Discount: Fuel Surcharge Discounted Hire Charge: Digger Dan 23 Pitt Crescent, Pittville 0412 345 678 LE10436V 4123 4567 8901 2345 12/2017 Bobcat Skid Steer Loader 7 400.00 2800.00 -280.00 0.00 2520.00