Jason Rod

Greenhorn
+ Follow
since Apr 13, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jason Rod

I have checked and double checked the file which I am reading from and it has the element in there. Here is my code:



I used a JOP to print out the ArrayList.toString() method and the element I am trying to access is in there too.
17 years ago
I have a question about Object arrayLists. I populated an arrayList with data and then wrote the ArrayList to disk using an ObjectOutputStream. I then repopulated the ArrayList using an ObjectInputStream but I am having trouble accessing this data and was wondering if anyone can help me out or point me in a general direction. I've tried using the ".indexOf(Object elem) method but it returned "-1" when I know the data is in there. I've already looked at all the information listed on the Java website and it didn't help at all. Thanks in advance for the help.
17 years ago
Problem solved, found out that my problem was with the .txt file I was trying to write to, Thanks for the response though.
17 years ago
I am trying to stream an arrayList from another class and write it to file. The code has no errors but nothing is being written to the file either. The file name is "Accounts.txt". Here is the code:



I don't know if that code is even right, but any help would be greatly appreciated. Thanks in advance.
17 years ago
oh great, that worked, thanks a bunch.
[ May 22, 2006: Message edited by: Jason Rod ]
17 years ago
I am having problems with a program hanging on a class method and I am not sure if it is caused by an infinite loop or something else. Here is the method.


studAns[i][j] is a double matrix containing 8 students(i), each with 10 answers(j).
answerKey[j] is a single matrix containing 10 answers(j).

I have no problems compiling the code, and I get no errors when running the program, it just hangs. After looking at the method I could not discern any problems with it, and I have checked and double checked and I know that this is the method on which the program hangs.
17 years ago
oh ok, got it, thanks so much
17 years ago
Sorry, I'm new to using arrays, how would I instantiate it in this case?
17 years ago
I am working on a program that will grade tests and return the test scores, the average, highest, and lowest scores, and will sort the scores from highest to lowest. The program allows the user to input answers for only one of the students, the rest of the student answers are hard-coded. I am having trouble with a null pointer exception on the line that says:

char studAns[][] = new char[][]

I am also unsure about the sorting method that I used, I have been having problems trying to find a simple sorting algorithm that will allow the data in the array to maintain it's same index number while being sorted.

here is the code



[ May 17, 2006: Message edited by: Jason Rod ]

[ May 17, 2006: Message edited by: Jason Rod ]

[ May 17, 2006: Message edited by: Jason Rod ]
[ May 17, 2006: Message edited by: Jason Rod ]
17 years ago
Ok well this is what I have so far. The helper class is:




public class ChangeCalc
{

int quarters, dimes, nickels, change, num1, num2, num3, num4;

public int change (int num1)
{
if (num1 == 1) {
change = 0; }
else {
change = 100 - num1; }
return change;
}

public int num2 ()
{
num2 = (change/25);

if (num2 >= 3)
{
quarters = 3;
}

else if (num2 >= 2) {
quarters = 2; }
else if (num2 >= 1) {
quarters = 1; }
else {
quarters = 0; }
return quarters;
}

public int num3 ()
{
num3 = change - quarters * 25;

if (num3 >= 20) {
dimes = 2; }
else if (num3 >= 10) {
dimes = 1; }
else {
dimes = 0; }
return dimes;
}

public int num4()
{
num4 = num3 - dimes * 10;

if (num4 >= 5) {
nickels = 1; }
else {
nickels = 0; }
return nickels;
}
}





and the implementation class is:

import javax.swing.JOptionPane;

public class VendingMachineImpl
{
public static void main (String [] args)
{

String userInput;
int num1, num2, num3, num4, change, nickels, dimes, quarters;

userInput = JOptionPane.showInputDialog ("Enter the price of your item, from 25" +
"cents to a dollar in 5-cent increments" +
"\nNote: For one dollar, please use 100 cents");
num1 = Integer.parseInt(userInput);

while (num1 <= 24) {
JOptionPane.showMessageDialog (null, "Please enter a valid number");
userInput = JOptionPane.showInputDialog ("Enter the price of your item, from 25" +
"cents to a dollar in 5-cent increments" +
"\nNote: For one dollar, please use 100 cents");
num1 = Integer.parseInt(userInput); }

while (num1 >= 101) {
JOptionPane.showMessageDialog (null, "Please enter a valid number");
userInput = JOptionPane.showInputDialog ("Enter the price of your item, from 25" +
"cents to a dollar in 5-cent increments" +
"\nNote: For one dollar, please use 100 cents");
num1 = Integer.parseInt(userInput); }

ChangeCalc c = new ChangeCalc();
ChangeCalc q = new ChangeCalc();
ChangeCalc d = new ChangeCalc();
ChangeCalc n = new ChangeCalc();

JOptionPane.showMessageDialog (null, "Your item cost " + num1 + " cents" +
" and you inserted a dollar" + "\nYour" +
" change is: " + c + " cents" + "\nGiven"
+ " in: " + q + " quarter(s), " + d +
" dime(s), and " + n + " nickel(s) ");

System.exit(0);
}
}

