I'm trying to fix this logic error in my slot machine game where no matter what slot combo comes up, it says you have won $10 and proceeds to add that amount to the balance and subtract the bet amount to the balance, even though it is not a winning combo! I've been trying to solve that and when doing so, I commented out Slot1.randNum1 == 0, Slot2.randNum2 ==0, and Slot3.randNum3 ==0 and anything relating to see if that was the problem, and it seemed like it was, because after that, the logic error described above was gone, but in doing so, the loss/win counter didn't increment, nor did the program pick up on the winning combos. However, I do not know why commenting out anything relating to randNum ==0 would cause that.
Here is the code for the processing (as you can see, some parts are commented in attempt to fix the logic error, but right now the code below is for the logic error that keeps on telling that the user has won):
public void askData () { title (); int betAmount; while (true) { try { c.setCursor (3, 1);
My code runs and populates an arraylist. However my break statement, while stopping the loop ends up being added to the arraylist. And I'm not sure how to fix this error.
public static void main(String args[]) throws Exception { // declaring variables String input = ""; // creating array list ArrayList<String> nameList = new ArrayList<String>();
I was tasked with creating a program that encrypts a line of text (for example, CANDY) by shifting the letters X amount of times. For example, if the user inputs the sentence CANDY and selects a shift of 5, the output would be: HFSID. I got this part working fine. The issue I am having is with the decryption part of the program.
This is simply the reverse of the above, as the user would enter the phrase HFSID, with a shift of 5, and the program would output: CANDY. It works fine, all except for one letter, being the "F" letter. With my code, when I enter the above word to be decrypted it outputs: C[NDY
Obviously, that [ bracket is not an 'A'. I realise the issue falls with the equation, Here is my code:
public class SimpleEncryption {
/** * @param args the command line arguments */ static int answer; public static void main(String[] args) { String cipher = JOptionPane.showInputDialog(null, "Please enter a sentence or word that you wish to encode or decode. This program uses" + " a basic cipher shift.");
import javax.swing.JOptionPane; public class Calculator { public static void main ( String args[] ) { double n1 = Double.parseDouble(JOptionPane.showInputDialog(" Enter first number: ")); double n2 = Double.parseDouble(JOptionPane.showInputDialog(" Enter second number: ")); String x = JOptionPane.showInputDialog("Enter operator: "); double result;
[code].....
Write a program that mimics a calculator. The program will need to accept as input two numeric double values, and accept the operation to be performed as the third input. The operation to be performed will be input in the form of the character representing the java operator for the operation to be performed (i.e + for addition, - for subtraction, * for multiplication, / for division, or % for modulus). Once the program has read these 3 inputs it should output the numbers, the operator, and the result. (For division, if the denominator is zero, the program will output an appropriate message (i.e division by zero is an invalid operation). Please use the JOptionPane class for both accepting the required inputs and for the required output demonstrated below.Some sample output may look as follows:
I've been learning about Swing and I'm working on a Grade Average Calculator, but the problem is after the user types in the the grades, the average is supposed to appear, but for some reason in my code, nothing appears, I can only type in the grades. Here's my code so far :
How do I make it so I am able to enter any number rather then just the numbers in the arrays? I want it to be able to find the position of any number between 0-100.
import javax.swing.*; public class BinarySearch { public static void main(String[] args) { int array[] = new int[11]; array[0] = 10; array[1] = 20; array[2] = 30; array[3] = 40; array[4] = 50; array[5] = 60;
I am trying to build an expression tree program . I try to print it then I have java.nullpointer exception . Is it error in my code or what ?
I have 2 classes
one is BSTreeNode which is the nodes for the tree . It has
public class ExpressionTree { public BSTreeNode root; public BSTreeNode curr = root; ExpressionTree() { root = new BSTreeNode(null, null, null, null); curr = root;
[Code] ....
My BSTreeNode
public class BSTreeNode { BSTreeNode parent; Object element; // Binary search tree element BSTreeNode left; // Reference to the left child BSTreeNode right; // Reference to the right child // Constructor BSTreeNode (Object elem) [Code] ....
The error i am getting is
Exception in thread "main" java.lang.NullPointerException at binaryexpressiontree.ExpressionTree.insert(ExpressionTree.java:38) at binaryexpressiontree.test.main(test.java:22)
Java Result: 1
After implementing exception handler what i am getting is
java.lang.NullPointerException root 1 * root 2 1 error error error//these error print because of my catch clause
The program i am working on is to take string from the user which should be a phone number then it will return true or false based upon the method that checks to see if it meets the criteria of a certain format if does not it will return false otherwise return true. I am working on a if/else structure that will print this number is valid if it meets the criteria of the method i previously mentioned or return the number is not valid if it is false. the logic of the expression i put in the parentheses of the if/else statement. This is what i have so far:
if(){ System.out.println("The phone number is valid"); } else { System.out.println("This isn't a valid phone number"); }
Do i need to compare it based upon the method that checks if it is true?
I've decided to go back to basics and start using pseudocode--but i want to see if my logic is correct.so here's the first program:each delegate to a certain conference must wear a tag showing their name and the organization they represent as shown below:
######################
#### Annual Conference #####
######################
##NAME: ##
######################
##ORGANIZATION: ##
######################
write a class called TagMaker that prints out tags. supply methods to (a) set the name (b) set the organization (c) print tag with the name and organization (d) clear the name and organization (e) print a blank tag. then write a TagTester class to test the TagMaker class. so this is the pseudo code (or logic) that i've come up with for the program:
TagMaker main class:
-Prompt user to enter in first and last name, as well as their organization.
-Read user input for the name and organization.
-Return user input.
-Write conference tag showing the person's information.
-Clear information.
-Print blank tag.
1. i assume i would have to import a few java libraries.
Java Code: java.util.Scanner mh_sh_highlight_all('java'); and Java Code: java.io.*; mh_sh_highlight_all('java');
2. afterwards i would declare the instance variables (private, i assume). static too? so for example: Java Code: private static string firstName mh_sh_highlight_all('java');
3. i'm not sure if this program requires a constructor...being that i'm supposed to clear the program at the end anyway.
4. i create a public class declaring my input variable. example: Java Code: String first = firstName.nextLine(); mh_sh_highlight_all('java');
5. so i then i have to create methods that get/set the user input.
getter/setter example:
Java Code:
public String getFirst(){ return first; } public void setFirst(){ this.first = new first; } mh_sh_highlight_all('java');
6. to print out both tags, would i write most of the code as part of a loop and make an "if" statement where the user input is valid, it prints out a tag with information, and another "if" statement that would automatically clear the buffer?
7. last i would create a tester class that would primarily be responsible for the program's output.
if (number % 2 == 0 && number % 3 == 0) System.out.println(number + " is divisible by 2 and 3");
if (number % 2 == 0 || number % 3 == 0) System.out.println(number+ " is divisible by 2 or 3");
if (number % 2 == 0 ^ number % 3 == 0) System.out.println(number + " is divisble by 2 or 3 but not both");
I understand the logic operators and the variable number, what i dont understand is what number % 2 == 0 and number % number == 0 mean. I know that % is a remaining operator and == means equals, i know that = and == are not the same.
I want to run a few things in my main when a JButton is pressed but can't work out the best way to do it. Here's the code in the main.
public static void main(String[] args) throws FileNotFoundException, ParseException, InterruptedException{ Map m = new Map("defaultMap"); GameLogic g = new GameLogic("defaultMap"); GodsEyeView gev = new GodsEyeView(g, m); gev.initialRun();
//Want to run this when a button is pressed. HumanUser h = new HumanUser(g); playerGUI gui = new playerGUI(h); gui.run(); gev.run(); }
I need to find the Winner using Object Orientation logic I have my old logic from my Tic Tac Toe game but it is not Object Orientated. So I want to convert it and add that code to my GUI Tic Tac Toe. I need to return a winner or tie.
I am going to develop a new web application of medium complexity. Right now i am somewhat comfortable with JSF and hibernate. I have never used JSF and hibernate together before.I just wanted to ask if it is good practice to use JSF (for both view layer and handling business logic) and hibernate(for persistence) without spring as a middle layer. The reason why i am asking this is i don't know anything about spring framework.
I'm having trouble with sorting Strings- 3 strings inputted by user, and I would like to output them in alphabetical order. I've used the str.compareToIgnoreCase method, and then I've tried to loop them through a series of if/ else statements. Everything I've been able to find online (including the forums here) has suggested to use the Comparator class, or to put the strings into an array, and sort list- I really would like to stick with just the String class, and its methods .
The program itself works and compiles, but I am getting logic errors that I have been unable to solve. I'm using IntelliJ Idea, and I've ran it through the built in debugger, about 100+ times (not exaggerating, lol) just to see what it's doing in particular scenarios. For instance, I can get c, a, b, to print out as a,b,c correctly, but a,b,c, will print out as b,a,c.
For me this is kind of like a Sudoku puzzle, or a Rubik's cube! Each time I fix one scenario, it breaks another one, so I don't know if there's a(logic) solution to fix all possible scenarios (abc, acb, bac etc... to all print abc) or if possibly I just need more if statements. I've only pasted in the area where I'm having problems (the if statements). I'm a big fan of the "Next Line" syntax.
(Note: please assume the non relevant content- import Scanner class, main method, etc... I didn't want to paste the entire program.)
System.out.println("Enter the first statement: "); //input.nextLine(); string1 = input.nextLine(); System.out.println("Enter the second statement: "); string2 = input.nextLine(); System.out.println("Enter the third statement: "); string3 = input.nextLine();
So, I'm working on a Tip Calculator for fun. I have everything worked out for the most part. The feature I am trying to add is to give the user the amount of change they'll get back from their transaction. I do not ask the user any information other than what is their bill.
Please enter your bill total : 5.50 Please enter your name : some name Total : 5.50 Tax : 0.48 -- Based off a tax rate of 8.75% Total with Tax : 5.98 -- 20 percent Tip : 1.10 Total with Tax and 20 percent Tip : 7.08 Total change : <-- I believe this will be about $2.92
I want the total bill to round to the nearest $10 value (e.g. for $5.50, calculate bill to $10. For $13.00, calculate bill to the $20.00, and so on... This way I get an accurate amount of change to give back to the user.
I made a MVC calculator. I was wondering if you could take a look at my design and if I was on track. I am still working on getting it to actually calculate something. All the buttons respond and print text on the JTextField but it is not calculating.
package calculator.MVC; import javax.swing.JButton; import javax.swing.JTextField; public class CalculatorModel { private int sum; private int number; private char opt;
I am making a calculator in Java. However, when I press the "=" button on my calculator, it always returns 0.0, no matter what. I don't understand why? The code is below:
import javax.swing.*;//import the packages needed for gui import java.awt.*; import java.awt.event.*; import java.util.Arrays; import java.util.List; import static java.lang.Math.*; public class CalculatorCopy {
import javax.swing.*; public class BasicCalculator{ public static void main (String[] args) { String output=""; double n1,n2; String operation; operation= JOptionPane.showInputDialog("Please enter your operation");