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.
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.
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.
what do you mean by program design steps
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.
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
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?
Not yet. The steps do NOT include any java classes or statements. They are all just statements of the logic.the program should also have filereader
If you don't understand my answer, don't ignore it, ask a question.
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
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?
Each step should be simplestep 3, the program needs to read the users input then ...
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.
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)
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
Normally programs do not stop because of bad input. They should print a message and allow the user to try again.the program should "stop"
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.
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
Which step in the list of steps for the program are you asking about?where do you add the file writer in the code
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.
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
Which step in the list of steps are you talking about?which would be better for the coding filereader or writer
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.
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.
Does it compile without errors?how is the coding/?
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.
i thought that you will write the step for me like you said in #26
That appears to ask you to write the programs steps so I could help you with any you are having problems with.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 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.
ok then, how do you add the loop case using the if statement
Are you asking about validating a user's input?the loop case using the if statement
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.
since im currently stuck in step 2 where if the number is higher than 4 you bring them back to step 1
Yes that is what a loop does.bring them back to step 1
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.
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); } }
Please explain what happens when the code is compiled and executed.im still stuck with the loop
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.
im stuck with what the condition in the while loop, and is the statement that i have already ok or does it need tweeks
Describe when you want the loop's execution to continue and when you want it to end?the condition in the while loop
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.