Results 1 to 5 of 5
  1. #1
    eppoair2 is offline Member
    Join Date
    Nov 2010
    Location
    Virginia
    Posts
    14
    Rep Power
    0

    Default Not getting the expected output. What is wrong with the coding ?

    Hello all,

    Cost is No Object – Luxury Car Rental
    Cost Is No Object is a car rental service that specializes in lending antique and luxury cars to clients on a short-term basis. A typical customer might rent a vintage convertible to transport out-of-town clients to a business meeting, or rent a luxury car to transport a wedding party. The service currently has three employees and 10 vehicles that it rents. One required application is a program that calculates customer bills. This month, cars are being rented for $35 per day, with a 9% tax applied. Draw a flowchart or write pseudocode for a program, as well as the Java program that accepts a client’s name, the type of car the client wants to rent, and the number of rental days needed. Output the client’s bill, including the name, type of car, number of days, total due before tax, tax, and total due with tax.

    Here is what I wrote, but I have the total is always 0.

    import java.util.Scanner;
    public class Car
    {
    private String name;
    private String CarType;
    private int NumberOfDays;
    private double tax;
    private double Subtotal;
    private double Total;
    private int RentalRate;



    public void readInput()
    {
    Scanner keyboard = new Scanner( System.in);
    System.out.println(" Please enter your name.");
    name= keyboard.nextLine();
    System.out.println(" Please enter Cartype, Whether is luxury or antique car.");
    CarType= keyboard.nextLine();
    System.out.println(" Please enter number of days would you like to rent.");
    NumberOfDays= keyboard.nextInt();

    }


    public double subtotal ()
    {
    readInput();
    int RentalRate= 35;
    double Subtotal=0;

    if(NumberOfDays >0)
    Subtotal= RentalRate * NumberOfDays;
    else
    System.out.println(" Number of days can't be 0. Please modify and try again.");

    return Subtotal;

    }


    public double TotalBill ()

    {

    double Total;
    double Tax = 0.09;
    Total= Subtotal * tax ;
    return Total;
    }



    public void writeOutput()
    {
    System.out.println(" Name : " + name);
    System.out.println(" CarType:" + CarType);
    System.out.println(" NumberOfDays:" + NumberOfDays);
    Subtotal=subtotal();
    System.out.println(" SubTotal:" + Subtotal);
    System.out.println(" TotalBill:" + Total);

    }


    public static void main (String [] args)
    {
    Car myCar = new Car();
    myCar.readInput();
    myCar.writeOutput();
    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,587
    Rep Power
    25

    Default

    Try debugging your code by adding some more println statements to show how the variables are changing.
    For example if total is made up of subtotal * tax where is subtotal set and what is its value after it is set and what is its value just before you use it?

  3. #3
    eppoair2 is offline Member
    Join Date
    Nov 2010
    Location
    Virginia
    Posts
    14
    Rep Power
    0

    Default

    Thank you Norm for your fast response, I will try it right now; then get back to you

  4. #4
    Kidatheart96 is offline Member
    Join Date
    Dec 2013
    Posts
    16
    Rep Power
    0

    Default Re: Not getting the expected output. What is wrong with the coding ?

    I'm having a similar problem. How did you solve your program?

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,786
    Rep Power
    5

    Default Re: Not getting the expected output. What is wrong with the coding ?

    This thread is over two years old.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 02:37 AM
  2. Replies: 3
    Last Post: 04-19-2011, 07:21 PM
  3. output not as expected.What's wrong?
    By abdullahansari in forum New To Java
    Replies: 1
    Last Post: 12-03-2010, 09:01 PM
  4. output not what expected!
    By aza101 in forum Java Applets
    Replies: 0
    Last Post: 07-10-2009, 07:17 AM
  5. Replies: 11
    Last Post: 05-24-2008, 05:26 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
  •