Win a copy of Rust Web Development this week in the Other Languages forum!

John Walker

Greenhorn
+ Follow
since Oct 28, 2003
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 John Walker

I'm in the process of creating a blackjack program and I need for it to deal out cards, but not have them repeat. I was thinking of making each card a variable, but I can't figure out how to make them not repeat themselves.
18 years ago
Hello everyone, I'm trying to make a little program that will output a random card from a deck. I just started but I'm getting the error that the card variable might not be initalized. What am I doing wrong?
public class Cards {

public static void main (String[]args) {
int number;
String card;
number = (int)(Math.random()*4+1);

if (number == 1)
card = ("Ace");
else
if (number == 2)
card = ("2");
else
if (number == 3)
card = ("3");
else
if (number == 4)
card = ("4");
else
System.out.println(card);

}
}
18 years ago
Thanks for the help. For the loop I just want it to display the multiplier (let's say 2) and the second input # will be the number of times tables displayed (let's say 4). So the loop will go around and outupt 2x1=2, 2x2=4, 2x3=6, 2x4=8 and end.
18 years ago
Hi all, I'm trying to create a program where the user inputs two numbers, the first will be the multiplication table and the second will be by how many many times tables to be shown. I'm having trouble getting the variables right.
import javax.swing.JOptionPane;

public class InputMultiply {

public static void main (String[]args) {
String input = JOptionPane.showInputDialog("Enter a multiplier");

String inputa = JOptionPane.showInputDialog("Enter the number of problems you want to display");

int input1 = input;
int input2 = inputa;
int answer;

for (input=1; input2 <= input2; input2++)
{
answer = input1 * input2;
System.out.println(input1 + "*" + input2 + "=" + answer);
}



System.exit(0);
}
}

I get the error:
C:\java\bin>javac InputMultiply.java
InputMultiply.java:13: incompatible types
found : java.lang.String
required: int
int input1 = input;
^
InputMultiply.java:14: incompatible types
found : java.lang.String
required: int
int input2 = inputa;
^
InputMultiply.java:18: incompatible types
found : int
required: java.lang.String
for (input=1; input2 <= input2; input2++)

Any suggestions?
18 years ago
This program is compiling and running, but it won't output anything. This is my first time using the console input so I'm new to this. What am I doing wrong?
import java.io.*;
public class Month {

public static void main (String[]args) throws IOException {

BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));


String response;
System.out.println ("Enter a numerical month number (1-12)");



if (response == 1)
System.in.println ("January has 31 days.");
else
if (response == "2")
System.out.println ("Febrary has 28 days, 29 in a leap year.");
else
if (response == "3")
System.out.println ("March has 31 days.");
else
if (response == "4")
System.out.println ("April has 30 days.");
else
if (response == "5")
System.out.println ("May has 31 days.");
else
if (response == "6")
System.out.println ("June has 30 days.");
else
if (response == "7")
System.out.println ("July has 31 days.");
else
if (response == "8")
System.out.println ("August has 31 days.");
else
if (response == "9")
System.out.println ("September has 30 days.");
else
if (response == "10")
System.out.println ("October has 31 days.");
else

if (response == "11")
System.out.println ("November has 30 days.");
else
if (response == "12")
System.out.println ("December has 31 days.");

}
}
18 years ago
I tried that but it still kept adding all of them together.
18 years ago
I'm trying to get my program to take coins out of the purse, but it keeps adding them:
public class Purse
{
private int pennies;
private int nickels;
private int dimes;
private int quarters;
public void purse ()
{
pennies = 0;
nickels = 0;
dimes = 0;
quarters = 0;
}
public void addPennies (int count)
{
pennies = pennies + count;
}
public void addNickels (int count)
{
nickels = nickels + count;
}
public void addDimes (int count)
{
dimes = dimes + count;
}
public void addQuarters (int count)
{
quarters = quarters + count;
}
public void delPennies (int count)
{
pennies = count - pennies;
}
public void delNickels (int count)
{
nickels = count - nickels;
}
public void delDimes (int count)
{
dimes = count - dimes;
}
public void delQuarters (int count)
{
quarters = count - quarters;
}
public double calculateTotal ()
{
return (pennies*.01)+(nickels*.05)+(dimes*.10)+(quarters*.25);
}
}
import javax.swing.JOptionPane;
public class InputTest3 {

public static void main (String[]args) {
Purse myPurse = new Purse ();

String input = JOptionPane.showInputDialog("How many pennies do you have?");
int count = Integer.parseInt(input);
myPurse.addPennies(count);
input = JOptionPane.showInputDialog("How many nickels do you have?");
count = Integer.parseInt(input);
myPurse.addNickels(count);
input = JOptionPane.showInputDialog("How many dimes do you have?");
count = Integer.parseInt(input);
myPurse.addDimes(count);
input = JOptionPane.showInputDialog("How many quarters do you have?");
count = Integer.parseInt(input);
myPurse.addQuarters(count);
input = JOptionPane.showInputDialog("How many pennies do you want to take out?");
count = Integer.parseInt(input);
myPurse.delPennies(count);
input = JOptionPane.showInputDialog("How many nickels do you want to take out?");
count = Integer.parseInt(input);
myPurse.delNickels(count);
input = JOptionPane.showInputDialog("How many dimes do you want to take out?");
count = Integer.parseInt(input);
myPurse.delDimes(count);
input = JOptionPane.showInputDialog("How many quarters do you want to take out?");
count = Integer.parseInt(input);
myPurse.delQuarters(count);
double totalValue = myPurse.calculateTotal ();
System.out.println("The total is " + totalValue);

}
}
Any ideas? I'm pretty stuck here.
18 years ago
Thanks for all of the help, I got it to work. And yes this my real name thanks.
18 years ago
Here's the code I'm trying to compile.

That's the constructor method, and here's the main:

With that I keep getting the errors:


[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ October 28, 2003: Message edited by: Dirk Schreckmann ]
18 years ago