But, when I run the program the values returned for quarters, dimes, and nickels look like "ChangeCalc@ab04c32." I've already tested the equations and they work fine so I'm thinking the problem arises when I call the methods.
[ April 15, 2006: Message edited by: Jason Rod ]
18 years ago
edit: double post :roll:

[ April 13, 2006: Message edited by: Jason Rod ]
[ April 13, 2006: Message edited by: Jason Rod ]
18 years ago
sorry for the ambiguity, basically the program is a VERY simple vending machine, the user inputs the price, no items are involved, so the program would be better described as a pseudo-change machine I suppose. One enters a price, between 25 cents and a dollar in 5-cent increments and the user inserts a dollar, the program then figures out the change, change = 100 - cost of item, and then converts the change into quarters, dimes, and nickels. I hope that's a little more clear than my first explanation.

As of right now I'm trying to make a class for the mathematical calculations, with a subclass for each type of coin (i.e. quarter, dime, nickel). So my class is called Change, and the subclasses are called Change.quarter, Change.dime, and Change.nickel. So I will give that a try and report back.
18 years ago
ok, i think i understand, thanks for the help, i'll go try that out now.
18 years ago
Hey everyone, I'm working on a program for my Java class but am having a heck of a time trying to figure out how to make classes for it. The code is a basic vending machine, inserting 25 cents to a dollar in 5 cent increments with the change being returned in the format of quarters, dimes, and nickels. Here is the code without classes:

import javax.swing.JOptionPane;

public class VendingMachine
{
public static void main (String [] args)
{

String userInput;
int num1, num2, num3, num4, change, nickels, dimes, quarters;

userInput = JOptionPane.showInputDialog ("Enter the price of your item, from 25" +
"cents to a dollar in 5-cent increments" +
"\nNote: For one dollar, please use 100 cents");
num1 = Integer.parseInt(userInput);

while (num1 <= 24) {
JOptionPane.showMessageDialog (null, "Please enter a valid number");
userInput = JOptionPane.showInputDialog ("Enter the price of your item, from 25" +
"cents to a dollar in 5-cent increments" +
"\nNote: For one dollar, please use 100 cents");
num1 = Integer.parseInt(userInput); }

while (num1 >= 101) {
JOptionPane.showMessageDialog (null, "Please enter a valid number");
userInput = JOptionPane.showInputDialog ("Enter the price of your item, from 25" +
"cents to a dollar in 5-cent increments" +
"\nNote: For one dollar, please use 100 cents");
num1 = Integer.parseInt(userInput); }

if (num1 == 1) {
change = 0; }
else {
change = 100 - num1; }

num2 = (change/25);
if (num2 >= 3) {
quarters = 3; }
else if (num2 >= 2) {
quarters = 2; }
else if (num2 >= 1) {
quarters = 1; }
else {
quarters = 0; }

num3 = change - quarters*25;
if (num3 >= 20) {
dimes = 2; }
else if (num3 >= 10) {
dimes = 1; }
else {
dimes = 0; }

num4 = num3 - dimes*10;
if (num4 >= 5) {
nickels = 1; }
else {
nickels = 0; }

JOptionPane.showMessageDialog (null, "Your item cost " + num1 + " cents" +
" and you inserted a dollar" + "\nYour" +
" change is: " + change + " cents" + "\nGiven in: "
+ quarters + " quarter(s), " +
+ dimes + " dime(s), and " + nickels +
" nickel(s) ");

System.exit(0);
}
}

I was wondering if anyone can help me out with creating a class or classes for the mathematical operations, or if someone can point me in the direction of an online tutorial that goes in depth into creating classes it would be greatly appreciated. Thanks in advance for your time.
18 years ago