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 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 52

Thread: car rental (project)

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

    Default Re: car rental (project)

    Please list the program design steps so we can see what you are working on and be able to write the statements for the step you are working on.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: car rental (project)

    what do you mean by program design steps

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

    Default Re: car rental (project)

    See the example in my post#24
    A list of the steps the program would take to solve the problem written in English.

    Here is another example for the steps in program development:
    1) design the program
    2) write the code
    3)compile the code
    4) if compiler errors go back to step 2
    5) execute the code for testing
    6) if errors found go back to step 1 and fix the logic
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: car rental (project)

    so like this?

    promt user what number of the car to rent
    if the num. of the car is greater than 4 "pls try again"
    type the num of days you want to rent
    give the total cost of (car rented price * days rented)

    --- Update ---

    wait i forgot to add that the program should also have filereader

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

    Default Re: car rental (project)

    Ok, that's a start.
    Where does the program read the first user input?

    What should the program do after it shows the message: "pls try again"

    What should the program do after step 3: type the num of days you want to rent
    Does the program need to read the user's input?

    Does "give" mean to display something to the user on the console?

    the program should also have filereader
    Not yet. The steps do NOT include any java classes or statements. They are all just statements of the logic.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: car rental (project)

    if the command for 2 is valid then it should stop after you typed like 5, btw each of the int have a value(1=400,2=500,3=600,4=700).
    as for step 3, the program needs to read the users input then multiply it by the value given by step 2 where it will show on step for the total amount of it

    ex for step 2
    enter the number of the car: 5
    pls try again

    as for the complete step
    enter the number of the car: 2
    enter the number of days: 8
    total rent is: 4000

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

    Default Re: car rental (project)

    You have skipped over completing the steps that were listed in post#29.

    Please update that list with the added steps I recommended and any you think are needed.

    For example you say: it should stop after you typed like 5
    Is that after the message: "pls try again" is shown?
    Are you saying the program should "stop" after showing that message?

    step 3, the program needs to read the users input then ...
    Each step should be simple
    the then... part should be in the next steps. For these two steps:
    multiply it by the value given by step 2 where
    it will show ...
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: car rental (project)

    step 1 the program ask you "Enter the number of the car"
    step 2 if the number is higher than 4 the program should "stop" while if its lower than 5 it should proceed to step 3
    step 3 the program ask you "Enter the number of days" ,after the user has typed in the number,the program should switch the number of the car for the value (1 =400,2=500,3=600,4=700) and multiply it by the number of days
    step 4 the program shows you the the total cost (which is the last part of step 3)

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

    Default Re: car rental (project)

    Step 3 has too many parts. It should be broken up:
    3) program ask you "Enter the number of days" ,
    4)after the user has typed in the number,
    5)the program should switch the number of the car for the value (1 =400,2=500,3=600,4=700)
    6)and multiply it by the number of days

    the program should "stop"
    Normally programs do not stop because of bad input. They should print a message and allow the user to try again.
    That is done by putting the code for getting the input inside of a loop and not allowing execution to exit the loop until valid input is read from the user.
    A program can exit/stop by calling the System exit method, but that is very unusual.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: car rental (project)

    so instead of stoping the code it would be better to do a loop,ok thats fine but ihave a question where do you add the file writer in the code

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

    Default Re: car rental (project)

    where do you add the file writer in the code
    Which step in the list of steps for the program are you asking about?
    I don't see anything in the list about writing files.
    If there are supposed to be files written, could you complete the list with the steps that shows when file writing should be done?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: car rental (project)

    before i want to edit the list i want to ask which would be better for the coding filereader or writer since our teacher dint say which to use to use and said its our choise

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

    Default Re: car rental (project)

    which would be better for the coding filereader or writer
    Which step in the list of steps are you talking about?
    Pick one step and ask some specific questions about whether to use filereader or writer when coding that step.

    The steps listed so far have not talked about disk files so I don't see where you would use either of those.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: car rental (project)

    nvm it, lets ignore it for now since i want to ask my teacher about it more spesifically. so how is the coding/?
    Last edited by clive nys; February 24th, 2018 at 03:19 PM.

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

    Default Re: car rental (project)

    how is the coding/?
    Does it compile without errors?
    Does it execute and produce the desired results?
    Have you tested it with different values to see what it does with good and bad input?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: car rental (project)

    i thought that you will write the step for me like you said in #26

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

    Default Re: car rental (project)

    Please list the program design steps so we can see what you are working on and be able to write the statements for the step you are working on.
    That appears to ask you to write the programs steps so I could help you with any you are having problems with.
    If you have the list of steps and are having problems with one, post the step and ask your questions about that step.
    The idea is you write the code for a step and ask questions about what you need help with to get the code to work.

    If you need to finish writing the steps for the program, go ahead and finish writing the steps and post them.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: car rental (project)

    ok then, how do you add the loop case using the if statement

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

    Default Re: car rental (project)

    the loop case using the if statement
    Are you asking about validating a user's input?

    Here is one way to use a loop to validate user input:
    Begin loop
    prompt for user's input
    read user's input
    test user's input
    if input is valid exit loop
    end loop - here execution goes back to the Begin loop

    Look at using a while loop with a boolean variable to keep the loop going. When the input is valid, change the boolean variable's value to allow the loop to exit.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: car rental (project)

    since im currently stuck in step 2 where if the number is higher than 4 you bring them back to step 1

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

    Default Re: car rental (project)

    bring them back to step 1
    Yes that is what a loop does.

    Begin loop
    step 1
    if input <= 4, exit loop
    // input > 4 so loop back to step 1
    end loop

    Another way to exit a loop is by using the break statement.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: car rental (project)

    im still stuck with the loop. pls help

    Scanner input = new Scanner(System.in);
     
                int carNumber = 0;
                int daysNumber = 0;
     
     
                System.out.print("Enter the Number of car: ");
                while (!carNumber) {
                if (carNumber >5) 
                break;
                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);
        }
    }

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

    Default Re: car rental (project)

    im still stuck with the loop
    Please explain what happens when the code is compiled and executed.
    What do you need help with?

    Also please fix the indentation of the statements to show what is inside the while loop:
       while(condition) {
          statement 1
          statement 2
       }
       next statement

    The code does not appear to follow the list of steps for the program.
    The prompt for input should be inside the loop.
    It does not read the user's input before testing it.
    It exits the loop with invalid input
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: car rental (project)

    im stuck with what the condition in the while loop, and is the statement that i have already ok or does it need tweeks

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

    Default Re: car rental (project)

    the condition in the while loop
    Describe when you want the loop's execution to continue and when you want it to end?
    Since the posted code uses a break statement, you could use the value: true as the condition
    so that the loop continues until the break statement is executed.
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 3 FirstFirst 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