Results 1 to 2 of 2
  1. #1
    SwEeTAcTioN's Avatar
    SwEeTAcTioN is offline Member
    Join Date
    Oct 2009
    Posts
    69
    Rep Power
    0

    Question Question about loops

    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
    Java 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
    Are you suggesting that Cocunuts migrate?!! -Monty Python

  2. #2
    Lizzip is offline Member
    Join Date
    Oct 2009
    Posts
    12
    Rep Power
    0

    Default

    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

Similar Threads

  1. Help with loops!
    By jrelvi23 in forum New To Java
    Replies: 9
    Last Post: 09-04-2012, 01:36 PM
  2. these loops...
    By Blaedel in forum New To Java
    Replies: 0
    Last Post: 10-01-2009, 06:59 PM
  3. how to use do while loops
    By mikeitalydz in forum New To Java
    Replies: 32
    Last Post: 09-26-2009, 08:30 PM
  4. Question about loops
    By BHCluster in forum New To Java
    Replies: 4
    Last Post: 04-16-2008, 05:40 PM
  5. Loops (while do etc)
    By manupr in forum New To Java
    Replies: 1
    Last Post: 01-15-2008, 03:59 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
  •