I'm spankn' new to java with no previous computer programming experience and I need help with an assignment.

The assignment is to write a Java program to direct a cashier how to make change.

Input guidelines:
1) Number of dollars due
2) Number of cents due
3) Number of dollars received from the customer
4) Number of cents received from the customer

Output guidelines:
1) Print a title for the program
2) Print the total amount due as $dd.cc
3) Print the total amount submitted as $dd.cc
4) Print the total amount of change as $dd.cc
5) Print how many $1, quarters, dimes, nickels and pennies are required for the change
6) Print a farewell

-Use Strings only for input. Do not use Strings to process the results
-Use named constants (final variables) for the money amounts. There should be no “magic numbers in the code.
-There is no error checking in this program. You can assume that the input is valid and the amount of money will exceed or equal the amount due.
-Use only statements like a declaration, assignment, input and output. DON'T use anything else like if-else, loops, etc.

Sorry for my ignorance, but I would seriously appreciate any help or guidance on how to get started. Thanks everyone for your time!

Recommended Answers

All 6 Replies

Atleast show some effort here ... typing a question is no effort ... atleast start writing the program ... you'll certainly be able to start it ... Its not a very hard program.

Show some effort and post again .. you'll certainly be helped.

That's the problem. I'm completely clueless where to start. I mean, I'm just really lost and don't know what all this means. I just scheduled an appointment with my instructor two days from now though any additional help or any suggestions of some good reading material/websites that can help me out would be greatly appreciated.

And for the record, it's embarrassing to post something this simple (to most people) here begging for help. So please, just anything that would get me started in the right direction, I'd really appreciate it.

And would a modulus be something like this?:

To start you'll want to script out the flow of your program. Maybe with a drawing. You have to get a feel for how the block structure will go. For instance:


>ask user for dollar input
- store dollar input as type double
>ask user for cents input
- store cents input as type double

.... etc.

That should give you a pretty good start to how you'll write your code that way you can work through it piece by piece giving yourself goals. When you get something coded or if you get stuck on piece you can post what you have and ask for help.

-=Code Master Flex=-

Hi L. Shelby,
JAVA contains a pre-built class named Math. To use it insert this statement at the top of your program =>
import java.lang.Math.*;

This class is static which means it is class variables and class methods. This class is very useful to caculate simple mathematical problems.

Thank you for the help CodeMasterFlex and Banderson. It really did help me get started so I didn't go in cold turkey when I went to visit my instructor. So again, I really appreciate it everyone!

Also the other reason why I'm posting here is I need some help, again. So after slaving away for a week, day and night (ignoring my other classes), this is what I have:

import java.io.*;

    public class MakeChange

    static BufferedReader keyboard = new BufferedReader
                (new InputStreamReader(System.in));

    public static void main (String [] args) throws IOException  

    System.out.println ("Program to calculate change");
    System.out.println ();

    int number;
    String line;

    int dollarsDue;
    int centsDue;
    int customerDollars;
    int customerCents;

    System.out.println ("Enter number of dollars due:");
    line = keyboard.readLine();
    dollarsDue = Integer.parseInt(line);

    System.out.print ("Enter number of cents due:");
    line = keyboard.readLine();
    centsDue = Integer.parseInt(line);

    System.out.print ("Enter number of dollars from customer:");
    line = keyboard.readLine();
    customerDollars = Integer.parseInt(line);

    System.out.print ("Enter the number of cents from the customer:");
    line = keyboard.readLine();
    customerCents = Integer.parseInt(line); 

It seemed to work on the compiler, but if anyone has any suggestions to improve it in terms of spacing or whatever, feel free to jump in and post any comments or suggestions.

But this is where I'm at a dead end again. Now I need some help coding the calculations and/or output (?), well the next part. I'm supposed to take the input of dollars due and add it to the number of cents due to get the [b]amount due[/b]. Then the same with number of dollars and cents from the customer to get the [b]amount submitted[/b]. Then when that's taken care of, subtract the amount submitted with the amount due to get the [b]final amount of change[/b]. And in the process convert the dollars into pennies. So say for example:

Enter number of dollars due: 3
Enter number of cents due: 13
Enter number of dollars from the customer: 5
Enter number of cents from the customer: 0

(input shown after colon)

So then the output's supposed to look something like this:

$3.13 is due  
$5.00 is submitted
The change is $1.87

...which is the part I need help coding. And the weird thing is I'm not supposed to use type double here (and I see three, count 'em, three decimal points), which makes it even more confusing.

Also another question, how and when do you use final variables? Do I have to use it for this part of the program? My instructor told me that I'd be needing to use them a lot at some point.

And excuse me if I butchered any terminology, which I'm pretty sure I did; hey I'm still learn'. So if anyone would be kind enough to help me out again (particularly on what I'm asking for help, though any additional feedback is welcome), you'll make a lowly, poor college student happy.

Thanks y'all!


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.