• 10-23-2009, 05:52 AM
SwEeTAcTioN
Alright i got 2 assignments i have to do for computer science and have some questions.

first is a parking garage program
what you have to do is ask how many minutes they parked.DONE
compute what they owe you.Done
the next thing is if they stayed for part of an hour they have to pay for the full hour. Any suggestions on how to do that????

would i use a loop?

All help is appreciated very much
Code:

```import java.io.*; public class Temp {         public static void main(String[] args) throws IOException {             BufferedReader input= new BufferedReader(new InputStreamReader(System.in));                 int minutesstayed;         System.out.println("Welcome to NO DENTS PARKING GARAGE");         System.out.println();         System.out.println("How long did you park for (in minutes)");         minutesstayed=Integer.parseInt(input.readLine());         double charge=0.75*(minutesstayed/60);         System.out.println("Your Parking Fee is:"+" "+charge);                                 } }```
The other question is i wrote a program that computes how many coins to give back in change and at the end of the program i ask if the want to do the program again and if they type yes it executes in program again if they type no then it exits out of the program

How do i do that???? i already did the change and coins but i dont know how to do the yes,no part

Im sorry i dont have the code i left it at school

But any help is appreciated
• 10-23-2009, 07:15 AM
Lizzip
For the paying for the full hour problem, after the user inputs their number of minutes stayed you could divide the result by 60. If the answer is below 1, set the minutesStayed to 60. If its between 1 and 2, set it to 120 etc. Probably not the best solution, but as long as you dont have an indefinate amount of hours the people could stay in the carpark, it will work.

As for the yes/no do program again thing, you could put the whole program in a while loop and use a bool to determine wether or not to run the program again