Results 1 to 3 of 3
  1. #1
    lexyloraine is offline Member
    Join Date
    Mar 2011
    Posts
    1
    Rep Power
    0

    Default what is wrong with my code :(

    my project is to:
    A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage
    charges an additional $0.50 per hour for each hour or part thereof in excess of three hours. The maximum
    charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24
    hours at a time. Write an application that calculates and displays the parking charges for each customer
    who parked in the garage yesterday. You should enter the hours parked for each customer.
    The program should display the charge for the current customer and should calculate and display
    the running total of yesterday’s receipts. The program should use the method calculateCharges to
    determine the charge for each customer.
    and so far my code is:
    package src;

    import java.io.PrintStream;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.Scanner;

    public class ParkingCharges {

    // Create method to ask for hours parked for each customer
    public void getHoursParked() {
    double hoursParked;
    int customerID;
    Scanner input = new Scanner(System.in);
    System.out.println("Enter the customer ID: ");
    customerID = input.nextInt();
    System.out.println("Enter the hours parked: ");
    hoursParked = input.nextDouble();

    // call the method calculateCharges()
    calculateCharges(customerID, hoursParked);
    }
    // Create method calculateCharges to determine the charge for each customer
    public void calculateCharges(int customerID, double hoursParked) {

    double chargeFees = 0;
    double excessHour=0;

    // if within 3 hours, set the charge fees to $2.00
    if (hoursParked==3) {
    chargeFees = 2.00;
    // if more than 3 hours, calculate the minutes that more than 3 hours
    // to determine the additional charge fees
    } else if (hoursParked>3) {
    excessHour = hoursParked-3;
    int remHours=(int) (excessHour % 10);
    chargeFees=2.00+(0.5*remHours);

    // if it is 24-hours, charge fees is $10.00
    } else if (hoursParked==24) {
    chargeFees = 10.00;
    } else {
    // additional charge of $0.5 for part thereof excess three hours
    chargeFees = 2.5;
    }

    // call the method of displayCharges
    displayCharges(customerID, chargeFees);
    } // end of method calculateCharges

    // Create a method to displayCharges of the charge calculation
    public void displayCharges(int customerID, double chargeFees) {
    long oneDay = (long) 1000.0 * 60 * 60 * 24;
    Date yesterday = new Date(System.currentTimeMillis() – oneDay);
    System.out.println("—– Parking Fees Calculation System —–");
    System.out.printf("| Date: %s |", yesterday);
    System.out.printf("\n| Customer ID: %d\t\t\t |", customerID);
    System.out.printf("\n| Total parking fees: %.2f\t\t |", chargeFees);
    System.out.printf("\n——————————————-")…
    } // end of method displayCharges
    } // end class ParkingCharges


    i am getting an error in my create a method to displayCharges

    on the line that reads:
    Date yesterday = new Date(System.currentTimeMillis() – oneDay);

    it says Multiple markers at this line
    - Syntax error on token "Invalid Character", ,
    expected

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Format your code with proper indentation and use code tags when posting the code.

  3. #3
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    First rule: Always put your code in CODE tag and it should be properly formatted

    For now change the below line in your code at line 52

    Java Code:
    long newDate = System.currentTimeMillis() - oneDay;
    Date yesterday = new Date(newDate);
    sanjeev,संजीव

Similar Threads

  1. what is wrong with my code
    By amrmb09 in forum New To Java
    Replies: 7
    Last Post: 02-11-2011, 06:10 PM
  2. What is wrong with this code?
    By Mythreadings in forum New To Java
    Replies: 38
    Last Post: 11-19-2010, 01:43 AM
  3. what is wrong in dis code?
    By jitun2004 in forum New To Java
    Replies: 8
    Last Post: 04-15-2009, 10:30 AM
  4. what's the wrong in this Code
    By the swan in forum AWT / Swing
    Replies: 1
    Last Post: 04-04-2009, 05:27 AM
  5. What is wrong with this code
    By rosh72851 in forum New To Java
    Replies: 13
    Last Post: 10-31-2008, 02:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •