I Can't Find The Problem!! pls help (ONLY IF U HAVE SOME FREE TIME)
I'd like to post some code because I cant see the problem, maybe somebody else will see it. Just take a little look if u see some detail let me know pls.
I have a class word, wich is actualy a representation of a word in some text
public class Word {
int timesInText; //how many times this word is in the text
//A vector with the lines were the word appears
public Vector<Integer> lines = new Vector<Integer>();
public String word; //The word we are representing... Very creative Isn't it?
//The lines were the word appear in a string in this format : , line, line, line...
StringBuffer Stringlines = new StringBuffer(":");
public Palabra(String word) {
this.word = word;
timesInText=1;
public void wordFinded(int linea) {
lines.add(linea);
Stringlines.append(", " + linea);
timesInText++;
public String toString() {
String var = word + ": " + Stringlines.toString();
return var;
}//End of the word class
I have a class main, wich is a window with the logic of the program, notice that
I'll provide only the necesary thing to understand my problem in order to make
my post shorter. The words I read can't have duplicates but I must say in wich
lines the duplicates are.
public class main{
Vector<Word> words = new Vector<Word>(); //A vector for all the words in text
JText area = new JTextArea(); //The JTextArea of my window
public void getWords(){
JFrame wordsInText = new JFrame("Word Search:");
JTextArea wordsArea = new JTextArea("\tResult :");
wordsInText.getContentPane().add(new JScrollPane(wordsArea));
boolean alreadySeen;
String text = area.getText();
String line;
String word;
Word wordBeingRead;
int lines = 0;
BufferedReader br = new BufferedReader(new StringReader(text)); //To read complete text
while ((line = br.readLine()) != null)
lines += 1;
StringTokenizer st = new StringTokenizer(line, " "); //But line by line
while (st.hasMoreTokens())
alreadySeen = false;
word = st.nextToken();
wordBeingRead = new Word(word);
Iterator iter = words.iterator();
if(!iter.hasNext()) //The first word! save it
words.add(wordBeingRead);
else //Yeah... not the first word... Check it...
Iterator iterAux = palabras.iterator();
while(iterAux.hasNext()) //Check if it's already defined
Word p = (Word) iterAux.next();
if(wordBeingRead.word.equals(p.word)) //It is already defined...
wordBeingRead.wordFinded(lines); //I got one on line (lines)
alreadySeen=true; //Yes! It's already seen
if(alreadySeen==false) //If it's already seen wont get in here
words.add(wordBeingRead); //A new word! Let's save it
Iterator iter = palabras.iterator(); //Ok I saved all the words, time to print them
while(iter.hasNext())
wordBeingRead = (Word)iter.next();
wordsArea.append("\n" + WordBeingRead.toString()); //Put them over here
wordsInText.setSize(400, 400);
wordsInText.setLocation(100, 75);
wordsInText.setVisible(true); //Yes! show them
}catch(Exception e){
label.setText(e.getMessage()); //If anything goes wrong
}//End of the class main
Ok, sorry about that.
Post your code between code tags (use the code button when you post a reply).I'm new in the forum and the tags doesnt seem to work with netscape, will use IE next time.
you should not have a main class. You should have a main method inside a class eg:The original name of the class is Ventana, but you can actually name a class main.
Also, your constructor should have the same name as your class eg:The constructor in the word class it's written like that because I translated the code to english so that it could be more simply to understand.
4. If you don't get errors tell us what you expect your code to do and what it IS actually doing.Ok I'll give you a sample input and output:
INPUT:
"I am sorry for not posting correctly
I will make sure this wont happen again
I will be a good user"
OUTPUT I'm getting:
I: :
am: :
sorry: :
for: :
not: :
posting: :
correctly: :
will: :
make: :
sure: :
this: :
wont: :
happen: :
again: :
be: :
a: :
good: :
user: :
OUTPUT I would love to have:
I: 1, 2, 3
am: 1
sorry: 1
for: 1
not: 1
posting: 1
correctly: 1
will: 2, 3
make: 2
sure: 2
this: 2
wont: 2
happen: 2
again: 2
be: 3
a: 3
good: 3
user: 3
I just noticed that I get the double : : Because I do it twice... ^^
Thanks for the recomendations, and I'm sorry, totally my fault, I mean it.
Similar Messages
-
trying to reset my password (which I have forgot) for elements 13 I have the serial no. But I can't find the right website to reset? I have "copy & paste " into the browser.
Go to the main page of adobe.com and sign out if you're already signed in there. Then click Sign In at the upper right of the page. In the next page you will see a Forgot Password link:
-
Where can i find the most popular common effects and title template for free online?
where can i find the most popular common effects and title template for free online?
Hello,
I have a couple of links that I have used:
http://www.solarisinternals.com/wiki/index.php/ZFS_Best_Practices_Guide
http://www.solarisinternals.com/wiki/index.php/ZFS_for_Databases
These are not exactly new, so you may have encountered them already.
List of ZFS blogs follows:
http://www.opensolaris.org/os/community/zfs/blogs/
Again, there does not seem to be huge activity on the blogs featured there.
jason.
http://jarneil.wordpress.com -
I can't play the song in my library bec they can't find the original file which i can play before may be I try to import mp 3 which couple song from mp3 can play but the song that come from original cd or purchase from itune store can't play
iTunes doesn't import it INTO the Library, it keeps it in it's original place and just adds the song into it, try and find them again and re-add them into your library.
-
I am in an internet cafe and my macbook pro can't find the wireless network available at the cafe. I have used this network before. I have restarted my machine several times too. help please
Change your router channel. Sometimes this is all you will have to do.
Power cycling the router. Read the router's user manual or contact their tech support for instructions.
System Preferences/Internet & Network/Network
Unlock the padlock
Locations: Automatic
Highlight Airport
Click the Assist Me button
In the popup window click the Diagnostic button.
System Preferences/Network- Unlock padlock. Highlight Airport. Network Name-select your name. Click on the Advanced button. Airport/Preferred Networks-delete all that is not your network.
Place a check mark next to "Remember networks this computer has joined." Click the OK button and lock the padlock. Restart your computer.
http://support.apple.com/kb/TS1920 Mac OS: How to release and renew a DHCP lease
No internet connection (wireless)
Check to see if an extra entry is present in the DNS Tab for your wireless connection (System Preferences/Network/Airport/Advanced/DNS).
Delete all extra entries that you find.
Place a check mark next to "Remember networks this computer has joined."
Other resources to check into:
http://www.netspotapp.comNetspot
How to diagnose and resolve Wi-Fi slow-downs
Pv6 troubleshooting
Mac OS X 10.6 Help: Solving problems with connecting to the Internet
What Affects Wireless Internet?
Solutions for connecting to the Internet, setting up a small network, and troubleshooting -
IMovies - Export Using Quicktime - can't find the finished file - help please!
Please help. I exported several imovies projects to a designated file on my mac, using Share - Export using Quicktime and then I uploaded them to Youtube.
I did this successfully several times, now when I export a project, it takes about 45 minutes to export it, then I can't find them anymore.
I have read several threads, which suggest looking in the iMovie projects folder and locate your project Right-click to get to "show package contents" and they are not there.
It looks as if it goes through successfully, no errors but this is so annoying as I am wasting hours sharing and then can't find it. Please help anyone.
ThanksHi Gee
I originally spent about 10 hours uploading 3 clips directly from imovies to Youtube to a private channel and they couldn't find any signs of my 3 uploads. So I read threads that said export to Quicktime from imovies and then load them to Youtube that way. I did that for 3 short, 10 minute videos and it worked fine. It changed the thread to .mov and it worked.
Then perhaps I changed something (not sure what) but now when I use Export to Quicktime, it spends 1 hour or so doing the motions and completes but when I go to the allocated folder to retrieve it. It can't be found. I read threads and this seems to be a regular occurrence but I haven't read any replies that has solved this issue.
Hope that's clearer. -
Hello,
I have hp pavilion dv4 lap,in this lap has some hard disk problem,when i am turn on the lap that screen shows this message "The smart hard disk check has detected an imminent failure.To ensure not data loss,please backup the content immediately and run the hard disk test in system diagnostics".
After that i was diagnostics the system but no changes in the lap,,again again lap shows hard disk error(301).
Then i am chosen the enter option to start up the lap it take long time for openning the windows,after enter the windows that also shows about the hard disk error in within few minitues,
What can i do?
This lap bought at 12-oct-2012 from malasiya,now im in tamil nadu,how to solve the problem please help me.Hello srhk. Thank you for posting on the HP Forums.
I understand the hard disk is experiencing issues. Error 301 indicates the hard disk possesses a hardware defect. I would contact HP Phone Support for assistance, or purchase an equivalent hard disk.
If you choose to contact HP, their options will be based on the warranty status of the computer. If you do not have this information, you can locate it at this website: http://h20566.www2.hp.com/portal/site/hpsc/public/wc/home?ac.admitted=1384280905804.876444892.199480...
You can utilize this website to learn how to contact HP appropriately, based on your region: http://www8.hp.com/us/en/contact-hp/ww-contact-us.html
Please let me know if you have any other questions or concerns.
Mario
I worked on behalf of HP. -
Can't find the Collective Search help for Customer in VD02/VD03
Hi
I ave (I hope ) an easy question for you -
I need to extent the Collective search help for Customer in VD02/VD03 with an additional elementary search help, but I can't find the name of the Collective Search Help (F1 -> Technical Information only gives Search help '=')
So, where do I find it ?
Regards
Morten NielsenOK I Found it - Called DEBI
Regards
Morten Nielsen -
My Ipod is disable, How can I fix the problem please help
My I-pod is disable, how can I fix the problem, Please Help
If it is disabled because of the passcode, see this article: iPhone and iPod touch: Wrong passcode results in red disabled screen
If you cannot remember the passcode, you will need to restore your device using the computer with which you last synced it. This allows you to reset your passcode and resync the data from the device (or restore from a backup). If you restore on a different computer that was never synced with the device, you will be able to unlock the device for use and remove the passcode, but your data will not be present. Refer to Updating and restoring iPhone and iPod touch software.
If the issue continues after updating and restoring your device, refer to this document. -
Need help... can't find the problem...
I'm trying to copmli my program.. but I'm getting
some errors...
C:\Umass\CS210\Hw2\SinglyLinkedList.java:301: unreachable statement
return NOT_FOUND;
^
C:\Umass\CS210\Hw2\SinglyLinkedList.java:316: variable p might not have been initialized
return p;
^
import java.util.*;
public class SinglyLinkedList implements List
* creatino of the SllIterator
private class SllIterator implements Iterator
private Node current;
private Node lastVisited = null;
private int expectedModCount = modCount;
public boolean hasNext()
if(expectedModCount != modCount)
throw new ConcurrentModificationException();
return true;
public Object next()
if(!hasNext())
throw new NoSuchElementException();
Object nextItem = current.data;
lastVisited = current;
current = current.next;
return nextItem;
public void remove()
if(expectedModCount != modCount)
throw new ConcurrentModificationException();
if(lastVisited == null)
throw new IllegalStateException();
SinglyLinkedList.this.remove(lastVisited);
lastVisited = null;
expectedModCount++;
// an inner class: This is our node class, a singly linked node!
private class Node
Object data;
Node next;
Node(Object o, Node n)
data = o;
next = n;
Node(Object o)
this(o, null);
Node( )
this(null,null);
private Node head; // the "dummy" head reference
private int size; // the number of items on the list
private int modCount = 0;
public SinglyLinkedList()
head = new Node(); // dummy header node!
public void add(int index, Object o)
Node p = getNode(index);
Node newNode = new Node(o, p);
newNode.next = newNode;
size++;
modCount++;
public boolean add(Object element)
if (element == null) return false;
// Check for dummy head node
if (head.data == null)
head = new Node(element, null);
else
// Traverse the list until we find the end
Node next = head;
while (next.next != null)
next = next.next;
next.next = new Node(element, null);
size++;
return true;
public boolean addAll(Collection c)
return true;
public boolean addAll(int index, Collection c)
return true;
public void clear()
head = new Node("Head", null);
size = 0;
// write a recursive implementation here
public boolean contains(Object o)
return findPos(o) != NOT_FOUND;
public boolean containsAll(Collection c)
return true;
public boolean equals(Object o)
return true;
// write a recursive implementation here
public Object get(int index)
return null;
// NOT implemented: we don't cover hash codes
// and hashing in this course
public int hashCode()
throw new UnsupportedOperationException();
public int indexOf(Object o)
return -1;
public boolean isEmpty()
return (size() == 0);
public Iterator iterator()
return null;
public int lastIndexOf(Object o)
return -1;
// Not implemented: The following two operations are not supported
// since we are using a singly linked list, which does not allow
// us to iterate through the elements back and forth easily
// (going back is the problem)
public ListIterator listIterator()
throw new UnsupportedOperationException();
public ListIterator listIterator(int index)
throw new UnsupportedOperationException();
// write a recursive implementation here
public Object remove(int index)
return null;
public boolean remove(Object o)
return true;
public boolean removeAll(Collection c)
return true;
public boolean retainAll(Collection c)
return true;
// write a recursive implementation here
public Object set(int index, Object element)
return null;
public int size()
return size;
// NOT implemented: to keep the homework reasonably simple
public List subList(int fromIndex, int toIndex)
throw new UnsupportedOperationException();
public Object[] toArray()
return null;
public Object[] toArray(Object[] a)
// you'll find this piece of code useful
// it checks the exact type of the array passed as a parameter
// in order to create a larger array of the same type.
if (a.length < size)
a = (Object[])java.lang.reflect.Array.
newInstance(a.getClass().getComponentType(), size);
// ... you need to write more code here!
return a;
private static final Node NOT_FOUND = null;
//FindPos
private Node findPos(Object o)
for(Node p = head.next; ; p = p.next)
if(o == null)
if(p.data == null)
return p;
else if(o.equals(p.data))
return p;
return NOT_FOUND;
//Get Node
private Node getNode(int index)
Node p;
if(index < 0 || index > size())
throw new IndexOutOfBoundsException();
if(index < size() /2)
p = head.next;
for(int i = 0; i < index; i++)
p = p.next;
return p;
//Print The node
private static void print(Node n)
Node current = n.next;
while (current != null){
System.out.println(current.data);
current = current.next;
public static void main (String[] args){
System.out.println("Singly Linked List");
System.out.println();
SinglyLinkedList l = new SinglyLinkedList();
l.add("F");
l.add("K");
}C:\Umass\CS210\Hw2\SinglyLinkedList.java:301: unreachable statement
return NOT_FOUND;
^
C:\Umass\CS210\Hw2\SinglyLinkedList.java:316: variable p might not have been initialized
return p;
^
The first problem is because your "for" loop has no "while" condition in it:
for(Node p = head.next; ; p = p.next)...
Therefor, the only way out of the loop is via break, return, or exception. In your case, you don't "break" out of the loop, so there's no way it can get to this statement.
The second problem, you didn't cover all cases to set "p", so it won't let you return an un-initialized value. -
How can I reduce the font. Can't slide?
You probably have figured this out already - but just in case -
Take 3 fingers and, all at the same time, double tap the screen. This will reset the size back to normal. I had the same problem a few weeks ago, Good Luck, Ron -
I am struggeling to download files in any format (i.e. pdf, dmg etc.). It deosn't bring up the download list anymore and in finder under downloads, it has the following suffix eg. xxx.pdf.part. The file size is usually 0 bites. Any advice?
Another comment on this forum back in 2009 suggests donloading applejack. This did not seem to fix the problem and the latest version only indicates support up to Leopard. I am currently running Lion... so a little nervous downloading this.
Any help here would be greatly appreciated, since I am highly dependent on this facility for my studies and other activities!!The first step is to disable or remove that download manager entirely. That in itself is a likely cause of your problem.
The following can be tried in any order:
— disable all the other extensions in your browsers and try again.
— are you running any AV software or using Little Snitch? If so, disable those. You'll probably also have to kill those in Activity monitor, as both run background helper processes that run when the main app isn't and can interfere with network connections.
— look in your Login Items in
> System Preferences > Users & Groups | Login Items
and remove any 3rd party apps that are there. Restart the computer and test again.
If you've tried all those and still have the problem, report back. -
Two calendars in my list of seven are not correctly syncing between my iMac and my ipad & iPhone. Also, the two calendars appear in my iCloud list with alert symbols after the (triangle with exclamation mark) whereas others in list show a "broadcasting" symbol. I don't know how to find out what these alerts are.
I have noticed problems in syncing special recurring events....I.e I am able to set up a 'last Friday of each month" on my iMac, but it doesn't appear on my iPad or iPhone. And I note I can't set up a special recurring event on my iPad or iPhone. What can I do to solve this? Is this a known flaw in iCal?
Mary CI have no idea if this will help as I sync via iTunes under OSX.6.8 - but there may be a clue somewhere here:
https://discussions.apple.com/thread/4981514
I have to say that, even after doing all that, my problem seems to recur at random with no obvious trigger - and it is even more bizarre because, like you, not all calendars or events are affected. Sometimes, different events within the same calendar are duplicated whereas others aren't!
And just how the iPad seems to pick up events which no longer appear in iCal is beyond me - presumably somewhere in a plist or old cache file but, as I said, no-one has any idea what or where!
No-one has managed to explian why my problem occurs or, indeed, just what is happening, but at least I now know how I can correct it, albeit via tedious series of steps.
I hope that helps? -
Can't find the geturl Statement HELP PLEASE
Ok I've been using for 3 years now flash, and of
course sometimes I have to modify the work of others. So far when I
intended to modify the target URL for a button I select the button,
and modify the getURL statement.
Then I changed to CS3, and I got a menu I need to change...
actionscript window is no longer where it used to be, but no
problem, I just clicked F9 locate the button and see the
actionscript right? WRONG.
All I see is the stop() and the gotoAndPlay statements but
not a single gotoURL in all the AS window. I can't seem to find how
to locate that instruction or even if there is another way to make
a button go to a URL without the gotoURL instruction, that i'm sure
has to be there... any idea how to locate the instruction?
Any help will be highly appreciated.
Elliot J. BalanzaOk here is how they did it, and i must say it was pretty
clever.
they created a layer called hit, and put the button there,
BUT on the layer hit on the first frame they just put a carriage
return (in the frame)
Now when you click on the button, they put the normal stuff,
on release etc. THEN they hide the hit layer and locked it.
End result, if you tried to see through AS the code, you just
saw a carriage return, even when the code was in that same frame
but on the button instance... further more even in the AS pane, you
only see a carriage return UNTIL you unlock the layer, make it
visible, and select the button, other wise you just see the
carriage return...
Thanks for your feeback dzedward you are the best. -
I'm at my wits end!!! Can't find the problem!!!
okay, I've got the code written for a vending machine program. i have a text file that loads in field variables to a product class, a money class that handles the basic functions of money handling methods, and a vending machine applet. the files compile fine, but they don't execute. i get an error: nosuchmethod error: main, you know the kind. i don't have a main because i'm trying to run it as an applet, but it won't run when i use appletviewer, it just does't do anything! This is going to be a tough one. But i swear up and down that i will literally find some way to pay the person who can find what the heck is wrong with the code...so, here it is, and i know it's long, but this is the final project in my java class at college, and i can't find where i'm going wrong.
the vendingmachine:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.NumberFormat;
import java.util.StringTokenizer;
import utilities.CashIn;
import utilities.Product;
public class VendingMachine extends Applet implements ActionListener {
private Font boldSerif16 = new Font("Serif",Font.BOLD,16);
private Font boldSerif24 = new Font("Serif",Font.BOLD,24);
private Font boldItalicSerif24 = new Font("Serif",Font.BOLD+Font.ITALIC,24);
private Font boldItalicSerif13 = new Font("Serif",Font.BOLD+Font.ITALIC,13);
private Font boldItalicSerif40 = new Font("Serif",Font.BOLD+Font.ITALIC,40);
// Mode flag.
private int mode = 0;
// Panels for the buttons
private Panel mainPanel = new Panel();
private Panel cashPanel = new Panel();
private Panel selPanel = new Panel();
private Panel maintPanel = new Panel();
// Product selection panel buttons
private Button selBtn[] = new Button[6];
// Cash customer puts in machine panel buttons
private Button viewC = new Button("View The Products");
private Button quit = new Button("Quit");
private Button bNickle = new Button("Nickel");
private Button bDime = new Button("Dime");
private Button bQuarter = new Button("Quarter");
private Button b$Paper = new Button("$1 Paper");
private Button b$Coin = new Button("$1 Coin");
private Label lCredit = new Label(" Credit:");
private Label lMsg = new Label("");
private Button bChange = new Button("Change Return");
private Button purchase = new Button("Purchase");
private Button maintenance = new Button("Maintenance");
private Product productForSale [];
private CashIn changeOH;
private int $collected = 0;
private double total$In = 0.00;
private NumberFormat nf;
private Image pic;
private Image picAnim;
private int prodSel = 999;
private String line;
private String f[] = new String[8];
private int tokenCount;
private int int3, int4, int5, int6, int7;
private double dbl4;
private StringTokenizer strings;
private int dispense = 99;
public void init()
{ setLayout(new BorderLayout());
productForSale = new Product[6];
try
{ BufferedReader inPut = new BufferedReader(new FileReader("Startup.txt"));
while ((line=inPut.readLine()) != null)
{ strings = new StringTokenizer(line,",");
tokenCount = strings.countTokens();
// Loop thru and retrieve each data element.
for (int i=0; i<tokenCount; i++)
f[i] = strings.nextToken();
// Load the money.
if (f[0].compareTo("M") == 0)
{ int3 = Integer.parseInt(f[3]);
int4 = Integer.parseInt(f[4]);
int5 = Integer.parseInt(f[5]);
int6 = Integer.parseInt(f[6]);
int7 = Integer.parseInt(f[7]);
changeOH = new CashIn(f[1],f[2],int3,int4,int5,int6,int7);
// Load the products.
if (f[0].compareTo("P") == 0)
{ int3 = Integer.parseInt(f[3]);
dbl4 = (new Double(f[4])).doubleValue();
int5 = Integer.parseInt(f[5]);
int6 = Integer.parseInt(f[6]);
int7 = Integer.parseInt(f[7]);
productForSale[int3] = new Product(f[1],f[2],dbl4,int5,int6,int7);
inPut.close();
catch(IOException e)
{ e.printStackTrace();
setBackground(Color.blue);
setForeground(new Color(120,0,120));
setFont(boldSerif16);
cashPanel.setLayout(new GridLayout(10,1));
cashPanel.add(viewC);
cashPanel.add(quit);
cashPanel.add(bNickle);
cashPanel.add(bDime);
cashPanel.add(bQuarter);
cashPanel.add(b$Paper);
cashPanel.add(b$Coin);
cashPanel.add(lCredit);
cashPanel.add(lMsg);
cashPanel.add(bChange);
add(cashPanel,"East");
selPanel.setLayout(new GridLayout(1,6));
for (int i=0; i<6; i++)
{ selBtn[i] = new Button(productForSale.getName());
selPanel.add(selBtn[i]);
add(selPanel,"South");
setBackground(Color.black);
viewC.addActionListener(this);
quit.addActionListener(this);
bNickle.addActionListener(this);
bDime.addActionListener(this);
bQuarter.addActionListener(this);
b$Paper.addActionListener(this);
b$Coin.addActionListener(this);
bChange.addActionListener(this);
nf = NumberFormat.getCurrencyInstance();
for (int i=0; i<6; i++)
selBtn[i].addActionListener(this);
} // =======>> END OF INIT METHOD
// ** PAINT METHOD **
public void paint(Graphics g)
{ int xVal = 35;
int yVal = 85;
int xValAnim = 0;
int yValAnim = 0;
int c = 0;
// Paint the product pictures on the vending machine.
g.setColor(Color.cyan);
g.setFont(boldItalicSerif24);
g.drawString(changeOH.getLogo1(),115,40);
g.setFont(boldItalicSerif13);
g.drawString(changeOH.getLogo2(),200,60);
for (int z=0; z<2; z++)
{ xVal = 35;
yVal = 85;
c = 0;
g.setColor(Color.black);
g.fillRect(xVal,yVal,500,350);
g.setColor(Color.yellow);
for (int i=0; i<2; i++)
{ for (int j=0; j<3; j++)
{ g.setFont(boldSerif16);
g.drawString(nf.format(productForSale[c].getPrice()),xVal+45,yVal-5);
pic = getImage(getCodeBase(),productForSale[c].getPic());
g.drawImage(pic,xVal,yVal,null);
// If product is dispensed get ready to animate.
if (c == dispense)
{ xValAnim = xVal;
yValAnim = yVal;
picAnim = pic;
xVal = xVal + 170;
c++;
yVal = yVal + 160;
xVal = 35;
// If product is dispensed, animate it.
if (dispense < 99)
{ for (int y=0; y<40; y++)
{ g.setColor(Color.black);
g.fillRect(xValAnim,yValAnim-9,125,125);
g.setColor(Color.yellow);
g.drawImage(picAnim,xValAnim,yValAnim,null);
yValAnim = yValAnim + 10;
pause(3);
dispense = 99;
if (mode == 0)
{ pic = getImage(getCodeBase(),"OutStock.gif");
g.drawImage(pic,300,300,null);
g.setColor(Color.black);
g.fillRect(1,1,500,300);
g.setColor(Color.pink);
g.setFont(boldItalicSerif40);
g.drawString(changeOH.getLogo1(),10,150);
g.setFont(boldItalicSerif24);
g.drawString(changeOH.getLogo2(),160,250);
mode++;
} // =======>> END OF PAINT METHOD
// ** ACTIONPERFORMED METHOD **
public void actionPerformed(ActionEvent event)
{ Object source = event.getSource();
lMsg.setText(" Enter up to $1.00");
// Customer puts money in the vending machine.
// Customer paid a nickle
if (source == bNickle && $collected < 96)
{ changeOH.nickleIn();
$collected = $collected + 5;
// Customer paid a dime
if (source == bDime && $collected < 91)
{ changeOH.dimeIn();
$collected = $collected + 10;
// Customer paid a quarter
if (source == bQuarter && $collected < 76)
{ changeOH.quarterIn();
$collected = $collected + 25;
// Customer paid a paper dollar
if (source == b$Paper && $collected == 0)
{ changeOH.dollarPaperIn();
$collected = $collected + 100;
// Customer paid a coin dollar
if (source == b$Coin && $collected == 0)
{ changeOH.dollarCoinIn();
$collected = $collected + 100;
// Customer makes their product selection.
for (int i=0; i<6; i++)
{ if (source == selBtn[i])
// Do nothing if customer selects item that isn't on-hand.
if (productForSale[i].getOnHand() == 0)
repaint();
// We have product on-hand.
else
{ prodSel = i;
// Tell customer to add more money if they don't have
// enough in the machine to handle the purchase.
if ($collected < (int) (productForSale[i].getPrice() * 100))
{ lMsg.setText(" Insert Money");
// Customer has enough money in machine to cover purchase.
else
{ // Take cost of item from customer's money
dbl4 = productForSale[i].getPrice() * 100;
int4 = changeOH.giveChange($collected - (int)dbl4,0);
// Tell customer to put exact amount in the machine
// because there isn't enough change to handle purchase.
if (int4 == 9)
{ lMsg.setText("Exact Amount Only!");
// **** Here the purchase was made and committed. ****
else
{ total$In = productForSale[i].getPrice() * 100;
$collected = $collected - (int) total$In;
productForSale[i].sellProduct();
dispense = i;
repaint();
// If the last product item was sold, set picture to OutStock.gif.
if (productForSale[i].getOnHand() <= 0)
productForSale[i].setOutOfStock();
if ((source == bChange || source == quit) && $collected > 0)
{ $collected = changeOH.giveChange($collected,1);
// Here we save the machine info file when customer asks
// for their change back or quits the machine.
// Customer has selected to Quit the vending machine program.
// Quit the program.
if (source == quit)
System.exit(0);
// These commands set up variables to show how much money
// the customer has in the machine.
total$In = $collected;
total$In = total$In / 100;
lCredit.setText(" Credit: " + nf.format(total$In));
repaint();
} // =======>> END OF ACTIONPERFORMED METHOD
// ** PAUSE METHOD **
public void pause(int i)
{ for(long l = System.currentTimeMillis() + (long) i; System.currentTimeMillis() < l;);
This is the product class:
package utilities;
import java.io.*;
import java.util.StringTokenizer;
public class Product {
private String name;
private String image;
private String picUsed;
private double price;
private int onHand;
private int sold;
private int maint;
public Product(String n, String i, double p, int o, int s, int m)
{ name = n;
image = i;
picUsed = i;
price = p;
onHand = o;
sold = s;
maint = m;
// Reset picture used when product is out of stock.
public void setOutOfStock()
{ picUsed = "OutStock.gif";
// Get product information
public String getName()
{ return name;
public String getImage()
{ return image;
public String getPic()
{ return picUsed;
public double getPrice()
{ return price;
public int getOnHand()
{ return onHand;
public int getQtySold()
{ return sold;
public int getMaintDate()
{ return maint;
// Sell one of the product.
public void sellProduct()
{ onHand--;
sold++;
// Set the product values.
public void setName(String n)
{ name = n;
public void setImage(String i)
{ image = i;
picUsed = i;
public void setPrice(double p)
{ price = p;
public void setOnHand(int o)
{ onHand = o;
public void setQtySold(int s)
{ sold = s;
public void setMaintDate(int m)
{ maint = m; }
The money class:
package utilities;
import java.math.*;
public class CashIn {
private String logo1;
private String logo2;
private int numProd;
private int nickles;
private int dimes;
private int quarters;
private int dollarsP;
private int dollarsC;
private int money;
private double moneyVal;
private int amtToChange = 0;
private int hNickle;
private int hDime;
private int hQuarter;
private int hpDollar;
private int hcDollar;
public CashIn(String l1, String l2, int p, int q, int d, int n, int dP)
{ logo1 = l1;
logo2 = l2;
numProd = p;
quarters = q;
dimes = d;
nickles = n;
dollarsP = dP;
dollarsC = 0;
money = (n * 5) + (d * 10) + (q * 25) + (dP * 100);
// Get total of money in machine.
public double getCashIn()
{ moneyVal = money;
moneyVal = moneyVal / 100;
return moneyVal;
// Get machine record information.
public String getLogo1()
{ return logo1;
public String getLogo2()
{ return logo2;
public int getNumProd()
{ return numProd;
public int getNickles()
{ return nickles;
public int getDimes()
{ return dimes;
public int getQuarters()
{ return quarters;
public int getDollarPaper()
{ return dollarsP;
public int getDollarCoins()
{ return dollarsC;
// Money comes into the machine
public void nickleIn()
{ nickles++;
money = money + 05;
public void dimeIn()
{ dimes++;
money = money + 10;
public void quarterIn()
{ quarters++;
money = money + 25;
public void dollarPaperIn()
{ dollarsP++;
money = money + 100;
public void dollarCoinIn()
{ dollarsC++;
money = money + 100;
// Give the customer their change.
public int giveChange(int custMoney, int mode)
{ hNickle = nickles;
hDime = dimes;
hQuarter = quarters;
hpDollar = dollarsP;
hcDollar = dollarsC;
amtToChange = custMoney / 100;
for (int i=0; i<amtToChange; i++)
{ // Give change in dollar coin if possible
if (hcDollar > 0)
{ hcDollar--;
custMoney = custMoney - 100;
// or else give change in paper dollar
else
{ if (hpDollar > 0)
{ hpDollar--;
custMoney = custMoney - 100;
amtToChange = custMoney / 25;
for (int i=0; i<amtToChange; i++)
{ if (hQuarter > 0)
{ hQuarter--;
custMoney = custMoney - 25;
amtToChange = custMoney / 10;
for (int i=0; i<amtToChange; i++)
{ if (hDime > 0)
{ hDime--;
custMoney = custMoney - 10;
amtToChange = custMoney / 5;
if (amtToChange > hNickle)
{ mode = 9;
for (int i=0; i<amtToChange; i++)
{ hNickle--;
custMoney = custMoney - 5;
if (mode == 1)
{ nickles = hNickle;
dimes = hDime;
quarters = hQuarter;
dollarsP = hpDollar;
dollarsC = hcDollar;
money = money - custMoney;
if (mode == 9) custMoney = 9;
return custMoney;
the startup text:
p,Fritos,Images/FritoLay.gif,
m,$.50,
p,Dr. Pepper,Images/Dr.Pepper.gif,
m,$.60,
p,Pepsi,Images/Pepsi.gif,
m,$.60,
p,Coke,Images/CocaCola.gif,
m,$.60,
p,Seven-Up,Images/7-Up.gif,
m,$.60,
p,Sprite,Images/Sprite.gif,
m,$.60,
c,10,20,40,S/he's only offering six Dukes here:
http://forum.java.sun.com/thread.jsp?forum=54&thread=469450&start=0&range=15#2169975
This problem has been done before. Break this down into something simpler. You don't need an applet. Just do it on the command line. You don't need a database. Just create a flat file if you need some persistent data. Do the simple thing first, then build out from there.
Click on the special tokens link up above and learn how to use [ code][ code] tags.
Your code is a big, unreadable mess. You've got pare this down into something sensible. If you can't understand it, it's unreasonable to expect someone on this forum to wade through all of that. - MOD
Maybe you are looking for
-
Hello, I've had harsh time trying to figure out how to read a csv file with double quotes, I need to read a csv file in order to fill a spreadsheet. I attach a csv file example to show the sort of file I'm working on. Thank you Raymundo Cassani Solve
-
SQL Query to retrieve the records
Hi All, I have one table. It contains millions of records.I gave the query as follows. select * from emp where empnob in (1,1000) it displays empnob 1 A 300000 Manager 6 B 120000 Analyst 87 C 32980 salsman Now I want to retrieve remaining records. Pe
-
HR ABAP FAQs - Part 7 (ans needed)
Hi, 1. What is the Additional Actions Infotype used for? 2. If an employee leaves the enterprise, are all Infotypes delimited? 3.What is an Infotype menu and what is its purpose? 4. What is an info group? What is a personnel action? 5. Which authoriz
-
Crazy green square artefacts showing on render
First of all I would like to thank the moderators for deleting my initial post. Yes, it included some bad language, but that can be censored. It's nice to know Adobe only cares about their image rather than solving their users' issues with the softwa
-
I have just downloaded creative suite cs2 but to install it I seem to need a serial number.which I don't have. I printed off the installation instructions, but they don't seem to correspond with what I am having to do l