Home Answers Viewqa Java-Beginners Eclipse (Problem with combining 2 codes together)(Cont)

 
 


Ben
Eclipse (Problem with combining 2 codes together)(Cont)
2 Answer(s)      2 years and 10 months ago
Posted in : Java Beginners

Hi, I have a problem with this code (below), I enter the username and password correctly then I want to input an integer either 1 or 2 but if I enter wrongly, e.g. 3, it will print out "Unsuccessfully login due to invalid username or password". How can I edit this code to make it print out "Invalid input" if I enter 3. Hope to receive help ASAP.
Thanks in advance :)

import java.util.Scanner;

public class Main {

static Scanner scan = new Scanner(System.in);

public static String username;
public static String input;
public static int userInput;


public static void main(String[] args) {

System.out.println("Enter your username and password in the following format (e.g. username, password [with the comma]):");
username = scan.nextLine();
if (username.equalsIgnoreCase("Norman Lim, a123") || (username.equalsIgnoreCase("Silvia Chong, b456") || (username.equalsIgnoreCase("Gordon Tan, c789")))){
System.out.println();
System.out.println("You have successfully login");
System.out.println();
System.out.println("Enter '1' to view movie listing by Hall and '2' by Time: ");
userInput = scan.nextInt();
}else
System.out.println();
System.out.println("Unsuccessfully login due to invalid username or password");
System.out.println();

if (userInput == 1){
System.out.println("====================================================================================");
System.out.println(" ~~~~~~~~~~~~~~~~~~~~~ Hall 1 ~~~~~~~~~~~~~~~~~~~~~");
System.out.println("Movid ID: 1 Title: Inception Time: 4pm Cost: $10.00");
System.out.println("Movie ID: 2 Title: Twelve Time: 6pm Cost: $9.00");
System.out.println("Movie ID: 3 Title: The Sorcerer's Apprentice Time: 8pm Cost: $9.00");
System.out.println();

// for movie showing in Hall 2
System.out.println(" ~~~~~~~~~~~~~~~~~~~~~ Hall 2 ~~~~~~~~~~~~~~~~~~~~~");
System.out.println("Movie ID: 4 Title: Toy Story 3 Time: 3pm Cost: $7.50");
System.out.println("Movie ID: 5 Title: Toy Story 3 Time: 5pm Cost: $7.50");
System.out.println("Movie ID: 6 Title: Twelve Time: 7pm Cost: $9.50");
System.out.println("Movie ID: 7 Title: Predator Time: 9pm Cost: $9.50");
System.out.println();

// for movie showing in Hall 3
System.out.println(" ~~~~~~~~~~~~~~~~~~~~~ Hall 3 ~~~~~~~~~~~~~~~~~~~~~");
System.out.println("Movie ID: 8 Title: Knight and Day Time: 3pm Cost: $7.50");
System.out.println("Movie ID: 9 Title: The Twilight Saga: Eclipse Time: 5pm Cost: $8.50");
System.out.println("Movie ID: 10 Title: The Twilight Saga: Eclipse Time: 7pm Cost: $10.50");
System.out.println("Movie ID: 11 Title: Predator Time: 9pm Cost: $9.50");
System.out.println("====================================================================================");
System.out.println();
}

else if (userInput ==2){
//for movie showing at 3pm
System.out.println("====================================================================================");
System.out.println(" ~~~~~~~~~~~~~~~ Movie showing at 3pm ~~~~~~~~~~~~~~~");
System.out.println("Hall 2: Movie ID: 4 Movie: Toy Story 3 Cost: $7.50");
System.out.println("Hall 3: Movie ID: 8 Movie: Knight and Day Cost: $7.50");
System.out.println();

//for movie showing at 4pm

System.out.println(" ~~~~~~~~~~~~~~~ Movie showing at 4pm ~~~~~~~~~~~~~~~");
System.out.println("Hall: 1 Movie ID: 1 Movie: Inception Cost: $10.00");
System.out.println();

//for movie showing at 5pm
System.out.println(" ~~~~~~~~~~~~~~~ Movie showing at 5pm ~~~~~~~~~~~~~~~");
System.out.println("Hall 2: Movie ID: 5 Movie: Toy Story 3 Cost: $7.50");
System.out.println("Hall 3: Movie ID: 9 Movie: The Twilight Saga: Eclipse Cost: $8.50");
System.out.println();

//for movie showing at 6pm
System.out.println(" ~~~~~~~~~~~~~~~ Movie showing at 6pm ~~~~~~~~~~~~~~~");
System.out.println("Hall 1: Movie ID: 2 Movie: Twelve Cost: $9.00");
System.out.println();

//for movie showing at 7pm
System.out.println(" ~~~~~~~~~~~~~~~ Movie showing at 7pm ~~~~~~~~~~~~~~~");
System.out.println("Hall 2: Movie ID: 6 Movie: Twelve Cost: $9.50");
System.out.println("Hall 3: Movie ID: 10 Movie: The Twilight Saga: Eclipse Cost: $10.50");
System.out.println();

//for movie showing at 8pm
System.out.println(" ~~~~~~~~~~~~~~~ Movie showing at 8pm ~~~~~~~~~~~~~~~");
System.out.println("Hall 1: Movie ID: 3 Movie: The Sorcerer's Apprentice Cost: $9.00");
System.out.println();

//for movie showing at 9pm
System.out.println(" ~~~~~~~~~~~~~~~ Movie showing at 9pm ~~~~~~~~~~~~~~~");
System.out.println("Hall 2: Movie ID: 7 Movie: Predator Cost: $9.50");
System.out.println("Hall 3: Movie ID: 11 Movie: Predator Cost: $9.50");
System.out.println();
System.out.println("====================================================================================");
}
else{
System.out.println("******************** End Of Your Booking ********************");
}

}}
View Answers

July 14, 2010 at 11:48 AM


Hi Friend,

Try the following code:

import java.util.*;

public class Hall {
static Scanner scan = new Scanner(System.in);
public static String username;
public static String password;
public static String input;
public static int userInput;
public static void main(String[] args) {
System.out.print("Enter your username:");
username = scan.nextLine();
System.out.print("Enter your password:");
password = scan.nextLine();
if (username.equalsIgnoreCase("rose") && password.equalsIgnoreCase("rose")){
System.out.println();
System.out.println("You have successfully login");
System.out.println();
System.out.println("Enter '1' to view movie listing by Hall and '2' by Time: ");
userInput = scan.nextInt();
}else
System.out.println();
System.out.println("Invalid Input");
System.out.println();
if (userInput == 1){
System.out.println("====================================================================================");
System.out.println(" ~~~~~~~~~~~~~~~~~~~~~ Hall 1 ~~~~~~~~~~~~~~~~~~~~~");
System.out.println("Movid ID: 1 Title: Inception Time: 4pm Cost: $10.00");
System.out.println("Movie ID: 2 Title: Twelve Time: 6pm Cost: $9.00");
System.out.println("Movie ID: 3 Title: The Sorcerer's Apprentice Time: 8pm Cost: $9.00");
System.out.println();

System.out.println(" ~~~~~~~~~~~~~~~~~~~~~ Hall 2 ~~~~~~~~~~~~~~~~~~~~~");
System.out.println("Movie ID: 4 Title: Toy Story 3 Time: 3pm Cost: $7.50");
System.out.println("Movie ID: 5 Title: Toy Story 3 Time: 5pm Cost: $7.50");
System.out.println("Movie ID: 6 Title: Twelve Time: 7pm Cost: $9.50");
System.out.println("Movie ID: 7 Title: Predator Time: 9pm Cost: $9.50");
System.out.println();

System.out.println(" ~~~~~~~~~~~~~~~~~~~~~ Hall 3 ~~~~~~~~~~~~~~~~~~~~~");
System.out.println("Movie ID: 8 Title: Knight and Day Time: 3pm Cost: $7.50");
System.out.println("Movie ID: 9 Title: The Twilight Saga: Eclipse Time: 5pm Cost: $8.50");
System.out.println("Movie ID: 10 Title: The Twilight Saga: Eclipse Time: 7pm Cost: $10.50");
System.out.println("Movie ID: 11 Title: Predator Time: 9pm Cost: $9.50");
System.out.println("====================================================================================");
System.out.println();
}

July 14, 2010 at 11:48 AM


continue..

else if (userInput ==2){
System.out.println("====================================================================================");
System.out.println(" ~~~~~~~~~~~~~~~ Movie showing at 3pm ~~~~~~~~~~~~~~~");
System.out.println("Hall 2: Movie ID: 4 Movie: Toy Story 3 Cost: $7.50");
System.out.println("Hall 3: Movie ID: 8 Movie: Knight and Day Cost: $7.50");
System.out.println();

System.out.println(" ~~~~~~~~~~~~~~~ Movie showing at 4pm ~~~~~~~~~~~~~~~");
System.out.println("Hall: 1 Movie ID: 1 Movie: Inception Cost: $10.00");
System.out.println();

System.out.println(" ~~~~~~~~~~~~~~~ Movie showing at 5pm ~~~~~~~~~~~~~~~");
System.out.println("Hall 2: Movie ID: 5 Movie: Toy Story 3 Cost: $7.50");
System.out.println("Hall 3: Movie ID: 9 Movie: The Twilight Saga: Eclipse Cost: $8.50");
System.out.println();

System.out.println(" ~~~~~~~~~~~~~~~ Movie showing at 6pm ~~~~~~~~~~~~~~~");
System.out.println("Hall 1: Movie ID: 2 Movie: Twelve Cost: $9.00");
System.out.println();

System.out.println(" ~~~~~~~~~~~~~~~ Movie showing at 7pm ~~~~~~~~~~~~~~~");
System.out.println("Hall 2: Movie ID: 6 Movie: Twelve Cost: $9.50");
System.out.println("Hall 3: Movie ID: 10 Movie: The Twilight Saga: Eclipse Cost: $10.50");
System.out.println();

System.out.println(" ~~~~~~~~~~~~~~~ Movie showing at 8pm ~~~~~~~~~~~~~~~");
System.out.println("Hall 1: Movie ID: 3 Movie: The Sorcerer's Apprentice Cost: $9.00");
System.out.println();

System.out.println(" ~~~~~~~~~~~~~~~ Movie showing at 9pm ~~~~~~~~~~~~~~~");
System.out.println("Hall 2: Movie ID: 7 Movie: Predator Cost: $9.50");
System.out.println("Hall 3: Movie ID: 11 Movie: Predator Cost: $9.50");
System.out.println();
System.out.println("====================================================================================");
}
else{
System.out.println("******************** End Of Your Booking ********************");
}
}}

