Hanging program; please help

import cs1.Keyboard;
public class Lab3Prog2Stage3 {
   public static void main(String[] args) {
      final int PENNY_VALUE = 1;
      final int NICKEL_VALUE = 5;
      final int DIME_VALUE = 10;
      final int QUARTER_VALUE = 25;
      int penniesAvail;
      int nickelsAvail;
      int dimesAvail;
      int quartersAvail;
      int pennies;
      int nickels;
      int dimes;
      int quarters;
      int penniesFinal;
      int nickelsFinal;
      int dimesFinal;
      int quartersFinal;
      int change;
      do {
         System.out.print("Enter change drawer counts (Q, D, N, P): ");
         quartersAvail = Keyboard.readInt();
         dimesAvail = Keyboard.readInt();
         nickelsAvail = Keyboard.readInt();
         penniesAvail = Keyboard.readInt();
         if (quartersAvail < 0 || dimesAvail < 0 || nickelsAvail < 0 ||
          penniesAvail < 0)
            System.out.println("No negative values allowed");
      while (quartersAvail < 0 || dimesAvail < 0 || nickelsAvail < 0 ||
       penniesAvail < 0);
      System.out.println();
      System.out.print("Enter change to make: ");
      change = Keyboard.readInt();
      while (change < 0) {
         System.out.print("Change must be a nonnegative number: ");
         change = Keyboard.readInt();
      do {
         quarters = 0;
         while (change >= QUARTER_VALUE) {
            quarters++;
            change = change - QUARTER_VALUE;
      while (quarters <= quartersAvail);
      do {
         dimes = 0;
         while (change >= DIME_VALUE) {
            dimes++;
            change = change - DIME_VALUE;
      while (dimes <= dimesAvail);
      do {
         nickels = 0;
         while (change >= NICKEL_VALUE) {
            nickels++;
            change = change - NICKEL_VALUE;
      while (nickels <= nickelsAvail);
      do {
         pennies = 0;
         while (change >= PENNY_VALUE) {
            pennies++;
            change = change - PENNY_VALUE;
      while (pennies <= penniesAvail);
      penniesFinal = penniesAvail - pennies;
      nickelsFinal = nickelsAvail - nickels;
      dimesFinal = dimesAvail - dimes;
      quartersFinal = quartersAvail - quarters;
      System.out.print("Quarters: " + quarters + " Dimes: " + dimes +
       " Nickels: " + nickels + " Pennies: " + pennies);
      System.out.print("Left in drawer: " + quartersFinal + " quarters, " +
       dimesFinal + " dimes, " + nickelsFinal + " nickels and " + penniesFinal
       + " pennies");
}Sample run 1:
Enter change drawer counts (Q, D, N, P): 2 -1 1 20
No negative values allowed
Enter change drawer counts (Q, D, N, P): 2 1 -2 20
No negative values allowed
Enter change drawer counts (Q, D, N, P): 2 1 1 20
Enter change to make: 77
Quarters: 2 Dimes: 1 Nickels: 1 Pennies: 12
Left in drawer: 0 quarters, 0 dimes, 0 nickels and 8 pennies
When I input the change to make, instead of telling me how much of each denomination was used and how much of each denomination I have remaining, the program just hangs idly:
Enter change to make: 77
(nothing)
Might anyone give me some advice as to how to tackle this enigma?

do {
quarters = 0;
while (quartersAvail >= 0) {
while (change >= QUARTER_VALUE) {
quarters++;
change = change - QUARTER_VALUE;
quartersAvail = quartersAvail - 1;
while (quartersAvail >= 0); How come I'm getting negative returns?The issue here is because of you are doing a post-test loop instead of a pre-test loop. In a post-test (like the do/while you are using) the loop is execute once and then continues if the condition is true. Also your spacing makes it a little confusing and many people (like one of the earlier posters) may not realize at first that the while statements are part of the previous do statement instead of a loop to themselves.
ex. post-test
  int i=0;
  do {
    i++;
  } while( false);
  System.out.println(i);  // output should be 1
ex: pre-test
  int i=0;
  while(false) {
    i++;
  System.out.println(i);  // output should be 0

Similar Messages

  • My MacBook get's hot really quick and then discharge's quickly without opening any program, please help.

    My MacBook get's hot really quick and then discharge's quickly without opening any program, please help.
    I have checked the cooling fan, and it's working, and I took it to an IT technician and he said my hardware is allright, so is it a problem from the OS it self??
    OS X(10.8.5)

    Restart with the Option key held down and the Mac OS X install disk inserted, provide the firmware password, click on the DVD, press the button with the straight arrow, access the firmware settings, disable the password, and use FireWire Target Disk mode. If you can't do that or it doesn't work, contact Apple.
    (38384)

  • Update to the new release and firefox hangs and becomes unresponsive each time I try to open it. I have tried removing firefox from my pc, restarted my pc. went to Google Chrome and downloaded it again. Still hanging. Please help

    Update to the new release and firefox hangs and becomes unresponsive each time I try to open it. I have tried removing firefox from my pc, restarted my pc. went to Google Chrome and downloaded it again. Still hanging. Please help
    I can open Google Chrome and IE without any problems. My new version of Thunderbird won't let me see messages.

    So i have just unistalled itunes logged on to apple to try and download the itunes prog ,but it dont seem to have downloaded.can anyone help me please.
    Could you walk us through what happened when you tried to do the download, please?

  • I have windows 8 and I got this error "Adobe Photoshop has stopped working" whenever I start a program. please help. how can I fix this problem? many thanks

    i have windows 8 and I got this error "Adobe Photoshop has stopped working" whenever I start a program. please help. how can I fix this problem? many thanks

    Please read these and proceed accordingly:
    http://blogs.adobe.com/crawlspace/2012/07/photoshop-basic-troubleshooting-steps-to-fix-mos t-issues.html
    http://forums.adobe.com/docs/DOC-2325

  • SDM hangs forever, please help.

    After start RemoteGui.bat, we enter the password, then
    hit enter, the hourglass hangs forever.
    No errors found in the logs.
    Please help, points guaranteed . Thanks!

    Hi,
    its is due to duplicate deploymet in SDM Repository.
    Try this out..
    1)Take a backup copy of the sdmrepository.sdc file from       \usr\sap\<SID>\JC<instno>\SDM\program\config\
    2)Stop the SDM from MMC.
    3)Edit the sdmrepository.sdc file using WordPad.
    4)In the deploy container part of the SDM repository (this is the second half of the  file  between the <DeploymentContainer> pair of tags),  search for the string " 2"
    5)if you found more than one value. delete all except one...
    6)Delete all space between the <SdaDeployment> pair for deployment with ID "com.sap.sen.permissions 2", including the <SdaDeployment> tags .
    (A corrected repository should not contain any IDs with trailing numbers.)
    7)Try the above procedure for occurrences of " 3", " 4", ... " N"(normally you will not find the occurance of "2" more than once..so u can ignore the rest.
    8)     Save the file and restart the SDM
        "   Solution: - Apply note no 824357  "
    Regards,
    Arun

  • Error while running HelloWorld program Please Help me

    Hi Friends! I am doing my hello world program...while running i m getting the below error...please help me regarding this...
    The target WSCO.java cannot be started as a servlet, because the class oracle.apps.ak.ws.webui.WSCO does not extend javax.servlet.GenericServlet.
    The target WSCO.java cannot be started as an application, because the class oracle.apps.ak.ws.webui.WSCO does not have a main method.

    Hi,
    For building a simple hello world page, follow these steps:
    1) Create a New OA Workspace and a new OA Project. Make sure that package name should be prefixed by some custom name like:
    xx.oracle.apps.ak.hello
    2) Create new OA Page under webui:
    xx.oracle.apps.ak.hello.webui.XxHelloWorldPG
    3) Create a new Application module, XxHelloWorldAM in below package:
    xx.oracle.apps.ak.hello.server.XxHelloWorldAM
    4) Attach this AM to your XxHelloWorldPG.
    5) Now create regions and items under pageLayout region of this page.
    6) Add a controller to pageLayout region in webui package:
    xx.oracle.apps.ak.hello.webui.XxHelloWorldCO
    Also you can add a button on the page and write some code in PFR method of your controller.
    --Sushant                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Problem compiling my first program; Please Help me!

    Please HELP, what am I doing wrong?
    For over 5hours I have been trying to figure out how to compile a simple Hello world program using sdk1.3.1_02/j2re1.3.1_02 and I am getting the following errors: helloworld.java:2 cannot resolve symbol
    symbol : class string
    location : class helloworld
    cannot reolve the string symbol
    symbol : class out
    location : package system
    I want to program in java so badly but I am trying to get my environment set so that I can take off. To compile my first program has been a disaster!!
    This is my path:
    SET PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\JDK1.3.1_02\BIN
    Thanks very much in advance
    ::(

    Java is case sensitive,
    use String instead of string. and System.out instead of system.out
    Sudha

  • I paid for membership and cannot access the program please help???????

    I paid for the program and cannot access it please help may i talk to someone?

    Did you install the trial or any update version?
    What were the instructions when you purchased?

  • Connecting two programs - please help

    Hi, I'm new here, so I'd like to say 'hi' to everyone :) I'm a freshman in the java comunity, so please be gentle.
    Firs of all I'd like to ask how to resolve the first problem. I've got the code which is responsible for convert a html document to the txt file. It looks like:
    import javax.swing.text.html.parser.*;
    import javax.swing.text.html.*;
    import javax.swing.text.*;
    import javax.swing.*;
    import java.io.*;
    public class TextFromHtml extends HTMLEditorKit.ParserCallback{
    static String trimmss(String o){
       return (o.trim()).replaceAll("\\s+", " ");
    public void handleText(char[] data, int pos){
    try{
          String o = new String(data);
          PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("test.txt", true)));
          o = trimmss(o);
          pw.println(o);
          //pw.close();
         catch (IOException exc){}      
    System.out.println(new String(data));
      public static void main(String args[]){
        try{
          String s = JOptionPane.showInputDialog("Enter the name of the file you want to convert from html to txt.");     
          Reader r = new FileReader(s);
          ParserDelegator parser = new ParserDelegator();
          HTMLEditorKit.ParserCallback callback = new TextFromHtml();
          parser.parse(r, callback, true); 
        catch (IOException e){
          e.printStackTrace();
         System.exit(0);
    }But unfortunately I don't know how to change this code to obtain such situation as making a new txt file without blank spaces > 0 and erasing the \n new lines. I'd like to get a txt file, which contains of line-by-line text. Could you please help me - tell & show me how to do that? I'd be very grateful
    Regards, skullscape.

    Hi Skullscape,
    My apologies for not getting a response on this forum, but this may have been because this is a fairly generic Java programming question, rather than an issue specific to the JSE product, the purpose of this particular forum.
    So may I suggest that you check out http://java.sun.com/ which has a full set of facilities for those such as yourself who are new to Java programming.
    Although by now you nay not be such a novice :-)

  • Deleted apple mail program, please help!

    I deleted mail, and can't seem to find it within the 'install bundled software' on the discs which came with the computer (mac os x install discs 1 & 2). How can I go about reinstalling the program? Please Help...

    Hi Rob, and a warm welcome to the forums!
    Is that the Install Disk?
    Custom installs in Mac OS X 10.4...
    http://docs.info.apple.com/article.html?artnum=301229
    "Here's a list of all the custom installation options available with Optional Installs.mpkg:
    * Applications
    o Address Book 4.0
    o iCal 2.0
    o iChat 3.0
    o iTunes 4.7.1
    o Mail 2.0
    o Oxford Dictionaries
    o Safari 2.0
    o X11"
    If that isn't the case, get Pacifist...
    http://www.charlessoft.com/
    then extract what you need from your Install Disk.

  • Problem with simple drawing program - please help!

    Hi,
    I've only just started using Java and would appreciate some help with a drawing tool application I'm currently trying to write.
    The problem is that when the user clicks on a button at the bottom of the frame, they are then supposed to be able to produce a square or circle by simply clicking on the canvas.
    Unfortunately, this is not currently happening.
    Please help!
    The code for both classes is as follows:
    1. DrawToolFrame Class:
    import java.awt.*;
    import java.awt.event.*;
    public class DrawToolFrame extends Frame
    implements WindowListener
    DrawToolCanvas myCanvas;
    public DrawToolFrame()
    setTitle("Draw Tool Frame");
    addWindowListener(this);
    Button square, circle;
    Panel myPanel = new Panel();
    square = new Button("square"); square.setActionCommand("square");
    circle = new Button("circle"); circle.setActionCommand("circle");
    myPanel.add(square); myPanel.add(circle);
    add("South", myPanel);
    DrawToolCanvas myCanvas = new DrawToolCanvas();
    add("Center", myCanvas);
    square.addMouseListener(myCanvas);
    circle.addMouseListener(myCanvas);
    public void windowClosing(WindowEvent event) { System.exit(0); }
    public void windowOpened(WindowEvent event) {}
    public void windowIconified(WindowEvent event) {}
    public void windowDeiconified(WindowEvent event) {}
    public void windowClosed(WindowEvent event) {}
    public void windowActivated(WindowEvent event) {}
    public void windowDeactivated(WindowEvent event) {}
    2. DrawToolCanvas Class:
    import java.awt.*;
    import java.awt.event.*;
    public class DrawToolCanvas
    extends Canvas
    implements MouseListener, ActionListener {
    String drawType="square";
    Point lastClickPoint=null;
    public void drawComponent(Graphics g) {
    if (lastClickPoint==null) {
    g.drawString("Click canvas first",20,20);
    } else {
    if (drawType.equals("square")) {
    square(g);
    else if (drawType.equals("circle")) {
    circle(g);
    public void actionPerformed(ActionEvent event) {
    if (event.getActionCommand().equals("square"))
    drawType="square";
    else if (event.getActionCommand().equals("circle"))
    drawType="circle";
    repaint();
    public void mouseReleased(MouseEvent e) {
    lastClickPoint=e.getPoint();
    public void square(Graphics g) {
    g.setColor(Color.red);
    g.fillRect(lastClickPoint.x, lastClickPoint.y, 40, 40);
    g.setColor(Color.black);
    public void circle(Graphics g) {
    g.setColor(Color.blue);
    g.fillOval(lastClickPoint.x, lastClickPoint.y, 40, 40);
    g.setColor(Color.black);
    public void mouseEntered(MouseEvent e) {}
    public void mouseExited(MouseEvent e) {}
    public void mousePressed(MouseEvent e) {}
    public void mouseClicked(MouseEvent e) {}
    Any help would be appreciated!

    Some of the problems:
    1) nothing calls drawComponent(Graphics g)
    2) Paint(Graphics g) has not been overriden
    3) myCanvas is declared twice: once as an instance variable to DrawToolFrame, and once local its constructor. Harmless but distracting.

  • HT6114 hi all, my cisco Router link sys E2000 stop working need to up date Mac OS 10.4.9 or 10.5.8 or 10.6.1later how do i find this program please help

    hi all, my cisco router linksys E2000 stop working need to up date Mac OS 10.5.8 later or 10.5.8 or later or 10.6.1 or later where do i find this up date im new on mac computer please help

    I just visited the Linksys e2000 page, I think you need 10.6. You can buy it here:
    http://store.apple.com/us/product/MC573Z/A/mac-os-x-106-snow-leopard

  • Can't Install Windows Program -PLEASE HELP

    This is now my 3rd attempt at trying to install stupid Windows on my Mac (need for merchant account and quickbooks).
    Anyway, I ordered Microsoft XP 2000 Home OEM. I actually go a link from a person on this board. I am a little concerned because the packaging and CD says 'to be distributed with a new PC'. It has been my problem that I have been using Free software and it won't take the Free version.
    Okay, here is what I have done so far
    1. Partitioned HD for Windows in Bootcamp
    2. Inserted new Windows CD
    3. Screen goes White(ish) and you here the Windows (bong).
    4. CD ejects
    5. Screen goes black and then you get a message that says 'no bootable device insert boot disk press any key)
    6. Reinsert CD, nothing happens
    Concern is there is some old Windows on this when I have tried to download in the past. I however cannot find anywhere and believe that I ahve removed everything. I did download a trial version of Parallels and tried to download another Windows version, but I removed everything from my computer that had to do with Paralles (or so I thought...even emptied trash).
    So, I am DESPERATE!! PLEASE HELP
    5. Insert

    Here is where I am now...
    I was able to remove Windows from Bootcamp.
    I go through the set up again.
    I get through everything and it says the computer will reboot and continue with setup.
    During the reboot, the disk ejects, then I get a black screen that says Disk Error press any key. Nothing happens when you press a key and you have to manually shut down. When I reboot, I get two icons, MAC HD and Windows HD. Yet, nothing comes up when I click on Windows HD.
    PLEASE SOMEONE HELP ME. I have spent hours on this and I really don't think I am THAT stupid.
    I know people don't get paid to help, but if someone could walk me through this. Mac won't help me.

  • During table import, program get hang! please help

    parameter file is like:
    FILE=C:\xxxxx.DMP
    LOG=C:\IMPORT.LOG
    FROMUSER=ABC
    TABLES=(xxxxx)
    GRANTS=n
    INDEXES=n
    ROWS=y
    CONSTRAINTS=n
    no import is done. no error, no termination message. any idea? thanks

    What may appear to be a hang, could just be import building indexes, constraints or other db objects. To check, use the following parameters:
    rows=y
    indexes=n
    constraints=n
    if this is successful, then you can immediatly do another import with
    rows=n
    indexes=y
    constraints=y
    Please note, that both imports will import any procedures, functions or packages. (IMP really needs a code=n parameter).

  • New to the world of programing. please help!!

    ello every one.
    I want to start programing and create software on my mac.
    where do i start? i was playing around with terminal and thougth it was cool.
    i went on the net and came across python and discovered it was already in my mac. i dabed with it and it is not easy. all the tutorials iv read seem to be written for someone who has programing experience. Are there any books, websites, anything that will break down programing in python "BARNEY" style.
    or is python the way to go for super beginers. Anyone who can help please do it will be greatly appreciated. Thanks to all.

    Hi,
    Welcome to Apple Discussions! If you want to do programming on your Mac, you'll first want to install the necessary compilers and other tools required. You'll find these on the DVD entitled "XCode" that came with your system. Install XCode first. Then, I'd recommend getting familiar with the software on your machine first, before installing open source software available on the web. You'll probably already have what you want. For example, Perl and MySQL are also included on your machine, in addition to Python, as you have already found out.
    I'd suggest reading the Getting Started page at the Apple Developer Connection, and the Fink website to get an overview of open source software available for OSX.
    As for Python, there's a lot out there on the web. Here is an easy tutorial for non-programmers. Enjoy!
    Ed
    PB G4   Mac OS X (10.2.x)  

Maybe you are looking for

  • I can no longer login to my Macbook Pro.

    Hello everybody, I am the owner of a Macbook Pro (bought it in 2010) with the newest Maverick software. There was an new update to be done (I don't really know which one), which went without problems. Afterwards I wanted to open mail, but I got a not

  • Applet needs browser to be restarted ?!?

    Hi again.. thats the problem: 1) I open FireFox2 2) i go to the Applet Page and make it start -> OK it works... 3) i close the Applet Page -> shutdown seems to be clear... 4) i go to the Applet Page and make it start -> it loads very quickly but it i

  • Audio Out Options?

    Hello, I have a question. I have a 7.1 Surround Sound Speaker set that I used to use with my Windows Based PC which had a Soundblaster Audigy 2 ZS sound card. I was wondering if there was a device I could purchase that would allow me to simply play m

  • Object Name

    How to pass object name to j.clsprint("j") ? rather than type "j" import java.lang.*; class clsone int j; int k; // Constructor Methods clsone(int x) j = x; // Overloading Constructors clsone(int x, int y) j = x; k = y; void clsprint(String x) System

  • No voice during incoming outgoing calls

    Hi, if anyone faced this issue before....there is no voice heard during incoming outgoing calls. However, we are able to talk on Skype or listen to music.