Skipping Else If Statement

Jun 5, 2014

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)

[code]...

View Replies


ADVERTISEMENT

IF Statement Skipping To Else

Aug 1, 2014

I'm very new to java programming / programming in general and I'm having an issue.

When I execute this part of my code it does this.

Quote

Has this car been in an accident? (Y/N): Please enter Y/N

View Replies View Related

Skipping While Loop After First Run

Dec 11, 2014

I need to add a kb.nextLine(); somewhere but I've tried adding it after nextInts and it hasn't worked. The problem is in the test.

public class Account{

//instance variables
private static double annualInterestRate;//this is the class variable
private int id;
private double balance;
private java.util.Date dateCreated; //creates an object from the date class in java

[code]....

View Replies View Related

Skipping Further Prompts When Certain Conditions Are Met

May 1, 2014

Is there any way to skip the 2nd and 3rd questions in this instance if I input "exit" or make an error in the 1st input. Essentially skip over the "enter 1st number / enter second number" prompts and go straight to the switch statement? In the case of "exit" exit the program immediately without the prompts. If an error, loop around to the beginning without the further prompts.

import java.util.Scanenr;
public class Meddle {
public static void main (String args []) {
double n1,n2,answer;
Boolean check = true;

[code]...

View Replies View Related

Skipping Lines During Debugging

Dec 19, 2008

I'm working or better say.. I'm trying to work :) with Maven projects (m2eclipse plug-in) and Eclipse IDE. The problem I have is that sometimes the debugger seems to skip some lines of the code without a reason.

Is there an issue of synchronisation with my .class files?

View Replies View Related

Program Skipping Over User Input

May 19, 2014

So i'm just toying around with making a simple inventory system, and when i'm trying to get the user's input (first the ID number, then the item name, then the item price) it will take the ID number, output asking for the name (but not take any input for it) and then ask for the item's price. I'm really not sure why it's never happened to me before when getting user input.

This is the input part of my code:

public void getInfoAdd() {
int id;
String name;
double price;
System.out.print("Enter ID: ");
id = sc.nextInt();
System.out.print("Enter item name:");
name = sc.nextLine();
System.out.print("Enter desired price: ");
price = sc.nextInt();
addItem(id, name, price);
}

And this is what it outputs:

Quote
Enter ID: 2
Enter item name:Enter desired price: 40
Successfully added: 2 $40.0

View Replies View Related

Line Skipping And Not Allowing To Put Values In

Apr 21, 2014

I been working on this code for hours and for some reaon, a system.out.println skips and wont let me put values in. I dont know what is wrong.

Code :

import java.util.Scanner;
public class Alcaraz_Program2a
{
public static void main (String [] args)
{
byte tons;
short pounds;

[Code] ....

View Replies View Related

How To Turn If Statement Into A Case / Switch Statement

Jun 19, 2014

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.

public String checkPasswordStrength(String passw) {
int strengthCount=0;
String strengthWord = "";
String[] partialRegexChecks = { ".*[a-z]+.*", // lower
".*[A-Z]+.*", // upper
".*[d]+.*", // digits
".*[@#$%!]+.*" // symbols

[code].....

View Replies View Related

Using Switch Statement Inside If Statement

Nov 18, 2014

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)

[code]....

View Replies View Related

How To Run If Statement

Apr 5, 2014

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)?

View Replies View Related

How To Use Variable In If Statement

Feb 17, 2014

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?

View Replies View Related

If Statement Not Working?

May 5, 2014

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].....

View Replies View Related

If / Else Statement With Arrays?

Jan 28, 2015

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

[code]....

View Replies View Related

For Loops With If Statement?

Nov 21, 2014

i'm confused about the if statement part because int i = 0 is set to zero but how can you get the remainder if int i is zero?

for (int i = 0; i < 200; i++) {
if (i % 12 == 0) {
System.out.println("#: " + i);
}

explain to why it output like this?

#: 0
#: 12
#: 24
#: 36
#: 48
#: 60
#: 72
#: 84
#: 96
#: 108
#: 120
#: 132
#: 144
#: 156
#: 168
#: 180
#: 192

View Replies View Related

SQL Statement Is Not Executed

Mar 20, 2014

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.

MY CODE:-

//package searchbook;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;

[code]....

View Replies View Related

Cannot Get Parameters For If Statement Right?

Mar 1, 2015

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();

[Code] ....

View Replies View Related

If Statement With Strings?

May 1, 2015

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");

String line = input.nextLine();

if input = "add";

View Replies View Related

If Else Statement Not Allow To Add To The Score

Mar 13, 2014

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?

View Replies View Related

GUI Log - IF Statement / For Loop

Nov 29, 2014

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 ?

View Replies View Related

Can Call A Method In If Else Statement?

Dec 6, 2014

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();
 
[Code] ....

View Replies View Related

NullPointerException Under IF Statement Which Should Be Skipped

Feb 10, 2015

/**
* 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?

View Replies View Related

Changing For Loop To While Statement?

Aug 23, 2014

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..."); 
 }

View Replies View Related

Output Statement In Java

Feb 1, 2015

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"?

View Replies View Related

How To Print A Different Statement In If Else Structure

Feb 6, 2015

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".

View Replies View Related

Boolean Statement Not Working

Apr 14, 2015

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.

View Replies View Related

Finding The Right Import Statement?

Feb 13, 2014

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 ?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved