User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 397,791 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,454 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1706 | Replies: 3
Reply
Join Date: Oct 2006
Posts: 9
Reputation: LSPUWILLC is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
LSPUWILLC's Avatar
LSPUWILLC LSPUWILLC is offline Offline
Newbie Poster

Help Vending (Drinking) Machine Java Code

  #1  
Oct 29th, 2006
This year I started learning Java in class and now we are making a Vending Machne code...
I compleated the task, but now I want to add another buton, but I get stuck a a sertain point...

Here is my original code with the second button added:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ThirstQuencher extends JFrame
implements ActionListener {

private JButton button1;
private JButton button2;

public static void main (String [] args) {
ThirstQuencher frame = new ThirstQuencher () ;
frame.setSize (400, 300) ;
frame.createGUI () ;
frame.show () ;
}

private void createGUI() {
setDefaultCloseOperation (EXIT_ON_CLOSE) ;
Container window = getContentPane () ;
window.setLayout (new FlowLayout () ) ;

//First button
button1 = new JButton ("Coca-Cola 1,15 Û") ;
window.add (button1) ;
button1.addActionListener (this) ;

//Second button
button2 = new JButton ("Water 0,85 Û") ;
window.add (button2) ;
button2.addActionListener (this) ;
}

public void actionPerformed (ActionEvent event) {
int cents;
int euros;
int change;
int changeCents;
int changeEuros;

//Makes windows that ask for money
String centsString;
String eurosString;
eurosString = JOptionPane.showInputDialog ("Enter Û (Euros)") ;
centsString = JOptionPane.showInputDialog ("Enter c (Cents)") ;
cents = Integer.parseInt (centsString);
euros = Integer.parseInt (eurosString) * 100;


//Calculate the change

change = (cents + euros) - 115;


//Splits up the change
changeCents = change % 100;
changeEuros = change / 100;
//Tells the change
JOptionPane.showMessageDialog (null,
"Change breakes down into:" +
" Euros: " + changeEuros +
" Cents: " + changeCents);
//Tells how the cents come out
int CentsDecimale;
int CentsJednine;
CentsDecimale = changeCents / 10;
CentsJednine = changeCents - (CentsDecimale * 10);
JOptionPane.showMessageDialog (null,
"Change in Cents coming out:" +
" " +
CentsDecimale +
" *10c" +
" " +
CentsJednine +
" *1c");
//Tells how the euros come out
int NEuros;
NEuros = changeEuros / 1;
JOptionPane.showMessageDialog (null,
"Change in Euros comming out: " +
NEuros +
" *1Û");

}
}



The only part I need to figure out is how to make the program calculate -85 if the person selected water instead of coke which is -115!
That part ih colored in blue!
PLS enyone help me
THANX.
B GRATEFUL,
LSP
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2006
Posts: 9
Reputation: LSPUWILLC is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
LSPUWILLC's Avatar
LSPUWILLC LSPUWILLC is offline Offline
Newbie Poster

Re: Vending (Drinking) Machine Java Code

  #2  
Oct 29th, 2006
Coke is button 1 and water is button 2...
B GRATEFUL,
LSP
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,183
Reputation: peter_budo has a spectacular aura about peter_budo has a spectacular aura about peter_budo has a spectacular aura about 
Rep Power: 10
Solved Threads: 265
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Vending (Drinking) Machine Java Code

  #3  
Oct 29th, 2006
nice job you nearly there here is your missing peace :cheesy:

//Calculate the change
String command = event.getActionCommand();
if(command == "Coca-Cola 1,15 Û")
{
change = (cents + euros) - 115;
}
else
{
change = (cents + euros) - 85;
}

KEEP UP YOUR WORK :p
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Join Date: Oct 2006
Posts: 9
Reputation: LSPUWILLC is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
LSPUWILLC's Avatar
LSPUWILLC LSPUWILLC is offline Offline
Newbie Poster

Re: Vending (Drinking) Machine Java Code

  #4  
Oct 30th, 2006
IT WORKS!!!
Thank you very much!
B GRATEFUL,
LSP
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Java Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 5:36 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC