Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Urgent help
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
edkedned




PostPosted: Sun Oct 10, 2010 9:18 pm   Post subject: Urgent help

I need some help on this project.. i think is easy but i just joined the course and the teacher is still mkaing me do it soo...
Write a program that reads an integer value between 0 and 100 (inclusive), representing the amount of a purchase in cents. Determine the amount of change that would be received from one dollar, and print the number of quarters, dimes, nickels, and pennies that should be returned. Maximize the coins with the highest value. Follow the format below. Assume the user enters the correct value.

Enter the purchase amount [0 ?100]: 36

Your change of 64 cents is given as:
2 Quarters
1 Dimes
0 Nickels
4 Pennies

Hint: You need to use the remainder operator (%) and the division operator (/).

Evaluation:

Your program will be marked based on the following criteria:

Code organization 2
Good programming practices 2
Algorithm Logic 2
Code efficiency 2
Memory efficiency 2
Correctness 10

Total: 20 marks
Sponsor
Sponsor
Sponsor
sponsor
copthesaint




PostPosted: Sun Oct 10, 2010 10:05 pm   Post subject: RE:Urgent help

What you think just because you post this question here you think we will answer it? lmbo Dude compsci isnt a website to help you cheat.
DanShadow




PostPosted: Sun Oct 10, 2010 11:17 pm   Post subject: RE:Urgent help

If your teacher expects you to complete the assignment, that means he has given you the courseware with the required information to do the assignment.

As your teacher said, the two key values are the division and remainder operator.

Edkedned wrote:
Enter the purchase amount [0 ?100]: 36

Your change of 64 cents is given as:
2 Quarters
1 Dimes
0 Nickels
4 Pennies


Step 1: Get user input
Step 2: Verify user input is (a) an integer, and (b) between 0 and 100
Step 3: Your going to want to make a few variables. One for quarters which = 25 (cents), one for dimes which = 10 (cents), one for nickles = 5 (cents), one for pennies = 1 (cent).
Step 4: Sequentially divide the integer entered by the user by your "coin" variables from highest value to lowest, keeping track of the remainder.

If the user entered 64 (the change being 36 cents), you would do (36/ QuarterVariable), which equals 1 with a remainder of 11.
So you have 1 quarter change.

Then you divide the remainder by the next coin variable. (11 / DimeVariable) equals 1, with a remainder of 1.
So you have 1 dime change.

Next divide the remainder by the next lowest coin variable (1 / NickleVariable) equals 0, with a remainder of 1.
So you have 0 nickles change.

Lastly, your penny. (1 / PennyVariable) equals 1, with a remainder of 0.
So you have 1 penny change.

In the end, with a user input of 64, and a change value of 36, you end up with:
1 Quarter Change
1 Dime Change
0 Nickles Change
1 Penny Change

This is the logic behind your assignment.
Now take a look at the courseware your teacher has provided for you, and look for...
- how to define a class, and "void main" method
- how to define and set variables
- how to print text
- how to get user input, and store in a variable
- how to perform "if" statements

Once you know how to do these things, you implement the pre-mentioned logic structure, and the assignment becomes very easy.

But as copthesaint said, at CompSci we dont give out answers and do assignments for people. We do, however, help people understand HOW to program, offer tips and suggestions, etc.

Hope this helps, and good luck with your assignment!
OneOffDriveByPoster




PostPosted: Mon Oct 11, 2010 9:22 am   Post subject: Re: RE:Urgent help

DanShadow @ Sun Oct 10, 2010 11:17 pm wrote:
Step 2: Verify user input is (a) an integer, and (b) between 0 and 100
The assignment said to assume correct input. The teacher should clarify whether doing this step counts for or against the student under:
Quote:
Good programming practices 2
Code efficiency 2
Especially since the code does not have to be very efficient at all for such a small problem.

DanShadow @ Sun Oct 10, 2010 11:17 pm wrote:
Step 3: Your going to want to make a few variables. One for quarters which = 25 (cents), one for dimes which = 10 (cents), one for nickles = 5 (cents), one for pennies = 1 (cent).
Variables will likely take up memory. If you are going to have these, then you should also parameterize on the number of coins and the names of the coins. Again, the teacher should clarify if having these is good programming practice and the trade offs.

DanShadow @ Sun Oct 10, 2010 11:17 pm wrote:
- how to perform "if" statements
Assuming correct input, this assignment does not require an if-statement.

DanShadow @ Sun Oct 10, 2010 11:17 pm wrote:
Once you know how to do these things, you implement the pre-mentioned logic structure, and the assignment becomes very easy.

But as copthesaint said, at CompSci we dont give out answers and do assignments for people. We do, however, help people understand HOW to program, offer tips and suggestions, etc.
A copy of this logic structure as a comment in English could get the OP 10% on their assignment. I encourage the OP to produce this part on their own for future requests or at least show an attempt to do so.
edkedned




PostPosted: Mon Oct 11, 2010 2:14 pm   Post subject: RE:Urgent help