Thanks









Related Pages:
Eclipse (Problem with combining 2 codes together)(Cont) - Java Beginners
Eclipse (Problem with combining 2 codes together)(Cont)  Hi, I have a problem with this code (below), I enter the username and password correctly then I want to input an integer either 1 or 2 but if I enter wrongly, e.g. 3
Eclipse (Problem with combining 2 codes together) - Java Beginners
Eclipse (Problem with combining 2 codes together)  hi, I have 2 pieces of code and I don't know how to combine together. Hope someone can help me combine it together. And I also want to add in if (inputs.equals
Eclipse erroe
Eclipse erroe  Dear Sir, I am facing a problem while check out a project from the repository error is org.tigris.subversion.javahl.clientException: RA layer request failed
Eclipse Plunging/UML
;    Borland Together Edition for Eclipse Borland Together Edition for Eclipse is an integrated and agile design environment... combining the open-source Eclipse platform with the power of the Unified
Eclipse hibernate problem
Eclipse hibernate problem  hie..i've just started a basic hibernate application using eclipse helios.I have added the jars,configured the xml files...;Hibernate Eclipse Integration Hibernate Tutorials
Borland Together Edition for Eclipse
Borland Together Edition for Eclipse       Borland® Together® is a visual modeling platform... or extracting design information from existing systems, Together gives all
Borland Together Edition for Eclipse 6.2
Borland Together Edition for Eclipse 6.2       Borland® Together® is a visual modeling... or extracting design information from existing systems, Together gives all
Eclipse Plugings
that are available for Struts 2 Development using Eclipse IDE... and the list of plugins that are available for Struts 2 Development using Eclipse IDE... for Struts 2 Development using Eclipse IDE. Build
My Eclipse deployed problem. - Struts
My Eclipse deployed problem.  Dear All, I am facing a problem. When First time I am deploying a web project in eclipse in jboss its fine but, when I am changing the project name by pressing 'f2' and then deploying
Eclipse-Apache tomcat error
Eclipse-Apache tomcat error  Hi..I'v been trying to install apache tomcat 7 with eclipse helios to try web applications ..but unable to run webcontents .it gives the folowing msg in eclipse:Several ports (8005, 8080, 8009
Eclipse
Eclipse   I am new to eclipse. i want to create a login page in eclipse and want to connect with mysql. what are the software and jar file i need to include in eclipse
eclipse
eclipse  Hi how to debug in eclipse ide and how to find bug in eclipse ? Thanks kalins naik
Tomcat Configuration For Eclipse Server
on eclipse 1)First download the tomcat and install it on your hard drive. 2)Run the eclipse. Clicks on the window menu and then Preferences menu item. 3)Now...Tomcat Configuration For Eclipse Server  How to configure Eclipse
Error In starting Glassfish in Eclipse.
Error In starting Glassfish in Eclipse.  Sir,I am new in Java/J2EE.And i am learning j2ee by regular study of your site. I am facing a problem in eclipse when i use Glassfish as server.I have installed Glassfish in C:\Glassfish
FITpro for Eclipse
Eclipse  2. Get the FITpro zip from the SourceForge download page... FITpro for Eclipse      ... by Luxoft. FITpro for Eclipse harnesses the power of the Framework for Integrated
Eclipse
Eclipse  I am new to eclipse. I want to write a jsp program and want to connect it with mysql. What are the configurations i need to check in eclipse
java,eclipse - Swing AWT
java,eclipse  Hi, I have made on program SimpleCalculator on eclipse 3.4.0.But while running the code I am getting the problem for Class File Editor... descriptor #2 (Ljava/lang/String;)V // Stack: 2, Locals: 2 public
Eclipse
Eclipse  How to develope web application servlets or jsp using eclipse id
Maven Eclipse Integration - IDE Questions
your maven project 2. Then create eclipse project file  Hi,If you...Maven Eclipse Integration  How to integrate Maven with eclipse? Hi... to integrate it with eclipse ide then follow the following steps:1: Create your maven
Tomcat For Eclipse
Tomcat For Eclipse   ... of your eclipse installation   How To Use... For Eclipse' property, check 'is a weppapp' For each dependencies
Struts 2 Eclipse Plugin
Struts 2 Eclipse Plugin       This page contains the examples and the list of plugins that are available for Struts 2... know the Eclipse plugin for Struts 2, kindly post in the following comment box
Eclipse-launch failed binaries not found
Eclipse-launch failed binaries not found  I recently downloaded eclipse(eclipse-cpp-europa-winter-win32) to work on c++. I don't know how to launch a cpp program in eclipse. I will tell you the steps that I am performing
Hibernate error in eclipse
code........ I will try to short out your problem
Database Modeling in Eclipse
Database Modeling in Eclipse   ...-in in the Eclipse (http://www.eclipse.org/) development environment. Clay has... database model. Locate the problem source by double-clicking on a error
Eclipse helios "Build Before Launch"
Eclipse helios "Build Before Launch"  Hi The IDE Eclipse Helios... look into this issue . i have tried these settings for Eclipse Helios... facing the problem please provide me the answer how to resolve it Thanks &
Eclipse helios "Build Before Launch"
Eclipse helios "Build Before Launch"  Hi The IDE Eclipse Helios... into this issue . i have tried these settings for Eclipse Helios Disable... the problem please provide me the answer how to resolve it Thanks & Regards chakry
hibernate configuration with eclipse 3.1 - Hibernate
there are plugin problem and .jar files and i m not able to open this existing project in eclipse. so facing more problem and need ur help. Thanks...hibernate configuration with eclipse 3.1  Dear Sir, i got your mail
Astyle Eclipse Plugin
Astyle Eclipse Plugin       Astyle Eclipse is based on Astyle program, it aims to provide a C/C++ formatter for CDT plugin in eclipse. so all the supported
Downloading, Installing and Initializing Eclipse
folder. 2. Now it will ask to specify a workspace to use (C:\Eclipse\workspace... Downloading, Installing and Initializing Eclipse       To use Eclipse in your system
Subversion Eclipse Plugin
Subversion Eclipse Plugin This tutorial shows you how to install Subversion Eclipse Plugin on Eclipse IDE. Eclipse provides in-built plugin for CVS... Subversion as version controlling tool. Eclipse does not provide any in-built tool
DB Visual Architect for Eclipse
DB Visual Architect for Eclipse   ... for Eclipse (DBVA-EC) supports wide range of databases, including Oracle, DB2... Together with Team Development Support Teamwork Server enables your software
Maven 2 Eclipse Plug-in
Maven 2 Eclipse Plug-in      ... from   http://www.eclipse.org/downloads/ 2. Get Maven-eclipse-plugin-plugin... the Maven Plugin with your eclipse IDE. Why Maven with Eclipse Eclipse is an industry
Lint4j Eclipse Plugin
Lint4j Eclipse Plugin         Eclipse is the perfect environment for using Lint4j. Problems can be reported as soon as the source is saved, and the Eclipse problem
XPairtise - Pair Programming for Eclipse
XPairtise - Pair Programming for Eclipse       The Eclipse plug-in XPairtise provides... terminal and program together. Distributed pair programming is the practice
search engine build by lucene and eclipse
JLabel(""); static JLabel[][] jlblResult = new JLabel[20][2... k=0;k<2;k++){ jlblResult[i][k] = new JLabel...++){ for(int k=0;k<2;k
I cannott integrate j boss wth eclipse
I cannott integrate j boss wth eclipse   Dear friend, I have a sophisticated problem with my IDE eclipse.I am trying to start my ap server boss ,i have getting a eror that "server cannot start the time of 50 sec ". Please help
Eclipse Plunging- Application Management
Eclipse Plunging- Application Management  ... Cape Clear Orchestrator is an intuitive Eclipse-based editor intended to simplify... directly integrates with Eclipse through a new Eclipse Plug-in called CodeLink
Database Modeling in Eclipse
Database Modeling in Eclipse   ...-in in the Eclipse (http://www.eclipse.org/) development environment. Clay has... database model. Locate the problem source by double-clicking on a error
Download Eclipse Helios And Add The Tomcat7 For Java EE6
Download Eclipse Helios And Add The Tomcat7 For Java EE6 In this tutorial you will learn how to download the Eclipse Helios IDE and how to add the tomcat7 application server in Eclipse. You can download the Eclipse Helios IDE for Java
Problem while using tomcat 6.0 in eclipse with struts application
Problem while using tomcat 6.0 in eclipse with struts application  Hi please provide solution for the following problem org.apache.jasper.JasperException: java.lang.ClassCastException
DB Visual Architect for Eclipse
DB Visual Architect for Eclipse   ... for Eclipse (DBVA-EC) supports wide range of databases, including Oracle, DB2... Together with Team Development Support Teamwork Server enables your software
Maven 2 Eclipse Plug-in
Maven 2 Eclipse Plug-in      ... Plugin with your eclipse IDE. Why Maven with Eclipse Eclipse...?Eclipse Integration makes the development, testing, packaging and deployment
How to navigate from one jsf to another in eclipse
id="UserDetail"> <h:panelGrid columns="2"> <h:outputText value... is working fine in NETBEANS.. but when i run this in eclipse it stays on the first...; </navigation-rule> Pls help me finding the solution for this problem
First Hibernate 4 Example with Eclipse
First Hibernate 4 Example with Eclipse In this tutorial you will learn that how easily you can do your first example of Hibernate 4 with Eclipse First... here. Next if you want to do example in Eclipse so an Eclipse IDE (Eclipse
Java with OOP assignment (Eclipse) - Java Beginners
Java with OOP assignment (Eclipse)  "THREE Ts GAME" *Description...* 1. The game must be GUI based. 2. Create all the necessary classes...[i][2].getToken() == token)) { return true; } for (int j = 0; j
eclipse - Struts
Eclipse keyboard shortcuts  I need a list of eclipse keyboard shortcuts.Thanks
Eclipse
Eclipse       Eclipse... a development environment from plug-in components. Fortunately, Eclipse comes... can also extend its capabilities by installing plug-ins written for the Eclipse
How to install Hibernate-3 and jars required for eclipse environment. And is jboss jars are necessary..?
How to install Hibernate-3 and jars required for eclipse environment... in Hibernate. Please guide me. I have Eclipse Platform Version: 3.3.1.1, Apache..... So i am confusing...? I need how many jars and what it might be..? 2) How
What is difference among Project explorer, Package explorer and Navigator in Eclipse?
in Eclipse?  The three in eclipse are looking like for same purpose. Could... to the Eclipse help, 1)Project Explorer: The Project Explorer provides... by the specific configuration of your Workbench. 2)Package Explorer - Provided by the Java
Debug in Eclipse
Debug in Eclipse  How to debug a java application in Eclipse Helio version

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.