Dollar Change Program Help needed!!

I need some immediate help writing a java program that determines change of 1 dollar recieved in the amout of quarters, dimes, and nickels when an item is purchased between the prices of 25cents and a dollar. For Example:
Total Money: $1 (static)
Enter the price of the item in cents: 45
You bought an item for 45 cent and gave me a dollar, so your change is:
2 quarters,
0 dimes, and
1 nickel.
That is the basics of what I need, and I am not sure where to start.

My program works as long as there is at least 1 penny to be given back in the change. I need help!
//          CoinCounter.java
//          This program counts the change given back from 1 dollar
//          in specific values such as quarters, dimes, and nickels
//          and pennies.
//          Written By Jasen Hudson
import javax.swing.*;
import cs1.Keyboard;
public class CoinCounter
{// Begin class CoinCounter
     public static void main(String[] args)
          {// Begin main method
               int cost = 0;
               int dollar = 100;
               int quarter = 25;
               int dime = 10;
               int nickel = 5;
               int penny = 1;
               int numQuarters = 0;
               int numDimes = 0;
               int numNickels = 0;
               int numPennies = 0;
//Item amount input
String input = JOptionPane.showInputDialog
("Please enter the amount paid for the item.");
cost = Integer.parseInt(input);
//While statement
     int changeRequired = dollar - cost;
     while(changeRequired > 0){
          if((changeRequired - quarter>= 0){
          numQuarters ++;
               changeRequired -= quarter;
                    continue;
          if(changeRequired - dime >= 0){
          numDimes ++;
               changeRequired -= dime;
                    continue;
          if(changeRequired - nickel >= 0){
          numNickels ++;
               changeRequired -= nickel;
                    continue;
          if(changeRequired - penny >= 0){
          numPennies ++;
               changeRequired -= penny;
//Amount of change needed to give back
     int change = dollar - cost;
//System print out
     System.out.println("The change required for $1.00 from an item costing "
          + cost + " Cents is " +change+ ". Here is your change:");
          System.out.println(numQuarters+" Quarters");
          System.out.println(numDimes+" Dimes");
          System.out.println(numNickels+" Nickels");
          System.out.println(numPennies+" Pennies");
          System.exit(0);
}

Similar Messages

  • Basic Java Program help needed urgently.

    I have posted the instructions to my project assignment on here that is due tomorrow. I have spent an extremely large amount of time trying to get the basics of programming and am having some difficulty off of the bat. Someone who has more experience with this and could walk me through the steps is what I am hoping for. Any Help however will be greatly appreciated. I am putting in a lot of effort, but I am not getting the results I need. Thank you for the consideration of assisting me with my issues. If you have any questions please feel free to ask. I would love to open up a dialogue.
    CIS 120
    Mathematical Operators
    Project-1
    Max possible pts 100
    Write a program “MathOperators” that reads two integers, displays user’s name, sum, product,
    difference, quotients and modulus of the two numbers.
    1. Create a header for your project as follows:
    * Prgrammer: Your Name (1 pt) *
    * Class: CIS 120 (1 pt) *
    * Section: (1 pt) *
    * Instructor: (1 pt) *
    * Program Name: Mathematical Operators (1 pt) *
    * Description: This java program will ask the user to enter two integers and *
    display sum, product, difference, quotients and modulus of the two numbers
    * (5 pts) *
    2. Display a friendly message e.g. Good Morning!! (2 pts)
    3. Explain your program to the user e.g. This java program can add, subtract, multiply,
    divide and calculate remainder of any two integer numbers entered by you. Let’s get
    started…. (5 pts)
    4. Prompt the user- Please enter your first name, store the value entered by user in a
    string variable name. Use input.next() instead of input.nextLine(). (8 pts)
    5. Prompt the user- name, enter first integer number , store the value entered by user in
    an integer variable num1.(5 pts)
    6. Prompt the user- name, enter second integer number , store the value entered by user in
    an integer variable num2.(5 pts)
    7. Display the numbers entered by the user as: name has entered the numbers num1and
    num2.(5 pts)
    8. Calculate sum, product, difference, quotients and modulus of the two numbers. ( 30 pts)
    9. Display sum, product, difference, quotients and modulus of the two numbers. ( 10 pts)
    10. Terminate your program with a friendly message like- Thanks for using my program,
    have a nice day!!(2 pts)

    Nice try. You have not demonstrated that you've at least TRIED to do something. No one is going to do your homework for you. Your "urgency" is yours alone.

  • SOCKET PROGRAMMING  HELP NEEDED!!!!

    hi,
    I got an idea of establishing socket connection with all clients from SERVER through the windows command
    called (arp -a). when we type the stated command on dosprompt in server, it gives the list of current system's
    ipaddress.....switched on. SO i can establish socket connections in a for loop where i can take the following ipaddress from output listed from command.
    i've written the code to call the command in JAVA.
    i write the dosprompt output in a file named list1.txt
    import java.util.*;
    import java.io.*;
    import java.io.File;
    public class RunCommand
    public static String[] runCommand(String cmd) throws IOException
    ArrayList list = new ArrayList();
    Process proc = Runtime.getRuntime().exec(cmd);
    InputStream istr = proc.getInputStream();
    BufferedReader br = new BufferedReader(new InputStreamReader(istr));
    String str;
    while ((str = br.readLine()) != null)
    list.add(str);
    try
    proc.waitFor();
    }catch (InterruptedException e)
    System.err.println("process was interrupted");
    // check its exit value
    if (proc.exitValue() != 0)
    System.err.println("exit value was non-zero");
    // close stream
    br.close();
    // return list of strings to caller
    return (String[])list.toArray(new String[0]);
    public static void main(String[] args) throws Exception
    try
    FileWriter f1=new FileWriter("list1.txt");
    String[] s = runCommand("arp -a");
    for (int i = 0; i< s.length; i++)
    f1.write(s);
    System.out.println(s[i]);
    f1.close();
    }catch (Exception ex) { System.out.println(ex);}
    SAMPLE OUTPUT:
    Interface: 172.16.3.1 on Interface 0x1000003
    Internet Address Physical Address Type
    172.16.3.4 00-00-e2-13-a9-e8 dynamic
    172.16.3.6 00-00-e2-13-aa-0f dynamic
    172.16.3.10 00-00-e2-13-ab-bb dynamic
    172.16.3.12 00-00-e2-13-ab-93 dynamic
    172.16.3.16 00-00-e2-13-37-b8 dynamic
    172.16.3.17 00-00-e2-13-37-19 dynamic
    172.16.3.18 00-00-e2-13-37-1d dynamic
    172.16.3.19 00-00-e2-13-38-98 dynamic
    172.16.3.22 00-00-e2-13-37-54 dynamic
    172.16.3.23 00-00-e2-13-39-02 dynamic
    172.16.3.24 00-00-e2-13-39-0f dynamic
    172.16.3.26 00-00-e2-13-37-a5 dynamic
    172.16.3.27 00-00-e2-13-37-0b dynamic
    172.16.3.28 00-00-e2-13-37-12 dynamic
    172.16.3.29 00-00-e2-13-39-15 dynamic
    172.16.3.30 00-00-e2-13-38-af dynamic
    172.16.3.31 00-00-e2-13-37-fe dynamic
    172.16.3.32 00-00-e2-13-38-ff dynamic
    172.16.3.34 00-00-e2-13-ab-c8 dynamic
    172.16.3.37 00-00-e2-13-ab-67 dynamic
    172.16.3.42 00-00-e2-13-ab-19 dynamic
    PLS HELP ME OUT IN GETTING ONLY THE IPADDRESS IN FOR LOOP IN SERVER SOCKET PROGRAM TO INVOKE ALL CLIENT'S PROGRAM IN NETWORK.
    PLS HELP ME!!!!!!!
    ATTACH THE CODE!!!!!!!!!!!!

    Connecting to a client presumes that the client is waiting for a connection.
    If that is the case I would suggest looking a java.net.Socket.

  • Install program help needed

    I am trying to install a software program on my destop computer, I am the administrator, running 7 Home Premium, 64 bit, I downloaded the program but when I try to install "Installer failed to initialize".  I turned off the antivirus program, that did not help.  I contacted Adobe for help, I did what they said, turn off antivirus, redownload,tried to install and again "Installer failed to initialize".  Any ideas as to what I can do?

    When requesting help you should always include the make/model (i.e. p6-xxxx) of the computer and/or monitor. This information is necessary for us to review the specifications of them.
    What is the program?  I presume that it is an Adobe product.
    Signature:
    HP TouchPad - 1.2 GHz; 1 GB memory; 32 GB storage; WebOS/CyanogenMod 11(Kit Kat)
    HP 10 Plus; Android-Kit Kat; 1.0 GHz Allwinner A31 ARM Cortex A7 Quad Core Processor ; 2GB RAM Memory Long: 2 GB DDR3L SDRAM (1600MHz); 16GB disable eMMC 16GB v4.51
    HP Omen; i7-4710QH; 8 GB memory; 256 GB San Disk SSD; Win 8.1
    HP Photosmart 7520 AIO
    ++++++++++++++++++
    **Click the Thumbs Up+ to say 'Thanks' and the 'Accept as Solution' if I have solved your problem.**
    Intelligence is God given; Wisdom is the sum of our mistakes!
    I am not an HP employee.

  • Programing help needed  urgently

    Please help with my home work I'm really stuck
    Read in an integer from the keyboard, then check to see whether it is :
    Positive or not
    Even or odd
    A multiple of 7 or not
    The number must be displayed together with each of the tests.
    I don't know how to check for a multiple of seven that were I had a problem.
    Here is the program that I have written so far. It is in java.
    import java.util.Scanner;
    public class hwork11
    public static void main (String[]args)
    Scanner input=new Scanner (System.in);
    System.out.println("please enter a number");
    int num=input.nextInt(System.in);
    if(num>0)
    System.out.println(num+" is negative"):
    else
    System.out.println(num+" is positive");
    if( num%2 == 0)
    System.out.println(num+" even number");
    else
    System.out.println(num+" odd number");
    }

    Vee190 wrote:Please help with my home work I'm really stuck
    Read in an integer from the keyboard, then check to see whether it is :
    Positive or not
    Even or odd
    A multiple of 7 or not
    The number must be displayed together with each of the tests.
    I don't know how to check for a multiple of seven that were I had a problem.
    Here is the program that I have written so far. *{color:#0000ff}({color}* It is in java. *{color:#0000ff}r u kiddin me )*
    *{color}*
    import java.util.Scanner;
    public class hwork11
    public static void main (String[]args)
    Scanner input=new Scanner (System.in);
    System.out.println("please enter a number");
    int num=input.nextInt(System.in);
    if(num>0) *{color:#0000ff}( I think that numbers >0 are +. Whuddya think?){color}*
    System.out.println(num+" is negative"):
    else
    System.out.println(num+" is positive");
    if( num%2 == 0) *{color:#0000ff}If num is 4, do know why this statement is true? (num % 2 == 0)*
    **The key to answering your question about whether or not a number is a multiple of 7 is understanding the use of the % operator. Look it up, and figure it out. You will learn programming languages much faster if you understand what it is you are typing, rather than just trying to make a program by copying lines of code out of the book.*{color}*
    System.out.println(num+" even number");
    else
    System.out.println(num+" odd number");

  • Program help needed?

    1. class A555{
    2.     public static void main(String []args){
    3.          Boolean b1 = new Boolean(true);
    4. Boolean b2 = new Boolean(true);
    5. System.out.println( false +" " );
    6.     }
    7. }
    Regarding the above question, at line 5 if i use a boolean literal the program doesn't give any error but whenever i am using b1==b2 *(the two Boolean objects declared,initialized at 3 and 4)* in place of boolean literal, i am getting a compiler compiler error: incomparable types: java.lang.Boolean and java.lang.String . Kindly tell me what could be the reason?

    If you do:
    System.out.println(b1==b2 + " ");
    The compiler will try to make: b1 == (b2 + " ")
    so he is trying to add a string " " to the b2
    if you make: System.out.println((b1==b2) + " "); that should work
    this is a problem of precedence with the operators
    Hope this help!
    Alex

  • Find and Replace text and change font help needed.

    I am completely new to Scripting and I'm sure this is quite simple but I do not know where to start.
    I have a FM template that is populated with "raw" text from a database.
    Within the text are several characters (+, @, *, $, # and %).
    I need to replace these characters with symbols from a different font e.g.:
    Each instance of:
    "+" to be replaced with Wingdings 2 font - Lowercase t
    "@" to be replaced with Wingdings 2 font - Lowercase u
    "*"  to be replaced with Wingdings font - Uppercase E   etc.
    I would like to automate the process and believe a script would enable me to do this.
    I have tried looking on the forum, but can not find anything suitable to help me (or I'm looking in the wrong place).
    Any help would be greatly appreciated.
    Cheers
    Kev

    not really
    important is the Illustrator Text Object-model, which is not very easy to understand.
    And the Core JS String and regExp Objekts.
    Have a look at this:
    http://www.ogebab.de/home/skripte/text/replace
    The dialog is poor (because of compatibility) and it works simply on TextFrames.contents, i don't know if this is good i all cases.
    But i use it not very often so i don't want to rewrite it.
    Maybe it is a starting-point for you.
    But maybe it is more then you need.
    try this:
    //select a text
    var text = app.activeDocument.selection[0];
    var string = text.contents;
    string = string.replace(/ /g,"  ");
    text.contents= string;
    / /g is a regular expression
    .replace() is a method of the String Object
    both explained at
    https://developer.mozilla.org/en/JavaScript/Reference

  • Some programming help needed

    I'm trying to make an alarm clock... I've done all the code but I don't know how to play sounds... I've seen that there is some sort of class for sounds with applets, but I didn't make an applet. It's just normal AWT... can anybody help me out? .....also, is there a more efficient way of 'updating' the clock-label? I used a while loop, but I don't think it's the way it's supposed to be done.
    thanks

    I am not sure what you mean by using a while loop to update the clock-label. I would have used a Timer class to change the time at the given intervals (say every second).

  • Game Programming help needed!

    Hi,
    I'm new to these forums just as i am fairly new to Flash Pro
    8, anyway i was mid way through creating my first flash game when i
    encountered this error message...
    **Error** Scene=Scene 2, layer=Layer 2, frame=25:Line 2: ')'
    or ',' expected
    gotoAndPlay('scene 2',frame 1);
    Total ActionScript Errors: 1 Reported Errors: 1
    it asks me to put an ')' or ',' in to the code but i just
    cant work out where it wans me to put it. Please Help!!!!!
    Thank You

    The parameters are wrong.
    The parameters should ne a scene name and a frame number or
    frame label on that scene.
    like . gotoAndPlay("myScene", 10);

  • Socket Based Server/Client Program Help Needed

    Alright,
    I am making a Client/Server program.
    The idea is that, when I run the 'Server' part, it sits and listens for a connection from the Client.
    The Client writes a string to the socket, then the server, interprets the command.
    This is what I have so far.
    The Server:
    public static void main(String[] args) {
             String clientLine = null;
              Socket channel = new Socket();
              try {
                   mainWin window = new mainWin();
                   window.open();
              } catch (Exception e) {
                   e.printStackTrace();
             try{
                   ServerSocket server = new ServerSocket(8313);
                  BufferedReader reader = new BufferedReader(new InputStreamReader(channel.getInputStream()));
                 channel = server.accept();
                 clientLine = reader.readLine();
                 doCommand(clientLine);
                 reader.close();
                 channel.close();
                 server.close();
             catch(IOException ioe){
                  System.out.println("I/O Exception occurred while using the server");
         }The Client:
    public void sendCommand(String command){
              PrintStream socketWriter  = null;
              try{
                    Socket client = new Socket("127.0.0.1", 8313);
                    socketWriter = new PrintStream(client.getOutputStream());
                    socketWriter.println(command);
                    socketWriter.close();
                    client.close();
              }catch(UnknownHostException uhe){
              }catch(IOException ioe){
         }When I press the command button, it lags for a second, then does nothing.
    Does anyone see the problem?

    public static void main(String[] args) {
             String clientLine = null;
              Socket channel = new Socket(); //<-- This is connecting to where? nowhere, so initiate it to null instead.
              try {
                   mainWin window = new mainWin();
                   window.open();
              } catch (Exception e) {
                   e.printStackTrace();
             try{
                   ServerSocket server = new ServerSocket(8313);
                  BufferedReader reader = new BufferedReader(new InputStreamReader(channel.getInputStream())); //<-- Getting an input stream from nowhere?
                 channel = server.accept(); //<-- Perhaps you want to do this before you try to get the input stream from it?
                 clientLine = reader.readLine();
                 doCommand(clientLine);
                 reader.close();
                 channel.close();
                 server.close();
             catch(IOException ioe){
                  System.out.println("I/O Exception occurred while using the server");
         }

  • New to Java Wireless Programming - Help needed!

    I'm currently finishing my 4 java programmign class in university, and i'm not looking to expand my knowledge in the this language. I would like to learn the how to code for wireless devices. I've already downloaded the Java Wireless Toolkit, but I would really appreciate some direction on what I should read to know where to start with this. Any info that anyone may have is greatly appreciated!
    Thanks
    Al

    Googling J2ME tutorials or MIDP tutorials will give you plenty to read.
    but here's a start:
    http://www.developer.com/java/j2me/article.php/10934_1561591_1
    http://developers.sun.com/techtopics/mobility/midp/samples/index.html#getstart

  • HELP NEEDED PLEASE

    Hi everyone
    Programming help needed here. Any advice would be greatly appreciated!!!
    I have been assigned some work for a program called Processing 1.0 availale at http://processing.org/download
    I was give the 9 individual programs I needed to make however they were converted to Java files from .pde files. The program is based on Java but only runs .pde files and NOTHING else!
    I decompiled the files and got the source code, but it is a slight variation of the original someone made in processing, and needs some tidying to get it to run.
    I think the programs are very simple for a programmer, although I AM NOT.
    CODE is BELOW
    // Decompiled by DJ v3.10.10.93 Copyright 2007 Atanas Neshkov Date: 02/05/2009 13:15:00
    // Home Page: http://members.fortunecity.com/neshkov/dj.html http://www.neshkov.com/dj.html - Check often for new version!
    // Decompiler options: packimports(3)
    // Source File Name: Assign2_1.java
    import processing.core.PApplet;
    public class Assign2_1 extends PApplet
    public Assign2_1()
    SquareSide = 20;
    Rank = Nums.length;
    Side = SquareSide * Rank;
    Green = color(0, 255, 0);
    Yellow = color(255, 255, 0);
    BG = Yellow;
    public void setup()
    size(Side, Side);
    background(BG);
    fill(Green);
    for(int i = 0; i < Rank; i++)
    rect(i * SquareSide, 0.0F, SquareSide, SquareSide * Nums);
    public static void main(String args[])
    PApplet.main(new String[] {
    "--bgcolor=#ece9d8", "Assign2_1"
    int Nums[] = {
    6, 14, 8, 9, 2, 3, 4, 2, 8, 3,
    9, 2, 0, 5
    int SquareSide;
    int Rank;
    int Side;
    int Green;
    int Yellow;
    int BG;
    Edited by: chevy1 on May 2, 2009 7:32 AM

    HELP NEEDED PLEASEShouting is a good way ensure you don't get help. Also you should give a meaningful subject.
    Any advice would be greatly appreciated!!!I suggest you ask a question after providing enough information to be able to answer it.
    Also use CODE tags when posting code as it make the code more readable.
    We are more likely to help people who are trying to learn Java rather than someone who might be looking for an easy way out of doing an assignment.

  • Help needed regarding change of system CLASSPATH

    Hi All,
    I need to change the system CLASSPATH using my java programe. I tried the following code but its not working though it returns the correct CLASSPATH, but unable to do the modification. All I need is to append a new jar file in the existing CLASSPATH..
    code]
    try{
              sysMap = System.getenv();
              }catch(Exception se1){
                        System.out.println("Exception in finding Environment properties");
              Set Keys = sysMap.keySet();
              Iterator It = Keys.iterator();
              while(It.hasNext()){
                   String strNow =(String) It.next();
                   if(strNow.contains("CLASSPATH")){
                        System.setProperty("CLASSPATH", ".;C:\\Calypso\\Software\\\\Release\\jars\\calypso.jar;C:\\Calypso\\Software\\Release\\build;C:\\Calypso\\Software\\Release\\build\\calypsofx;C:\\Calypso\\Software\\Release\\resources;C:\\Calypso\\Software\\Release;C:\\Calypso\\Software\\Release\\jars\\jconn2.jar;C:\\Calypso\\Software\\Release\\jars\\jaxb-1.0.4\\;C:\\Calypso\\Software\\Release\\jars\\javacup.jar;C:\\Calypso\\Software\\Release\\jars\\antlr.jar;C:\\Calypso\\Software\\Release\\jars\\ojdbc14.zip;C:\\Calypso\\Software\\Release\\jars\\web\\servlet.jar;C:\\Calypso\\Software\\Release\\jars\\web\\webserver.jar;C:\\Calypso\\Software\\Release\\jars\\ftp.jar;C:\\Calypso\\Software\\Release\\jars\\itext-1.02b.jar;C:\\Calypso\\Software\\Release\\jars\\Jama-1.0.1.jar;C:\\jdk1.5.0_10\\bin;C:\\Calypso\\Software\\Release\\webfx\\calypsoWebFXServer.jar;C:\\XXX.jar");
                        System.out.println("Classpath changed");
    Any help will be appreciated.

    Hi Kaj ,
    Well I am in a situation where we need to extend a
    existing system and we are providing the client with
    a new jar file for every modification. Now all I need
    is that our programe automatically add (infect
    append) the jar file in the existing system
    CLASSPATH, so that the client need not to add(append)
    the new jar files all the time.
    Can you provide any help??As others have said, use -cp as argument when you start your application. It's quite common that people write a script that adds all jars in a certain directory to the argument to -cp.
    Kaj

  • The credit card info on the account has changed but for some reason there is no option for me to make the changes.  In addition, cloud has stopped working and all other programs that need to be updated cannot be.

    the credit card info on the account has changed but for some reason there is no option for me to make the changes.  In addition, cloud has stopped working and all other programs that need to be updated cannot be??

    Make sure that EVERY DETAIL is the same in every place you enter your information
    -right down to how you spell and punctuate the parts of your name and address
    Change/Verify Account https://forums.adobe.com/thread/1465499 may help
    -Credit card https://helpx.adobe.com/utilities/credit-card.html
    -email address https://forums.adobe.com/thread/1446019
    -http://helpx.adobe.com/x-productkb/global/didn-t-receive-expected-email.html

  • Help needed. I have a 3TB external hard drive partitioned into 1TB's. I used one partition as backup for the main computer hard drive. But now it is greyed out as shown in the disk utility and its name changed, i dont know how that happened, i tried verif

    Help needed. I have a 3TB external hard drive partitioned into 1TB's. I used one partition as backup for the main computer hard drive. But now it is greyed out as shown in the disk utility and its name changed, i dont know how that happened, i tried verifying and repairing it but had no luck. I also tried mounting and unmounting it but still no solution. Anyone to help please?

    Looks bad. I would strongly advise backing up the stuff on the other two partitions as soon as possible in case the rest of the drive goes wrong.
    Beyond that, Disk Utility has limited abilities to repair disks, DiskWarrior uses a different approach and might, emphasis might be more successful. It has certainly done the job for me in the past when Disk Utility could not.
    See http://www.alsoft.com/diskwarrior/

Maybe you are looking for