Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 3 123 LastLast
Results 1 to 25 of 52

Thread: car rental (project)

  1. #1
    Junior Member
    Join Date
    Feb 2018
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default car rental (project)

    good day I am clive nys a 3rd year highschooler in the philipines and want to ask you guys if i can get some help with our project that we have

    the project is to create a car rental using either filereader, file writer or buffered, our teacher said that we only need to get the ff.

    1. what kind of car you are gonna rent
    2. how many days
    3.how much per day
    4. the total cost

    our deadline will be on march the 6th and i hope that i will you will help me

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: car rental (project)

    Do you have any specific questions about your project?
    What have you tried?

    Be sure to wrap all posted code in code tags.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    clive nys (February 24th, 2018)

  4. #3
    Junior Member
    Join Date
    Feb 2018
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: car rental (project)

    i dont have any posted code or code tags since i dont know where to begin and the spesific questions about our project is
    1.what kind of car you wanna rent
    2.how much per day is the car
    3.for how many days you wanna rent
    4. the total cost

    that is all of the questions

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: car rental (project)

    The questions you posted look like what the program would ask the user. It appears to be an exact copy of the first post.

    I was asking you for what java programming questions you have about how to design and write the program.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #5
    Junior Member
    Join Date
    Feb 2018
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: car rental (project)

    im sorry since i am just learning about java and all and may be confused with what you are asking
    and so if im understanding this correctly then my questions are 1. what kind of method of the three ( filewriter, ""reader, or mixed) should i use 2. what should i use with the method (ex. loops)

    so the program should do something like this:

    what kind of car do you want to rent: toyota
    for how many days: 6
    the total cost will be: 1200 dollars

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: car rental (project)

    Is the program supposed to have a GUI window with input fields, display areas and buttons
    or will it use a command prompt to get user input and display results?

    If it uses the command prompt window, you can use the println method to display output on the console
    and the Scanner class's next... methods to read user input.

    Before writing any code you should make a list of the steps the program needs to take to solve the problem.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #7
    Junior Member
    Join Date
    Feb 2018
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: car rental (project)

    imm gonna try what you have said but im still wondering how to add either filewriter or reader to my program and which is the easiest to add

  9. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: car rental (project)

    Before worrying about what classes and methods to use you need to make a design for the program.
    Once you have a list of the steps then worry about how to implement those steps.

    wondering how to add either filewriter or reader
    Which step in the program's design are you working on?
    A writer and a reader are for different purposes.
    One outputs some data like to ask a user a question
    the other reads some data like to get the user's input.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #9
    Junior Member
    Join Date
    Feb 2018
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: car rental (project)

    i have started and have finished with the " how many days to rent" but now im stuck with the "what kind of car to rent" and adding a value to each kind of car

    so far this is what i have done and need help with what to do next

    import java.util.Scanner;

    public class gg
    {
    public static void main(String[] args)
    {

    Scanner input = new Scanner(System.in);

    int daysNumber = 0;

    System.out.print("Enter the Number of Days: ");



    daysNumber = input.nextInt();

    double totalRentalCharge = 0.0;

    totalRentalCharge = daysNumber;

    System.out.println("Total Rental Charge is: " + totalRentalCharge);
    }}

  11. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: car rental (project)

    stuck with the "what kind of car to rent"
    Can you explain what needs to be done for that?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    Note: program statements should be indented to show nesting level
    There should not be more than } on a line. Each } should be in the same column as the start of the statement that has the pairing }
    If you don't understand my answer, don't ignore it, ask a question.

  12. #11
    Junior Member
    Join Date
    Feb 2018
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: car rental (project)

    the thing that im confused with is what kind of data type should i use for "what kind of car to rent?

  13. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: car rental (project)

    what kind of data type should i use for "what kind of car to rent?
    What are the choices for "kind of car"?
    Can you use a String for each kind
    or a digit/letter (1 for 2-seater, 2 for truck, 3 for 4-door, etc)?
    If you don't understand my answer, don't ignore it, ask a question.

  14. #13
    Junior Member
    Join Date
    Feb 2018
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: car rental (project)

    now im stuck with how to give each number (up to 4) a vaule like 1 = 500

    [code]import java.util.Scanner;

    public class gg
    {
    public static void main(String[] args)
    {

    Scanner input = new Scanner(System.in);

    int carNumber = 0;
    int daysNumber = 0;

    System.out.print("Enter the Number of car: ");

    carNumber = input.nextInt();

    System.out.print("Enter the Number of Days: ");

    daysNumber = input.nextInt();

    double totalRentalCharge = 0.0;

    totalRentalCharge = daysNumber;

    System.out.println("Total Rental Charge is: " + totalRentalCharge);
    }
    }
    {/code]

    --- Update ---

    now im stuck with how to give each number (up to 4) a vaule like 1 = 500

    import java.util.Scanner; 
     
    public class gg
    {
    public static void main(String[] args) 
    {
     
    Scanner input = new Scanner(System.in);
     
    int carNumber = 0;
    int daysNumber = 0;
     
    System.out.print("Enter the Number of car: ");
     
    carNumber = input.nextInt();
     
    System.out.print("Enter the Number of Days: ");
     
    daysNumber = input.nextInt();
     
    double totalRentalCharge = 0.0;
     
    totalRentalCharge = daysNumber;
     
    System.out.println("Total Rental Charge is: " + totalRentalCharge);
    }
    }
    Last edited by Norm; February 24th, 2018 at 11:44 AM. Reason: Changed { to [ on end tag

  15. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: car rental (project)

    The posted code has lost all its indentations. Statements should not all start in column 1.
    indent the statements to show there logical nesting.
    Inside class - indent 3
    inside method indent 3 - now indented 3+3 = 6
    There should never be a } immediately above another }. The top one should be indented.

    how to give each number (up to 4) a vaule like 1 = 500
    Where are the "numbers' coming from? What data type are they? int, char or String?
    One way to get values for user's input would be with a switch statement.
       switch(userInput) {
          case "1":
             value  = 500;
             break;

    Notice the statements' indentations.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #15
    Junior Member
    Join Date
    Feb 2018
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: car rental (project)

    where should i put the switch statement or between what line should i put it in
    Last edited by clive nys; February 24th, 2018 at 12:11 PM.

  17. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: car rental (project)

    Put it after where you have obtained the user's input
    and before where you need the value associated with the user's input.
    If you don't understand my answer, don't ignore it, ask a question.

  18. #17
    Junior Member
    Join Date
    Feb 2018
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: car rental (project)

    what do i need to do so that when i put 5 or more in the "number of car" it will say that " that is not a valid car, pls try again"

    Scanner input = new Scanner(System.in);
     
    int carNumber = 0;
    int daysNumber = 0;
     
    System.out.print("Enter the Number of car: ");
     
    carNumber = input.nextInt();
     
    System.out.print("Enter the Number of Days: ");
     
    daysNumber = input.nextInt();
     
    switch(carNumber) {
        case 1:
        carNumber = 500;
        case 2:
        carNumber = 600;
        case 3:
        carNumber = 700;
        case 4:
        carNumber = 800;
        break;
    }
     
    double totalRentalCharge = 0.0;
    totalRentalCharge = daysNumber;
     
    System.out.println("Total Rental Charge is: " + totalRentalCharge);
    }
    }
    Last edited by clive nys; February 24th, 2018 at 12:43 PM.

  19. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: car rental (project)

    which part do i need to correct on my switch case
    Please explain why you think there is a problem.

    Have you read the tutorial about switch statements: https://docs.oracle.com/javase/tutor...ts/switch.html



    Note: The posted code still does not have proper indentations. Please fix it.
    If you don't understand my answer, don't ignore it, ask a question.

  20. #19
    Junior Member
    Join Date
    Feb 2018
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: car rental (project)

    ok now that i have done that,what do i need to do so that when i put 5 or more in the "number of car" it will say that " that is not a valid car, pls try again"

  21. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: car rental (project)

    Use an if statement to test if the number is valid.
    What should the code do if it displays a message that says: "pls try again"?
    If you don't understand my answer, don't ignore it, ask a question.

  22. #21
    Junior Member
    Join Date
    Feb 2018
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: car rental (project)

    should i put the if statement after the switch statement and should i use the if-then statement

  23. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: car rental (project)

    should i put the if statement after the switch statement
    Back to doing some design work BEFORE writing any code.

    What steps does the program need to take to solve the problem?
    Make a list first and check that the steps will work.
    Then start at the top of the list and write the code for each step.
    Some steps will take more sub-steps to solve what they are supposed to do.

    Post the steps for the design of this program
    and then ask your question about how to implement that step.
    If you don't understand my answer, don't ignore it, ask a question.

  24. #23
    Junior Member
    Join Date
    Feb 2018
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: car rental (project)

    this is what ive done so far

    Scanner input = new Scanner(System.in);
     
                int carNumber = 0;
                int daysNumber = 0;
     
                System.out.print("Enter the Number of car: ");
                 if (carNumber<5){
                System.out.println("pls try again");
                carNumber = input.nextInt();
     
                System.out.print("Enter the Number of Days: ");
     
                daysNumber = input.nextInt();
     
                switch(carNumber) {
                    case 1:
                    carNumber = 500;
                    case 2:
                    carNumber = 600;
                    case 3:
                    carNumber = 700;
                    case 4:
                    carNumber = 800;
                    break;
                }
     
     
                }
     
                double totalRentalCharge = 0.0;
                totalRentalCharge = daysNumber*carNumber;
     
                System.out.println("Total Rental Charge is: " + totalRentalCharge);
    }
    }

  25. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: car rental (project)

    Ok, those are java statements.

    What design do you have for what the program should do? The steps in a design are not java statements.
    They would be short phrases describing what the code would do.
    For example
    Prompt user for type of fruit
    Read user's response
    test response is valid
    if not valid display a message and loop back to the prompt
    ...
    If you don't understand my answer, don't ignore it, ask a question.

  26. #25
    Junior Member
    Join Date
    Feb 2018
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: car rental (project)

    how exactly should i put it in the program? should i add to the if statement i have?

Page 1 of 3 123 LastLast

Similar Threads

  1. Rental Management System
    By Yigs in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 1st, 2014, 04:40 AM
  2. car racing project
    By mike416 in forum AWT / Java Swing
    Replies: 3
    Last Post: August 16th, 2013, 10:29 PM
  3. Working on a Car Rental Program and need to finish by Tonight!!
    By alexsport93 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 13th, 2012, 11:08 PM
  4. The car/vehicle application will be responsible for providing a car simulation.
    By vikasreddy556 in forum What's Wrong With My Code?
    Replies: 13
    Last Post: June 20th, 2011, 01:32 AM