Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

Have Programming Question? Ask it here!
 
 
 


Ben
Eclipse (Problem with combining 2 codes together)(Cont)
2 Answer(s)      4 years and 2 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 ********************");
}

}}

Advertisement
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 Tutorials/Questions & Answers:
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
Advertisements
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
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
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
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
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
Eclipse  How to develope web application servlets or jsp using eclipse id
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
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
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
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
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
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
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+wampserver
eclipse+wampserver  when i run my mobile appilcation code in eclipse i get an error, ClassNotFoundException: com.mysql.jdbc.Driver SQLException: No suitable driver found for jdbc:mysql://127.0.0.1/plants. i have already created
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
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
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
SJ Eclipse
SJ Eclipse       SJ Eclipse is an Eclipse plugin that allows users to interact with a SourceJammer archive. Once you install SJ Eclipse, the first thing you should
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
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
websphere IDE and eclipse IDE
websphere IDE and eclipse IDE  can we work struts framework in eclipse IDE. i am working in trial version of websphere studio application developer . if i work in eclipse all the features are available in eclipse
plugins in eclipse helios
plugins in eclipse helios  How to add the capabilities of already builtin plugins to the project in eclipse helios
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
Eclipse Goodies
Eclipse Goodies       Eclipse Goodies is a set of open source released Eclipse-plugins and tools for the Eclipse RCP and other Eclipse projects like BIRT or GEF we
Spring and Eclipse - Spring
Spring and Eclipse  How to add Spring API Docs to Eclipse
Tikal Eclipse
Tikal Eclipse       Tikal Eclipse is an open source Eclipse-based distro which combines the Eclipse binaries with a broad range of Eclipse plugins for Java, Java
eclipse - JSP-Servlet
Eclipse ide for java ee developers  What is the eclipse ide for java ee developers ..and from where i can download
Tomcat For Eclipse
Tomcat For Eclipse   ... of your eclipse installation   How To Use... For Eclipse' property, check 'is a weppapp' For each dependencies
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
Working with Eclipse IDE - Struts
Working with Eclipse IDE  hello, i am beginner to eclipse . i want to run my first struts program in eclipse 3.2. what are the steps for running struts in eclipse . Any body plz, tell me the setting environment of eclipse
Eclipse configuration - Hibernate
Eclipse configuration  Hi, I installed Eclipse and Tomcat 6.0. I configured the tomcat in the eclipse. When I execute simple JSP example it use...\eclipse-jee-ganymee-win32/eclipse\plugins\org.eclipse.jst.server.generic.jboss
Downloading, Installing and Initializing Eclipse
? file in the eclipse folder. 2. Now it will ask to specify a workspace to use... Downloading, Installing and Initializing Eclipse       To use Eclipse in your system
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
Eclipse JarRetriever
Eclipse JarRetriever Eclipse JarRetriever is a plug-in for Eclipse that allows developers to easily search for and download jar files from... detail: https://eclipse-jarretriever.dev.java.net
eclipse - IDE Questions
eclipse  Hey I am very new to eclipse and I don't know how to execute web based project on eclipse.Please help me by providing the procedure? Please tell me the latest version of Eclipse IDE used and how to download
Importing in eclipse - Java Beginners
Importing in eclipse  I'm using eclipse for designing struts application... I'm manually copying the tld files and creating struts-config.xml file... the struts capabilities automatically in eclipse
Eclipse - IDE Questions
Eclipse  Hello Sir, I want to configure the eclipse IDE to perform java web applications...so please help me in this regard..... thank you...  Hi friend, For read more information on Eclipse IDE visit
Struts with Eclipse - IDE Questions
Struts with Eclipse  How to develope struts application in Websphere Rational Application Developer 7.0?  AT First Check Your Eclipse contain Plugins for Websphere 7.0 or not? ifcontain go preference/eclipse
DWR eclipse Plugin - Framework
DWR eclipse Plugin  Hi, I am new to DWR, can u please guide me how to use DWR with eclipse3.1
mini project using eclipse
mini project using eclipse  please send me the steps to design online examination system using eclipse,,,,b fast
eclipse svn - Subversion
eclipse svn  Hi I m using svn along with eclipse. I have so many commits in a branch named test. Suppose it have versions 101,102,103,104 ...200.... Is it possible to do it with eclipse? Please help me... Thanks in advance
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
WebScarab for Eclipse
WebScarab for Eclipse         WebScarab for Eclipse is an extensible framework... and remote servers. It is a port to Eclipse of the WebScarab application from
Eclipse - Java Beginners
Eclipse  hi.. i have a file in java(SWT , Eclipse) which adds widgets at runtime... but the widgets are not visible until i resize the window... can anyone help me
Adding Jar into Eclipse
Adding Jar into Eclipse  Hi, Please provide Step by step procedure to add jar, tld files and configurations in Eclipse Helios version and i am using Jboss5. Thanks&Regards, Shiva s
Advertisements
 

 

 

DMCA.com