I wasnt expecting anyone to do it..just wanted some clarification...forgot to mention it srry..and thanks for ur help ...so shud i use the variables or not
OneOffDriveByPoster




PostPosted: Mon Oct 11, 2010 3:57 pm   Post subject: Re: RE:Urgent help

edkedned @ Mon Oct 11, 2010 2:14 pm wrote:
...so shud i use the variables or not
Ask your teacher what he or she thinks about the option, or refer to course material for guidance. In either case, you may wish to justify your decision in comments near the first instance of the hard-coded values or the variable declarations (whichever is applicable).
DanShadow




PostPosted: Mon Oct 11, 2010 4:46 pm   Post subject: RE:Urgent help

@OneOffDriveByPoster

There is no reason to criticize how I offer help, and whether or not I was awake enough at 11 at night to catch the specifics of his request.
It's a free forum, and my "free" advice does not need to conform to a request, it can be taken as I write it or not at all Wink.

Additionally, some (and by that I mean quite a few) teachers may actually give better marks for an assignment that uses structure beyond or at the level of the courseware that is being taught.

@edkedned

In terms of variables, memory isnt an issue at all for such a small program -_-, and variables can help better define what a program section is doing - but so can comments.

[ex1]
//Check if quarter value is in input
if (input >= 25) {
System.out.println("quarter!");
}

[ex2]
int QuarterValue = 25;
if (input >= QuarterValue) {
System.out.println("quarter!");
}

Yes, it takes up a slight amount of memory, but in my opinion, it makes code look more clear, and rather than continuously commenting every time you might use the same value, you could just use the (self-explanatory) variable name rather than the value.

edkedned wrote:
...so shud i use the variables or not

You dont need to, but your teacher may like to see that you know how to use the Java syntax properly, and it may get you more marks.
I would check your courseware first, and see how your teacher uses examples.
If he/she uses variables in his example code, I would use it too - it shows your paying attention to what he/she is teaching, and (yet again) may get you more marks.

Assuming your in high-school, most teachers are not worried about "efficient memory usage", they're worried about students understanding what is being taught, and putting it to use in their assignments.
copthesaint




PostPosted: Mon Oct 11, 2010 9:19 pm   Post subject: Re: Urgent help

uhh why use variables when you can just use math...

Java:
public static int getNOC (int total, int num){
return  ((total-(total%num))/ num);
}


Very simple... He also even hints to use these... geez
Sponsor
Sponsor
Sponsor
sponsor
DanShadow




PostPosted: Tue Oct 12, 2010 2:38 am   Post subject: RE:Urgent help

Well, its obvious that the two given mathematical operators are to be used, but its possible the teacher hasnt explained functions yet.
But really, there are MANY different ways to code just about any program - most work fine, it just depends on the requirements of the person asking you to write the program.
2goto1




PostPosted: Tue Oct 12, 2010 5:00 pm   Post subject: Re: RE:Urgent help

DanShadow @ Mon Oct 11, 2010 4:46 pm wrote:
@OneOffDriveByPoster
Yes, it takes up a slight amount of memory, but in my opinion, it makes code look more clear, and rather than continuously commenting every time you might use the same value, you could just use the (self-explanatory) variable name rather than the value.

Yes, let the code do the talking! I completely agree with that philosophy Dan. Well named classes, variables, and methods can significantly help to make code understandable and maintainable - particularly important when developing a team project, or developing larger corporate applications.

Compilers detect syntax issues, the J2SE runtime is happy to let you know when a checked or unchecked exception occurs, bu unfortunately nothing lets you know when a comment is "broken" Smile
OneOffDriveByPoster




PostPosted: Wed Oct 13, 2010 11:57 am   Post subject: Re: RE:Urgent help

DanShadow @ Mon Oct 11, 2010 4:46 pm wrote:
@OneOffDriveByPoster
Yes, it takes up a slight amount of memory, but in my opinion, it makes code look more clear, and rather than continuously commenting every time you might use the same value, you could just use the (self-explanatory) variable name rather than the value.
In this particular case, I believe that using a variable is unnecessarily verbose. The uses of the value can be placed so close together and to the output code, that even a comment may not be necessary. Now, my original response did not completely dismiss the use of variables. It suggested that if you were going to have variables, then you might as well have ones for the names of the coins and the number of kinds as well. You may use an array, for example, and a loop over the array.

A potential problem with "commenting in code" is that the code may not become more clear, only more complex, and your "comments" can affect the correctness of your program. By adding names, even ones for variables marked "final", you may hit snags with potential name conflicts and name hiding issues.
2goto1




PostPosted: Thu Oct 14, 2010 7:09 am   Post subject: RE:Urgent help

Yes, do the minimum that needs to be done while balancing readability, and everything in moderation.
DanShadow




PostPosted: Thu Oct 14, 2010 9:18 am   Post subject: RE:Urgent help

As I said, the is a high school level project -_-.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: