Vending Machine - Different Files

May 1, 2014

keep getting an error when inventory is printed out. wont carry the money over. cant find out how to do it?

[import java.util.Scanner;
public class VMachine
{
Scanner input = new Scanner (System.in);
double candy;
double soda;
double dsoda;
double money;

[Code] ....

View Replies


ADVERTISEMENT

Simple Vending Machine Program

Jan 22, 2014

I am having a difficult time writing what started out as a simple vending machine program. As I go on though, it seems that I'm overcomplicating it and it is getting messy, so I have resorted to the forum before I really get off the path. how to clean it up? I'm going to list a few of the problems I am having with the code below:

1. The user is supposed to enter his/her money and the program is to read each value separately (Do-While loop) and keep a running total of the money entered. I can't seem to get the right code format to do this. I was trying to do this with the variable total and so that is why the total exists in the switch statement, but it did not work.

2. In the second Do-While statement, is there a way to kick back an error when their are insufficient funds to purchase an item? Instead of getting a negative change return.

package practice;
import java.util.Scanner;
public class Practice {
public static void main(String[] args) {
double count, total;
int item;
//Display Available Options To Customer
Scanner input = new Scanner(System.in);
System.out.println("*VENDING MACHINE*");

[code]....

View Replies View Related

Vending Machine Program - Inheritance In Java

Mar 24, 2015

I'm making a vending machine program to practice inheritance and have a few questions. My superclass is a Soda class, and I'm making subclasses like "Orange soda", "Coke", etc. My first question is, what is the point of the subclass inheriting the instance variables of the superclass? If you have to define them again is there any point in the super class having them? Here is an example of this:

My superclass:

public abstract class Soda {

public double price;
public int numAvailable;
public String name;
public String machineCode;

[code]...

Besides not having to write the vendSoda() method again, what is the benefit of inheritance in a situation like this if you have to define all variables again? My second question is, how could I store all of the code strings from all of the different subclasses in one place? (so when the user enters a code it can search for the code entered to give the desired soda)...

View Replies View Related

Vending Machine Algorithm - Item Order And Retrieval

Oct 18, 2014

I'm having a major problem in forming the algorithm for my JAVA project, which is a vending machine. I desperately need one in order for it to guide me in making the code. I plan to include an array, switch class to customer and technician portals, item order and retrieval, and change calculator.

View Replies View Related

Making Vending Machine - Asking User To Insert More Money

Sep 23, 2014

So I am making a vending machine and am having trouble knowing what exactly to use or how to go about giving the user a error message depending if they initially added enough money for their choice of drink. So if the user only input 1 dollar, and the drink they select is $1.25, they need to add the $.25, but how do I implement that in this code?

Here is my code along with the zip file just in case.

package vending.sample;
import java.util.Scanner;
public class VendingSample {
public static void main(String[] args) {
int coke = 1, sprite = 2, DrPepper = 3, Pepsi = 4, Fanta = 5, Water = 6, selection, i;
double change, total;

[Code] ....

View Replies View Related

Vending Machine - Tell User Combination Of Coins That Equals To Amount Of Change

Jan 25, 2012

I have a simple java program to write which tells the user combination of coins that equals to the amount of change i.e:

user input 87

output:

3 quarters
1 dime
0 nickels
2 pennies

How the program remembers the remainder which is passed to the next column of let say dime

i.e

originalAmount = amount;
quarters = amount /25;
amount = amount % 25; <---- this is confusing for me?!?! how can the integer = integer % 25
dimes = amount / 10; <--- HOW THE PROGRAM remembers the "remainder" instead of the original user input as the code it self tells you dimes = amount where "amount" is what user input NOT remainder.

amount = amount % 10;
so on ....;

What I don't understand is HOW this algorithm works. I mean we have int amount where user inputs the number we get the first calculation amount/25 = how many quarters and then amount %25 WILL tell us about the reminder. By looking at this piece of code I would say that the system should start the calculation for the dimes again from the original number since the code says dimes = amount/10 AND amount = amount%10. My understanding is that the calculation should be done from the original user input.

Book or code it self is not clear for me how the reminder is "REMEMBERED" and then pass on to the next calculation>!?!?

UNLESS the code: amount=amount%25 gets the remainder so the next code under it is REQUIRED to read from the last prompt code.

View Replies View Related

Networking :: Connecting To Remote Windows Machine From Local Machine Using SSH2

Apr 11, 2014

I have developed a code to connecting remote windows M/C from local M/C by using SSH2 (ganymed-ssh2-build209.jar) API. when I run the code its giving below error. Is there any other way to connect remote windows system using java code.
 
Exception.
 
java.io.IOException: There was a problem while talking to <host name>:22
  at ch.ethz.ssh2.Connection.connect(Connection.java:642)
  at ch.ethz.ssh2.Connection.connect(Connection.java:460)
  at Connect.RemoteServer.ConnectWindowsServer.runCommand(ConnectWindowsServer.java:55)
  at Connect.RemoteServer.ConnectWindowsServer.main(ConnectWindowsServer.java:27)
Caused by: java.net.ConnectException: Connection refused: connect

[Code] ....
 
JAVA Code

import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
 public void setAuthenticationInfo(String hostname, String username,String password) {
       this.host = hostname;
       this.userid = username;
       this.password = password;      
       this.recentCommand = "";     
       System.out.println("setting authentication info completed for host=" + host );
 
[Code] .....

View Replies View Related

Java Code To Access Windows Machine From Unix Machine

Feb 28, 2014

I have a requirement where I have to send a file from a local system to unix box(present on client side) using java code.I have developed a code that is successfully sending the file from local system to client side unix box (I am connecting to client side unix box using VPN) provided I run the code in my eclipse IDE present in local system. But when I am running the same code in the unix box it is throwing null pointer exception.Might be the unix system is not recognising the local system. Please find the code.
 
package abc;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.Properties;
import com.jcraft.jsch.Channel;

[Code] ....

Error on unix box which I am getting is :-
 
Inside sftpConnection method
llllllll
fffffffffffff
Connection Successfull
Channel Connection Succesfull
aaaaa
Inside findFile method
Exception in thread "main" java.lang.NullPointerException
        at abc.TranferFile.sftpConnection(TranferFile.java:58)
        at abc.TranferFile.main(TranferFile.java:21)

View Replies View Related

How To Create Java Files Into Windows Applications (Exe Files)

Oct 26, 2014

What step to know to develop software..

View Replies View Related

How To Attach External Files To Executable Jar Or Exe Files

Apr 13, 2015

In a program I created, I'm using a text file that contains some texts needed for the program. The method relevant to this is something like the following.

private String wordgen(){
try {
BufferedReader reader = new BufferedReader(new FileReader("src/Resources/adjectives.txt"));
Random rand = new Random();
int low = rand.nextInt(400);
String fil="";
int i=0;
while(i!=low){

[Code]...

The program runs fine in netbeans project but once the jar is created it does not corporate with the text file. ("null" is returned) How can I attach text files to jar and exe?

View Replies View Related

How To Use JAXB - Transform TXT Files Into XML Files

Mar 10, 2015

I need to transformation the txt files into xml files, but each row txt files don't have same elements, for example the first book is composite one author

<books>
<book>Title</book>
<price>price</price>
<author>Author</author>
</books>

but the second book is composite two author

<books>
<book>Title</book>
<price>price</price>
<author>Author</author>
<author>Author2</author>
</books>

I would have the xml files with the number of authors variables, I can use JAXB for my problem?or not?

View Replies View Related

JSF :: Passing Session To Different Machine

Aug 4, 2014

In my JSF application user starts on primary server where the session begins and then the user is redirected to a different server using sendRedirect. I want to pass some authentication token to the next server from primary server. I am trying to set session attribute as:

request.getSession().setAttribute("auth_token", "1");

And then send it to the next server as:

response.sendRedirect(encodedUrl);

But this attribute is not reaching the new server. I cannot pass this auth_token as request parameter as that wont be secure. So how to get some session data to new server?

View Replies View Related

ATM Machine - Action Listeners

Mar 27, 2014

My output is all over the place. I cancelled out the borderlayouts beneath each panel I created and it completely changed the output, and I'm not sure why. The first photo below, shows what it looked like with the layouts and the second shows the output without. I still don't understand why I don't see the digits 1-9.

Java Code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
public class Atm extends JFrame {
Atm(){
super("ATM");
//Create Panels For ATM
JPanel buttonPanel1 = new JPanel(); //To Contain Digits 1-9

[Code] ....

Why would setting the layout beneath each object change the layout so much? I stayed consistent in my use of BLayout and GLayout in the program.

View Replies View Related

What Is Java Virtual Machine

Mar 5, 2014

What is Java Virtual Machine (Java VM)?

View Replies View Related

JCreator Slot Machine

May 18, 2014

I pulled off an all nighter in order to finish off this project for my computer studies class but i keep getting an error cannot find symbol at line 96?

import java.io.*;
import java.util.*;
import java.util.Random;
public class SlotMachine {
//Generates 3 random numbers for slot machine
public static void main(ArrayList<Integer> slotMachine) {

int count = 0;
while (count<3)

[code]....

View Replies View Related

Create ActionListener For ATM Machine

Mar 28, 2014

I've scanned the book and a few other forums trying to find an answer to my particular question (or I simply didn't understand) with no luck. I want to create an ActionListener for my ATM machine, that will both receive the input numbers to check them against the passcode for a predefined user, but also add the typical " * " that we see when performing such an action.

1. I have created individual objects for each button, which I then used in the constructor "perform" from class action. I'm not sure where to start in the method ActionPerformed.

2. How do I get the asterisks to appear in the JPasswordField each time a numeric button is pressed on the keypad?

Java Code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Atm extends JFrame {
Atm(){
super("ATM");
//Create Panels For ATM
JPanel buttonPanel1 = new JPanel(); //To Contain Digits 1-9
buttonPanel1.setLayout(new GridLayout(4,3));

[code]....

View Replies View Related

State Machine Compiler

Oct 19, 2014

I am working in software testing, specifically automatic test cases generation. Among the existing forms of test cases, my focus is on the test cases that are composed of sequences of events such as _.event1.event2 eventx()

However, the events can be classified into: sensitive and insensitive. The latter does not affect the system's states, and hence, it can be ignored; while the former affects the states. Anyhow, the sensitive events in the test cases may lead to states explosion and there is a need to prevent that. Therefore, some techniques suggest using one variable to present states and group all similar states together such as using len variable in circular queue. Relatively, the states can be represented by using specific drawings such FSM.

For example, the test cases for circular queue may look like:

add(0).remove().add(1).Front()
add(0).add(1).remove().Front()

which produce the following states:

len=1, rear=0, front=0 and dataQ[0]=0
len=0, rear=0, front=1 and dataQ={0}
len=1, rear=1, front=1 and dataQ[1]=1

len=1, rear=0, front=0 and dataQ[0]=0
len=2, rear=1, front=0 and dataQ[1]=1
len=1, rear=1, front=1 and dataQ={1,0}

As can be seen, every addition/deletion produces a new state. A state is composed of 4 variables: len, rear, front and dataQ. The 1st three variables are integers while the dataQ is an integer array. Nonetheless, the states produced by different test cases can be identical which wastes effort and time. So, there is a need to optimize these states. The search techniques were suggested where the problem can be represented as a search problem and the technique is applied. If we consider Len as a state, then we will have: len=0; 0QSize. However, this does not represent the state but it suits for classifying the states into groups.

In terms of states representation, State Machine/Map Compiler (SMC) was suggested as a modeling mechanism that takes the state machines (i.e. FSM) drawing and generates the code in any preferred language. In SMC, the FSM is represented in a specific syntax (state---transition----next state) and saved in a file (.sm). This file will be compiled by SMC to generate a context class which includes definitions of states, transitions and actions in FSM but still need to be triggered by another class. This class has to call the transitions that modifies the state.

We had created that class and implemented all the methods with their transitions. However, the FSM used was based on 1 variable only (i.e. len). Besides, we are still looking for the SMC results as they will be the input for any search technique to be applied. Supposedly, the states generated by SMC can be used directly in the search technique but this is still questionable.

View Replies View Related

ATM Machine - Inner Listener Class

Mar 31, 2014

Couple of problems here...

1. I am trying to use the getSource method in my inner class, in order to set the JPasswordField within an Inner Listener Class. This is a 4 integer password, setup by my for statement in the loop. I know what I want the program to do, but I don't know the correct language to use. I want the user to press one of the keys (0-9), that value be stored in JPassword (at least I think that is how it works) and for it to display the "*" in the Field---I want this to loop 4x. How do I use the getSource() to do this.

Also, I believe I need to use the set and get methods for the password entered into the JPassField, is that correct? The inner class is not recognizing my the object password that represents the JPasswordField.

2. In my second Inner Listener Class, clearButton, I set the event.getSource method to reset the JPasswordField to " ", when the clear button is pressed. Again, the problem is that the inner class does not recognize password. Why is this the case, since it is still a part of the parent class Atm?

Java Code: import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Atm extends JFrame {
Atm(){
super("ATM");
int i = 0;
//Create Panels For ATM
JPanel buttonPanel1 = new JPanel(); //To Contain Digits 1-9
buttonPanel1.setLayout(new GridLayout(4, 3));

[code]...

View Replies View Related

Could Not Create The Java Virtual Machine

Dec 11, 2014

I keep getting this error:-
/opt/solr# java -v
Unrecognized option: -v
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

View Replies View Related

Could Not Create Java Virtual Machine

Jan 19, 2012

Since a few weeks i receive windows reports with the text: "Could not create the Java virtual machine". That were not disturbing, but now i would like to play a game that based on Java, but every time I would start it, the message come and the game do not start. The game called "Edna and Harvey: The Breakout" (German: Edna bricht aus) and is developed by a german game studio called "Daedalic entertainment".

View Replies View Related

Electric Bandit Machine Coding

Jan 8, 2015

I am required to create an electronic bandit machine that can display all images and buttons, user can input money, random display of images, machine stop when money runs out, user can put money in and start again and also a display of winnings. So far The user can input money and this is added to their bank however when the spin button is clicked no shapes appear despite their being a selection of images. My code is below.

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.*;
import javax.swing.Timer;

[code]....

View Replies View Related

Java Virtual Machine Launcher

May 1, 2015

I created a program and am able to run it perfectly fine in netbeans/cmd. Then I made an .exe file with "Launch4j" and every time that I run the .exe file I get the following error: Java Virtual Machine Launcher: "A Java Exception has occurred."

Here in detail:

Exception in thread "main" java.lang.NoClassDefFoundError: edu/cmu/sphinx/util/props/PropertyException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)

[code]...

View Replies View Related

Program Which Stimulates A Bet Placer Machine

Dec 23, 2014

I am making a program which stimulates a bet placer machine for horse race betting for my school project.The program isnt complete yet but till this it doesnt let me input the String a and the program stops after printing "Type "view info" to display info about the different derbies". I use BlueJ 3.1.0 and version of jdk is the latest Java 8 Update 25

import java.util.*;
public class Derby
{
public static void main()
{
Scanner in=new Scanner(System.in);
System.out.println("Welcome to the Horse Racing Bet Placer Machine");
System.out.println("Through this Machine you can place bets on different derbies accross the globe");
System.out.println("Press 1 to choose a Derby"); //Ask user whether he wants to place a bet or not
System.out.println("Press 2 if you don't want to place a bet");
int choice=in.nextInt(); //Inputs user's choice
if (choice==2) //Determines the user's choice

[code]....

In this screenshot, after printing ''Type "view info" to display info about the different derbies'' it should let me input the value of String a according to the code but instead it stops the program there and doesn't let me input anything

View Replies View Related

Load Jars From Client Machine?

Apr 2, 2014

My application loads some 15 Jars from the server, which slows down the entire process.
 
I need to Load the Jars from a local machine. I want to store the Jar files in the client machine and not in the server.
 
So that every time when a client need to run my application by a URL specified, the Jar file stored in his system should load.

View Replies View Related

JSF :: Copying File From Server To Remote Machine

May 21, 2014

I am developing a web application in java(JSF 2.0 - Prime Faces). I need to do below operation. My appllication is running on WLS server. WLS is deployed on a server(say Machine-X). In my application i have a requirement , where i have to copy file from Machine-X to another Machine-Y. The Machine-Y is access restricted.

When i tried to copy the file from my app, getting no access exception. I have full control over Machine-Y. We cannot use SFTP as SFTP cannot be installed on target machine(Machine-Y). Robocopy is failing for some use cases. Is there any other way we can copy/write file from one server to other by providing userid/password in java

View Replies View Related

Slot Machine Program Using Methods And Arrays

Nov 13, 2014

I am designing a program that generates 3 random numbers from 1-5 and if 2 match, the user wins $1. If 3 match, the user wins respectively:

All 1s - $5
2s - $10
3s - $25
4s - $50
5s - $100

I first used a loop to run until the user runs out of money or wishes to stop. Then I made 2 methods. 1 to generate the random numbers and 1 to see if the user won any money. I am storing the random numbers in an array called slotnumber.

This is what I have so far but I am getting compiling errors at while (cont == 'y') {

import java.util.Scanner;
import java.util.Random;
public class SlotMachine
{

[Code]......

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved