I'm having a problem where an if statement isn't working. In the Person class boolean olderThan ignores my if statement so it always returns false and I just don't get why that's happening.
import java.util.Calendar;
public class Person {
private String name;
private MyDate birthday;
public Person(String name, int pp, int kk, int vv) {
this.name = name;
code=Java import java.util.Random; import java.util.Scanner; public final class Derp { public static int WIN, Tick; public static Scanner Input = new Scanner(System.in);
[code]...
why this boolean statement isn't working correctly. It's not detecting that the WIN and Tick are the same and instead chooses to always run the second statement.
I am building a program that when you enter 1. it allows you to setup an item. However running my code my second if statement runs through.
import java.util.Scanner; public class InventorySystem { public static void main(String [] args) { Scanner input = new Scanner(System.in); int count=0; int inputEntered=0; int numberOfItems=0; double cost=0.00; String item; String description;
My if else statement is not working...it keeps telling me that the else in the statement is a syntax error and that I should remove it. Whats wrong with it?
package Homework2; import java.util.Scanner; public class Homework2 { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Welcome to the Triangle Program.");
Alright so I'm trying to write a code that implements a for loop and if statements that displays any number from 100-200 if the number is divisible by either 5 or 6 in rows of ten numbers each row. If it is not divisible by that number then it should go back to the beginning of the loop until it reaches 200. My main problem is that it doesn't display anything. I don't get any errors or anything but every time I run the program it just displays nothing. Sample output is at the bottom of the code.
public class Exercise5_11 { public static void main(String[] args) { int count = 0; int i = 100; //for (the numbers from 100 to 200) for (i = 100; i>100 && i<200; i++){
So from what iv learnt in Java and programming in general is that using a case statement is far more efficient that using multiple IF statements. I have an multiple IF statements contained within a method of my program, and would like to instead use a case statement.
So I want to make a simple Java that ask the user to pick a powers and it has two options.If the user picks magic then execute the first if statement then ask the user again which type of magic the user wants.I can't make it work it keeps printing the else statement. Why is that?
import java.util.Scanner; public class Variable { static Scanner zcan = new Scanner(System.in); public static void main(String[] args)
I am developing an application to share my client screen with server, it is working well on swing. But i want to develop as web application, i am trying to using applet. But i am facing the fallowing problem..,
1) The Applet screen also open and project also running well on server mechine. But unable to see the client screen on the server.
2) The problem may be to display the JDesktopPane or JInternalFrame.
My working Server Code extends withe JFrame..Java Code:
I'm trying to run an if statement with an input condition and here is my code.
import java.util.Scanner; public class App10A { public static void main(String[] args) { Scanner fun = new Scanner(System.in); System.out.println("What's your name?"); String name = fun.nextLine();
[code]....
When the computer asked me "What's your name?", I typed in Victor, then the result turned out to be "Oops, try again!".I typed in Victor (without parenthesis) and "Victor" and both gave me the negative results.What exactly should I put in in order to get "This is the result I wanted!" ? how should I modify my code in order to get "This is the result I wanted!" when I put in Victor (without changing the equal sign)?
How do I use a variable in an if statement to return a public void method from another class? I've tried:
System.out.print("select 1 - 6: "); Scanner myScanner = new Scanner(System.in); myScanner.nextInt(); if (myScanner.nextInt()==1) { carSelection colour = new carSelection(); colour.carSelection();
The method colour in class car selection is just 4 print line statements? I've // out the if statement to see if it is correctly calling the method and displaying the data and it is?
In the program below I populated three arrays: student id, name, and GPA. The findStudent() method attempts to match users input with the input stored in the studentID array using an if/ else statement. When I use the if/ else statement the else always executes regardless if the IDs match? I am trying to get JOptionPane.showMessageDialog(null, "Incorrect entry"); to print only if the IDs don't match.
Java Code:
//FILE: StudentIDArray.java import javax.swing.*; //Used for the JOption dialog boxes import java.util.*; //Used for Scanner input public class StudentIDArray { boolean nameFound = true; final int numOfElements = 2; //Final int to control to loop for data
My program basically has 2 executeQuery statements. Based on the result of the first sql query the 2nd sql query gets executed (I intend to use if else ladder). The control executes the first query but never executes the second one.
I have this JAVA written but I can't get the parameters for the if statements right.
import java.util.Scanner; public class myFirstJAVA { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Please enter command: "); String text = input.nextLine();
I am making a simple calculator. I want the user to input either string "add" or "subtract" and then it will take two numbers and either add or subtract them. I cannot get the if statement to work with a string!
import java.util.Scanner; public class newcalc { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter add or subtract");
I'm trying to make a test on java. So far I'm on Question 1 and I'm having this issue. The if else statement won't allow me to add to the score.
class ExamEngine { static CinReader Cin= new CinReader(); static int Score=0; public static void main(String[] args) { System.out.println("Type in your name."); String name=Cin.readString();
[Code] ....
If I remove the "Score++;" bit, everything is fine. But I need to add to the score when they answer a question right. However, with "Score++;" there, I get this issue: 'else' without 'if'.
Note that this cannot be multiple choice, so that's why I'm using if-else, because I don't think a case system would work here.
Is there a way I can make this work while adding to the score?
I've done a basic login GUI for a application, a user enters their name and address and clicks register, a four digit pin is then randomly generated, the pin and name and address are all added to an object of the MemberDetails class , this obj is then added to an array list.
returning customers can then enter a previously generated pin and either get a welcome back message or an invalid pin message.
my issue if i register two new users and get their generated pins, that on the returning members screen it will only show the welcome message for the second new customer i created and not recognizing the first customers pin. heres my code:
taking in new customer details, generating pin , adding obj to arraylist
int randomPIN = (int) (Math.random() * 9000) + 1000; members = new MemberDetails(); members.name = nameNew.getText(); members.address = addressNew.getText(); members.pin = randomPIN;
[Code] ....
that lest method is a bit of a mess i know, i was going to store the log in attempts in a array but thats probly not a good tactic, and that inner for loop is probly unnecessary ?
I have two different Class object arrays storing 3 elements (2 Store arrays, both initialised to hold 3 Product objects). The problem is, I can set data to one array with no problem but my program doesn't want to set the data for my second array.
For instance, The main problem is this method:
public void addData(String store, String newName, int newDemand, double newSetup, double newUnit, double newInventory, double newPrice) //Method that sets the data value for a product { if (store.equalsIgnoreCase("callaghan"))//!!!!Goes from this line in the debugger if (noOfProductsCallaghan==0) { setData(product[0], newName, newDemand, newSetup, newUnit, newInventory, newPrice); noOfProductsCallaghan++; } else if (noOfProductsCallaghan==1)
I am trying to get the program to ask the user to enter the project grade and if it is less than 65, then I want the program to display "fail" or if it is greater than 64 than I want it to display "passed". In this project I have to include a method and I am trying to call it in my if-else statement. I keep getting an error message saying "Project.java:143: error: incompatible types: void cannot be converted to int". I posted my code below. It's a long program, but this part is toward the bottom.
import java.util.Scanner; public class Project { public static void main(String[] args) { //call method welcomeMessage();
/** * This method displays all winner names for a given year. * @param year is the integer parameter asked of the user. */ public void displayAllWinnersForYear (int year) { if (year >= 1993 || year <= 2009) { String[] winnersForTheYear = nobelPrizeWinners.get(year); for (int i = 0; i < winnersForTheYear.length; i++) {
[Code] ....
When year is outside the 1993-2009 range, I get a NullPointerException from line 10. Shouldn't it be skipped entirely since the conditions of its parent IF statement (line 7) is not met?
I am having trouble doing a simple exercise changing a for loop to a while statement, it works fine in the for loop but in the while statement it just prints out 10(it is supposed to count to 0 and print liftoff).
public void run() { int i = 10; while (i>=1) { println(+i+"..."); i--; } println("liftoff..."); }
It has been about 2 years that I'm programming in JAVA and never has this occurred to me about the reason why this happens. So, in this code snippet
public class Test { public static void main(String[] args) { char m = 'A'; int p = 15; System.out.println(m+p); System.out.println("Answer :"+m+p); } }
The statement "System.out.println(m+p);" returns "80" which is evident that the type of the entire expression is promoted to the value of the largest data type int. But in the statement " System.out.println("Answer :"+m+p);, why does the output change to "Answer :A15" but not "Answer :80"?
Implement a Las Vegas slot machine! The machine works as follows. First, it generates three random integers (use import java.lang.Math.*; then call Math.random()*7 to generate a random number between [a,b)) that are in the range of 0-7. Once the numbers are generated, the following rules are used to determine the prize:
- If all three numbers are equal to 7, you are winning $1,000, - If all three numbers are equal, but not equal to 7, you are winning $500, - If two of the numbers are equal to 7 and the third one is six, you are winning $400, - If two numbers are equal, you are winning $100, - Otherwise you are not winning anything.
And for that I wrote:
import java.lang.Math;
public class Assn1_2150130 { public static void main(String[] args) { // Generate three random signle-digit integar from 0-7. int n1 = (int)(Math.random()*7); int n2 = (int)(Math.random()*7); int n3 = (int)(Math.random()*7);
[code]...
But I just can't figure out a way to print out the "YOU WON NOTHING." independently.If I say that n1!=n2 && n2!=n3 && n3!=n1, and then write another line of println. It gives out the number as well as the "NOTHING".
Often times i don't remember which package a specific class (like ArrayList) belongs to. Is there an easy way to find that java.util.* is what i need to import, if i wanted to use the class ArrayList ?