How To Add Multiple OR Choices In If Statement

Jan 21, 2015

I have this very code:

if (minute > 35 && hosts < 1 && guests < 1)

In this if statement I would also like to add another two possibilities:

first would be: hosts < 1 && guests < 2
second would be: hosts < 2 && guests < 1

Is it possible to somehow add it so it can all be in included in one if statement, and it would look something like that:

if (minute > 35 && hosts < 1 && guests < 1 OR
minute > 35 && hosts < 2 && guests < 1 OR
minute > 35 && hosts < 1 && guests < 2) {}
.. ?

View Replies


ADVERTISEMENT

Using Multiple Selection Choices?

May 28, 2014

This program allows the user to select one of each different type of skateboard/accessories items. Then it allows the user to select as many misc items as he or she chooses. The program works fine for the single choices, but I cannot solve the latter part. I have a get method in the misc class that is trying to pull out any selection or selections that were made by the user, but it simply does nothing...

Here's my program, I have four panel classes for each skateboard type, and then I have one class that takes care of adding each panel to the content pane, and calculating the total cost of the item.

Decks Panel Class:

import java.awt.event.*;
import javax.swing.*;
// The DecksPanel class allows the user to selects a specific type of skateboard
public class DecksPanel extends JPanel

[Code]....

View Replies View Related

How To Create Multiple Choices In One Panel

Jan 20, 2014

How to create multiple Choices in one Panel? I need to create a program that will choose a number in these choices then it will display the words at the bottom.

E.g. "Two Thousand Fourteen"
"Three Thousand"
"Two Thousand"

Thanks1.JPG

View Replies View Related

Inserting Else Statement And Multiple Brackets At Various Places

Jan 16, 2014

I'm using this try statement to check for errors in input in my Tic Tac Toe game. The problem I have having is I don't understand why this error is happening. It's preventing my code from compiling. I've tried inserting an else statement and multiple brackets at various places with no success.

Java Code:
public void play(){
Scanner input = new Scanner(System.in);
int row, col;
char currPlayer = 'X';

[code]....

View Replies View Related

Java Statement Getting Executed Multiple Times Outside For / While Loop

Aug 14, 2014

I am trying to execute the following method: This method takes a delivery date as one of the arguments and a list of calendar holidays as another argument. If the delivery date is present in the holiday list, I will add 1 day more to the delivery date and check again if the new delivery date is part of holiday list.

Issue is that the last 3 statements before 'return' are getting executed multiple times though there is no for or while loop. Why they are getting invoked multiple times.

@SuppressWarnings("rawtypes")
private String fetchNextWorkingDay(String sDeliveryDate, Element eleCalendarDayExceptions, SimpleDateFormat sdf, Format formatter) throws Exception {
System.out.println("");
System.out.println("Inside fetchNextWorkingDay method");
System.out.println("Del Date to compare is "+sDeliveryDate);
Boolean isDateSet = true;

[Code] .....

View Replies View Related

Why Program Does Not Display Anything When Choices Are Inputted

Feb 28, 2014

I am experimenting with messages in JOptionPane and I was wondering why this program does not display anything when the choices are inputted.

*note: I tried putting "JOptionPane.showMessageDialog(null, "This is an information message", "Information", JOptionPane.INFORMATION_MESSAGE);" after the "int i = 0;" and then the messages displayed.

Scanner scan = new Scanner(System.in);
int i = 0;
while (i != 6)
{
System.out.println("1. Information message");
System.out.println("2. Error message");
System.out.println("3. Question message");
System.out.println("4. Plain message");
System.out.println("5. Warning message");

[code]....

View Replies View Related

JComboBox - Different Choices Depending On Selection Made

Oct 5, 2010

I am stuck trying to build a relatively "simple" GUI. The GUI should have one JComboBox that allows the user to pick from one of three locations. Then based on their choice, another JComboBox should be generated with another set of choices. The key is that the second ComboBox should have different choices depending on the selection made in the first one. So, in theory, the logic should be something like:

//create new JComboBox array of strings "locations"
//create new JComboBox array of strings "costToTravelThere"
//if user picks location 1 from the first ComboBox
then add the second ComboBox with options specific to that first location
else if user picks location 2 from first ComboBox
then add the second ComboBox with options specific to that second locatoin

I understand how to do the basic stuff, like create the JFrame and the actual panels and ComboBoxes, etc. What I don't understand is how to implement the second ComboBox dependent on the first one. I'm not very experience with Listeners and such, and I'm sure that's a big part of this.

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

JSF :: Multiple Tool Tips To Be Displayed On Same Page When Click Multiple Image Links

Dec 8, 2014

I have i am trying to implement tooltip through javascript, like when we click on an image link tooltip should be displayed and it should have close button/ close image to close that tooltip.like the same way i will have multiple images on page, when ever i click on the images all tooltips should be displayed on the page when ever i want to close that then only it should close through close button on tooltip.can we do it through java script or will go for jquery.

View Replies View Related

How To Draw Multiple Graphics Inside One JPanel Using Multiple Classes

May 5, 2015

I'm very new to Java, and I am creating a program that takes multiple user input to create one face. I have a class for the eyes, nose, lips, and headshape. For some reason, my program is not drawing the graphics. ***for question purposes, I have only included my head shape class and my test class****

my "test" class:

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class FaceTest
{
public static void main(String[] args)
{
String head = JOptionPane.showInputDialog("Would you like a circle, square, rectangle shaped head?: ");

[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

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 View Related

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

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







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