Wiihacks - Nintendo Wii Hacks Community
Left Container Right Container
 



Go Back   Wiihacks - Nintendo Wii Hacks Community > Wii Discussion > Lounge


Reply
 
LinkBack Thread Tools Display Modes
Old 10-10-2009, 04:20 PM   #1 (permalink)
Junior Member
Last Achievements
 
Join Date: Jul 2009
Posts: 9
Downloads: 0
Uploads: 0
Thanks: 0
Thanked 0 Times in 0 Posts
Points: 745, Level: 6
Points: 745, Level: 6 Points: 745, Level: 6 Points: 745, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Wii Friend Code: None Yet
Post Java Progammers, i need help

I need help with my code. Its basically supposed to be like vending machine. You input the value of any item from 25 cents upto 1 dollar. Then the program will tell you how much change you will recieve the coins you will recieve (least amount of coins).
I made this program, but is there any way to make it shorter/better?

import java.io.*;
public class vending {
public static void main(String[] args)throws IOException
{
double dollar = 100;
double price;
int change;
int quarter, dime, nickel;
String quar, dimes, nickels;
BufferedReader in;

in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please enter price of item (in cents): ");

price = Double.parseDouble(in.readLine());
if (price < 25)
System.out.print("Sorry, we don't have any items for that price.");
else {
System.out.println("n" + "You bought and item for " + (int)price + " cents.n");
change = (int)(dollar - price);
System.out.println("After giving me $1, your change will be " + change + " cents.");
System.out.println("It will be given to you as:n");

quarter = change / 25;
dime = (change - (quarter * 25)) / 10;
nickel = (change - (quarter * 25) - (dime * 10)) / 5;

if (quarter == 1)
quar = "quarter";
else
quar = "quarters";
if (dime == 1)
dimes = "dime";
else
dimes = "dimes";
if (nickel == 1)
nickels = "nickel";
else
nickels = "nickels";

if (quarter == 0)
if (dime == 0)
if (nickel == 0)
System.out.println("no coins.");
else
System.out.println(nickel + " " + nickels);
else
if (nickel == 0)
System.out.println(dime + " " + dimes);
else
System.out.println(dime + " " + dimes + "\n\n" + nickel + " " + nickels);
else
if (dime == 0)
if (nickel == 0)
System.out.println(quarter + " " + quar);
else
System.out.println(quarter + " " + quar + "\n\n" + nickel + " " + nickels);
else
if (nickel == 0)
System.out.println(quarter + " " + quar + "\n\n" + dime + " " + dimes);
else
System.out.println(quarter + " " + quar + "\n\n" + dime + " " + dimes + "\n\n" + nickel + " " + nickels);
}
}
}



i apologize if its hard to read

Last edited by babbalabba; 10-11-2009 at 05:49 AM. Reason: Rewrote
babbalabba is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-10-2009, 04:38 PM   #2 (permalink)
~WiiHacks Staff~
~*Senior Moderator~"

*We are always busy..
*ONLY Forum Donators...
can PM Staff at this time
if u pm me for help...
you better be a Forum donator or a hot girl!!
Last Achievements
Award-Showcase
 
messie's Avatar
 
Join Date: Jun 2009
Posts: 3,826
Downloads: 8
Uploads: 0
Thanks: 34
Thanked 2,236 Times in 727 Posts
Points: 17,216, Level: 39
Points: 17,216, Level: 39 Points: 17,216, Level: 39 Points: 17,216, Level: 39
Activity: 99.9%
Activity: 99.9% Activity: 99.9% Activity: 99.9%
Wii Friend Code: None Yet
is this the kind "this is my first java program"?
__________________
Simple rules:
a) Read the guides before posting -> GUIDES, FAQ, ERROR INDEX
b) Provide us with sufficient info when asking a question.
c) Some guy must have invented sentences, commas, fullstops. Let's honor him and use them...
d) We thank the people who have helped us by clicking the button.


"...βλέπεις τον άνθρωπο μικρό που τον πατάν στ'αλήθεια, τα πόδια του τα ίδια..."
messie is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-10-2009, 05:49 PM   #3 (permalink)
Junior Member
Last Achievements
 
Join Date: Jul 2009
Posts: 9
Downloads: 0
Uploads: 0
Thanks: 0
Thanked 0 Times in 0 Posts
Points: 745, Level: 6
Points: 745, Level: 6 Points: 745, Level: 6 Points: 745, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Wii Friend Code: None Yet
Its not my 1st, its like my 3rd. But i actually want to improve this to show my teacher.
babbalabba is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-11-2009, 02:41 AM   #4 (permalink)
~WiiHacks Staff~
~*Senior Moderator~"

*We are always busy..
*ONLY Forum Donators...
can PM Staff at this time
if u pm me for help...
you better be a Forum donator or a hot girl!!
Last Achievements
Award-Showcase
 
messie's Avatar
 
Join Date: Jun 2009
Posts: 3,826
Downloads: 8
Uploads: 0
Thanks: 34
Thanked 2,236 Times in 727 Posts
Points: 17,216, Level: 39
Points: 17,216, Level: 39 Points: 17,216, Level: 39 Points: 17,216, Level: 39
Activity: 99.9%
Activity: 99.9% Activity: 99.9% Activity: 99.9%
Wii Friend Code: None Yet
what more do you want? if its working then np. it is clear, you can understand what it is doing... what more?
__________________
Simple rules:
a) Read the guides before posting -> GUIDES, FAQ, ERROR INDEX
b) Provide us with sufficient info when asking a question.
c) Some guy must have invented sentences, commas, fullstops. Let's honor him and use them...
d) We thank the people who have helped us by clicking the button.


"...βλέπεις τον άνθρωπο μικρό που τον πατάν στ'αλήθεια, τα πόδια του τα ίδια..."
messie is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-11-2009, 05:44 AM   #5 (permalink)
Junior Member
Last Achievements
 
Join Date: Jul 2009
Posts: 9
Downloads: 0
Uploads: 0
Thanks: 0
Thanked 0 Times in 0 Posts
Points: 745, Level: 6
Points: 745, Level: 6 Points: 745, Level: 6 Points: 745, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Wii Friend Code: None Yet
Just want to know if it can be made better
babbalabba is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
code, java, program

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -8. The time now is 02:06 PM.
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.2