import java.util.*;
import java.lang.*;
// blah
public class TwoDice
{
int dieOne = 0;
int dieTwo = 0;
int dieThree = 0;
int dieFour = 0;
int dieFive = 0;
int dieSix = 0;
Die dieRoll = new Die();
Die dieRoll2 = new Die();
dieRoll.dieValue()
dieRoll2.dieValue()
}
public class TwoDice
{
public static void main(String[] args);
int dieOne;
int dieTwo;
int dieResult;
Die dieRoll = new Die();
Die dieRoll2 = new Die();
Die dieRoll = new Die();
Die dieRoll2 = new Die();
import java.util.*;
import java.lang.*;
// This class generates a random number
public class Die
{
int dieValue;
public int Die()
{
dieValue = ((int) (Math.random() * 100) % 6 +
1);
return dieValue;
}
public void displayLine()
{
System.out.print("\n");
System.out.print("Roll One: " + dieValue + "\n");
System.out.print("Roll Two: " + dieValue + "\n");
}
}
import java.util.*;
import java.lang.*;
// This class instantiates 2 objects from the Die class
public class TwoDice
{
public static void main(String[] args)
{
Die dieRoll = new Die();
Die dieRoll2 = new Die();
dieRoll.Die();
dieRoll2.Die();
dieRoll.displayLine();
dieRoll2.displayLine();
}
}
import java.util.*;
import java.lang.*;
// This class instantiates 10 objects from the Die class
public class FiveDice
{
public static void main(String[] args)
{
Die dieOnePlayer = new Die();
Die dieOneCPU = new Die();
Die dieTwoPlayer = new Die();
Die dieTwoCPU = new Die();
Die dieThreePlayer = new Die();
Die dieThreeCPU = new Die();
Die dieFourPlayer = new Die();
Die dieFourCPU = new Die();
Die dieFivePlayer = new Die();
Die dieFiveCPU = new Die();
dieOnePlayer.Die();
dieOneCPU.Die();
dieTwoPlayer.Die();
dieTwoCPU.Die();
dieThreePlayer.Die();
dieThreeCPU.Die();
dieFourPlayer.Die();
dieFourCPU.Die();
dieFivePlayer.Die();
dieFiveCPU.Die();
dieOnePlayer.displayLine();
dieOneCPU.displayLine();
dieTwoPlayer.displayLine();
dieTwoCPU.displayLine();
dieThreePlayer.displayLine();
dieThreeCPU.displayLine();
dieFourPlayer.displayLine();
dieFourCPU.displayLine();
dieFivePlayer.displayLine();
dieFiveCPU.displayLine();
System.out.print("CPU wins 3 to 2");
}
}
public class FixDebugFour4
// This class discounts prices by 10%
{
public static void main(String args[])
{
double price = 100.00;
double rate = 0.10;
double discount = price * rate;
double newprice = price - discount;
System.out.print("Ten percent off of " + price + " dollars "
+ "is " + discount + " dollars " + "\n");
System.out.print("The new price of it is " + newprice + " dollars ");
}
}
public class FixDebugFour4
// This class discounts prices by 10%
{
public static void main(String args[])
{
int price = 100;
double price2 = 100.00;
tenPercentOff(price);
tenPercentOff(price2);
}
public static void tenPercentOff(int p)
{
double newPrice = price * .90;
System.out.println("Ten percent off";
System.out.println("New price is " + nwPrice);
}
public static void tenPercntOff(double price)
{
double price = p * .90;
System.out.println("Ten percent off");
System.out.println("New price is " + newPrice);
}
}
public class FixDebugFour4
// This class discounts prices by 10%
{
public static void main(String args[])
{
int price = 100;
double price2 = 100.00;
tenPercentOff(price);
tenPercentOff(price2);
}
public static void tenPercentOff(int p)
{
double newPrice = price * .90;
System.out.println("Ten percent off";
System.out.println("New price is " + nwPrice);
}
public static void tenPercntOff(double price)
{
double price = p * .90;
System.out.println("Ten percent off");
System.out.println("New price is " + newPrice);
}
}
// DebugFive1
// Adds your lunch bill
// Burger and hot dog are $2.59
// Grilled cheese and fish are $1.99
// Fries are 89 cents
import javax.swing.*;
public class DebugFive1
{
public static void main(String args[]) throws Exception
{
String usersChoiceString;
int usersChoice;
double bill;
usersChoiceString = JOptionPane.showInputDialog(null,
"Order please\n1 - Burger\n2 - Hotdog" +
"\n3 - Grilled cheese\n4 - Fish sandwich");
usersChoice= Integer.parseInt(usersChoiceString);
if(usersChoice = 1 || 2)
bill +=2.59;
else
bill += 1.99;
usersChoiceString = JOptionPane.showInputDialog(null,
"Fries with that?\n1 - Yes\n2 - No);
usersChoice = usersChoiceString;
if (usersChoice = 1)
bill+=.89;
JOptionPane.showMessageDialog(null,"Bill is " + bill);
System.exit();
}
}
// DebugFive1
// Adds your lunch bill
// Burger and hot dog are $2.59
// Grilled cheese and fish are $1.99
// Fries are 89 cents
import javax.swing.JOptionPane;
public class FixDebugFive1
{
public static void main(String args[])
{
String usersChoiceString;
double burger = 2.99;
double hotdog = 2.99;
double grilledcheese = 1.99;
double fish = 1.99;
double fries = .89;
double usersChoice;
double bill =
usersChoiceString = JOptionPane.showInputDialog(null,
"Order please\n1 - Burger\n2 - Hotdog" +
"\n3 - Grilled cheese\n4 - Fish sandwich");
usersChoice = Double.parseDouble(usersChoiceString);
if(usersChoice == 1 && usersChoice == 2)
JOptionPane.showMessageDialog(null, bill += 2.59);
else
JOptionPane.showMessageDialog(null, bill += 1.99);
usersChoiceString = JOptionPane.showInputDialog(null,
"Fries with that? \n1 - Yes \n2 - No");
if (usersChoice == 1)
JOptionPane.showMessageDialog(null, bill += .89);
JOptionPane.showMessageDialog(null,"Bill is " + bill);
System.exit(0);
}
}
// DebugFive2.java
// Prints odd numbers
// Prints new line after every 10
public class DebugFive2
{
public static void main(String args[])
{
int num, count;
for(num = 1; num <= 100; num++)
{
System.out.print(" " + num);
++count;
if(count = 10)
{
count = 10;
System.out.println();
}
}
System.out.println(End of odd numbers");
}
}
// DebugFive2.java
// Prints odd numbers
// Prints new line after every 10
public class DebugFive2
{
public static void main(String args[])
{
int num;
int count;
for(num = 1; num <= 100; num++)
if(num == 10)
{
num = 10;
System.out.println("The odd numbers are" + num);
}
}
}
// DebugFive3.java
// Determines whether item number on order is valid
// Over 999 invalid
// Less than 111 Invalid
// Valid and less than 500 - Automotive Department
// Valid and 500 or higher Housewares Department
import javax.swing.*;
public class DebugFive3
{
public static void main (String args[])
{
int item;
String itemString, output;
itemSting = JOptionPane.showInputDialog(null,
"Please enter item number
item = Integer.parseInt(itemString);
if(item < 111)
output = "Item number too low";
else
output = "Item number too high";
else
if(item < 500)
output = "Valid - in Automotive Department";
else
output = "Valid - Item in Housewares Department";
JOptionPane.showMessageDialog(output);
System.exit(0);
}
}
// DebugFive3.java
// Determines whether item number on order is valid
// Over 999 invalid
// Less than 111 Invalid
// Valid and less than 500 - Automotive Department
// Valid and 500 or higher Housewares Department
import javax.swing.JOptionPane;
public class DebugFive3
{
public static void main (String[] args)
{
String itemString, output;
int item;
itemString = JOptionPane.showInputDialog(null,
"Please enter item number");
item = Integer.parseInt(itemString);
if(item < 111)
item = JOptionPane.showMessageDialog(null, "Item number too low");
else
output = JOptionPane.showMessageDialog(null, "Valid - in Automotive Department");
if(item > 500)
output = JOptionPane.showMessageDialog(null, "Item number too high");
else
output = "Valid - Item in Housewares Department";
System.exit(0);
}
}
// DebugFive3.java
// Determines whether item number on order is valid
// Over 999 invalid
// Less than 111 Invalid
// Valid and less than 500 - Automotive Department
// Valid and 500 or higher Housewares Department
import javax.swing.JOptionPane;
public class DebugFive3
{
public static void main (String[] args)
{
String itemString, output;
int item;
itemString = JOptionPane.showInputDialog(null,
"Please enter item number");
item = Integer.parseInt(itemString);
if(item < 111)
JOptionPane.showMessageDialog(null, "Item number too low");
else
JOptionPane.showMessageDialog(null, "Valid - in Automotive Department");
if(item > 500)
JOptionPane.showMessageDialog(null, "Item number too high");
else
output = "Valid - Item in Housewares Department";
System.exit(0);
}
}
// DebugFive2.java
// Prints odd numbers
// Prints new line after every 10
public class DebugFive2
{
public static void main(String args[])
{
int num, count;
{
for(num = 1; num <= 100; ++num)
System.out.print(" " + num);
}
if(num == 10)
{
count = 10;
System.out.println();
System.out.println("End of odd numbers");
}
}
}
// DebugFive4.java
// Outputs highest of four numbers
import javax.swing.*;
public class DebugFive4
{
public static void main (String args[])
{
int one, two, three, four;
String str;
str = JOptionPane.showInputDialog(null,"Enter an integer");
one = Integer.parseInt(str);
str = JOptionPane.showInptDialog(null,"Enter an integer");
two = Integer.parseInt(str);
str = JOptionPne.showInputDialog(null,"Enter an integer");
three = Ineger.parseInt(str);
str = JOptionPane.showInputDialog(null,"Enter an integer");
four = Integer.parseInt(str);
if(one > two || one > three || one > four)
output = "Highest is " + one;
else
if(two > one || two > three || two > four)
output = "Highest is " + two;
else
if(three > one || three > two || three > four)
output = Highest is " + three;
else
output = "Highest is + four;
JOptionPane.showMessageDialog(null, output);
System.exit(0);
}
}
// DebugFive4.java
// Outputs highest of four numbers
import javax.swing.*;
public class DebugFive4
{
public static void main (String args[])
{
int one, two, three, four;
String str, output;
str = JOptionPane.showInputDialog(null,"Enter an integer");
one = Integer.parseInt(str);
str = JOptionPane.showInputDialog(null,"Enter an integer");
two = Integer.parseInt(str);
str = JOptionPane.showInputDialog(null,"Enter an integer");
three = Integer.parseInt(str);
str = JOptionPane.showInputDialog(null,"Enter an integer");
four = Integer.parseInt(str);
if(one > two || one > three || one > four)
output = "Highest is " + one;
else
if(two > one || two > three || two > four)
output = "Highest is " + two;
else
if(three > one || three > two || three > four)
output = "Highest is " + three;
else
output = "Highest is " + four;
JOptionPane.showMessageDialog(null, output);
System.exit(0);
}
}
// DebugFive4.java
// Outputs highest of four numbers
import javax.swing.*;
public class DebugFive4
{
public static void main (String args[])
{
int one, two, three, four;
String str, output;
str = JOptionPane.showInputDialog(null,"Enter an integer");
one = Integer.parseInt(str);
str = JOptionPane.showInputDialog(null,"Enter an integer");
two = Integer.parseInt(str);
str = JOptionPane.showInputDialog(null,"Enter an integer");
three = Integer.parseInt(str);
str = JOptionPane.showInputDialog(null,"Enter an integer");
four = Integer.parseInt(str);
if(one > two || one > three || one > four)
output = "Highest is " + one;
else
if(two < one || two > three || two > four)
output = "Highest is " + two;
else
if(three < one || three < two || three > four)
output = "Highest is " + three;
else
output = "Highest is " + four;
JOptionPane.showMessageDialog(null, output);
System.exit(0);
}
}
I looked this over some more and noticed the userChoiceString isnt outputting the 1 and 2 = 2.99 part. How do you fix this?Bill was initialized as a double and a String based on user input, so I assigned it to 0;
Something to note (my own practices):
Other than that just try to keep the if statements better organized or they can get out of hand. I use a lot of "{"s when I use ifs and only recently started using single line commands after the requirements of the if are fulfilled.
It's just easier, cleaner, and someone working with you can clearly see what is supposed to be within the if statement.
EDIT: Could just be the code tag on the boards making it look that way though.
Code:// DebugFive1 // Adds your lunch bill // Burger and hot dog are $2.59 // Grilled cheese and fish are $1.99 // Fries are 89 cents import javax.swing.JOptionPane; public class FixDebugFive1 { public static void main(String args[]) { String usersChoiceString; double burger = 2.99; double hotdog = 2.99; double grilledcheese = 1.99; double fish = 1.99; double fries = .89; double usersChoice; double bill = 0; usersChoiceString = JOptionPane.showInputDialog(null, "Order please\n1 - Burger\n2 - Hotdog" + "\n3 - Grilled cheese\n4 - Fish sandwich"); usersChoice = Double.parseDouble(usersChoiceString); if(usersChoice == 1 && usersChoice == 2) JOptionPane.showMessageDialog(null, bill += 2.59); else JOptionPane.showMessageDialog(null, bill += 1.99); usersChoiceString = JOptionPane.showInputDialog(null, "Fries with that? \n1 - Yes \n2 - No"); if (usersChoice == 1) JOptionPane.showMessageDialog(null, bill += .89); JOptionPane.showMessageDialog(null,"Bill is " + bill); System.exit(0); } }
// FixDebugFive1.java
// Jason Sodano
// October 30th, 2010
import javax.swing.JOptionPane;
public class FixDebugFive1
{
public static void main(String args[])
{
String usersChoiceString;
double burger = 2.59;
double hotdog = 2.59;
double grilledcheese = 1.99;
double fish = 1.99;
double fries = 0.89;
double usersChoice;
double bill = 0;
//Asks user for main order
usersChoiceString = JOptionPane.showInputDialog(null,
"Order please" + "\n1 - Burger " +
"\n2 - Hotdog " + "\n3 - Grilled cheese "
+ "\n4 - Fish sandwich ");
usersChoice= Integer.parseInt(usersChoiceString);
// Burger and hot dog are $2.59
if(usersChoice == 1 || usersChoice == 2)
JOptionPane.showMessageDialog(null, bill += 2.59);
// Grilled cheese and fish are $1.99
else
JOptionPane.showMessageDialog(null, bill += 1.99);
// Asks user for fries
usersChoiceString = JOptionPane.showInputDialog(null,
"Fries with that? \n1 - Yes \n2 - No");
usersChoice= Integer.parseInt(usersChoiceString);
// Fries are 89 cents
if (usersChoice == 1)
JOptionPane.showMessageDialog(null, bill += 0.89);
// Adds your lunch bill
JOptionPane.showMessageDialog(null,"Bill is " + bill);
System.exit(0);
}
}
i dont even think changing it from dooble to int mattered.Just like you did before with the double
usersChoice = Double.parseDouble(usersChoiceString);
only with an integer
userChoice = Integer.parseInt(userChoiceString);
I'm not sure if that is how it you parse an int in Java or not, looks right though.
// FixDebugFive4.java
// Jason Sodano
// October 30th, 2010
import javax.swing.*;
public class FixDebugFive4
{
public static void main (String args[])
{
int one, two, three, four;
String str, output;
// Inputs the numbers in order to determine the highest number.
str = JOptionPane.showInputDialog(null,"Enter an integer");
one = Integer.parseInt(str);
str = JOptionPane.showInputDialog(null,"Enter an integer");
two = Integer.parseInt(str);
str = JOptionPane.showInputDialog(null,"Enter an integer");
three = Integer.parseInt(str);
str = JOptionPane.showInputDialog(null,"Enter an integer");
four = Integer.parseInt(str);
// Determines which is the highest number.
if(one > two || one > three || one > four)
output = "Highest is " + one;
else if(two < one || two > three || two > four)
output = "Highest is " + two;
else if(three < one || three < two || three > four)
output = "Highest is " + three;
else
output = "Highest is " + four;
// Outputs highest of four numbers
JOptionPane.showMessageDialog(null, output);
System.exit(0);
}
}
// FixDebugFive4.java
// Jason Sodano
// October 30th, 2010
import javax.swing.*;
public class FixDebugFive4
{
public static void main (String args[])
{
int one, two, three, four;
String str, output;
// Inputs the numbers in order to determine the highest number.
str = JOptionPane.showInputDialog(null,"Enter an integer");
one = Integer.parseInt(str);
str = JOptionPane.showInputDialog(null,"Enter an integer");
two = Integer.parseInt(str);
str = JOptionPane.showInputDialog(null,"Enter an integer");
three = Integer.parseInt(str);
str = JOptionPane.showInputDialog(null,"Enter an integer");
four = Integer.parseInt(str);
// Determines which is the highest number.
if(one < two)
output = "Highest is " + one;
else
output = "Highest is " + two;
if(!(three < four))
output = "Highest is " + three;
else
output = "Highest is " + four;
// Outputs highest of four numbers
JOptionPane.showMessageDialog(null, output);
System.exit(0);
}
}