Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

I'm working on a java program that takes input from user and creates flights (objects).

I'm trying to assign variables to user input, and use these variables as an argument for my object, but I keep getting an error that says I didn't initalize my variables (although I did + it should have the value of user input). Can someoene please tell me what I'm doing wrong?

82
cap = sc.nextInt ()
83
84
catch (Exception InputMismatch) {
System.out.println ("Please input an integer number");
85
86
}
87
System.out.println ("Does the flight make more than one stop to its destination? answer true or false: ");
88
try {
89
transit = sc.nextBoolean ():
90
91
catch (Exception InputMismatch) {
92
System.out.println ("Please answer (true) or (false) ");
93
94
System.out.println ("Is the flight international? answer true or false: ");
95
try {
96
international = sc.nextBoolean () ;
97
98
catch (Exception InputMismatch) {
99
System.out.println ("Please answer (true) or (false) ");
100
boolean FlightCheck = true;
for (int i = 0; i < Flights.size (); i++) {
if (flightNumber == Flights.get (i).getFlightNum () ) {
101
102
104
FlightCheck
false;
105
106
if (FlightCheck = false) {
System.out.println ("Flight " + flightNumber + "already exists");
109
110
else{
Flight flight = new Flight (flightNumber, cap, transit, international);
112
System.out.println (Flights);
O ahmed.alsomali.pkg20428164.AhmedAlsomali20428164 >
O main > while (option != 9) > switch (option)
case 1: > for (int i = 0; i < Flights.size(); i++) > if (flightNumber == Flights.get(0).getFlightNum0) >
Dutput x
A Ahmed Alsomali 20428164 (run) x Ahmed Alsomali 20428164 (run) #2 x
Select an option: 1- NewFlight
Please input flight number:
Please input flight passenger capacity (maximum) :
Does the flight make more than one stop to its destination? answer true or false:
false
Is the flight international? answer true or false:
false
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - variable flightNumber might not have been initialized
at ahmed.alsomali.pkg20428164.AhmedAlsomali20428164.main (AhmedAlsomali20428164.java:112)
C:\Users\ahmdh\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time:
8 seconds)
Abmed Alsomali 20428164 (run)
expand button
Transcribed Image Text:82 cap = sc.nextInt () 83 84 catch (Exception InputMismatch) { System.out.println ("Please input an integer number"); 85 86 } 87 System.out.println ("Does the flight make more than one stop to its destination? answer true or false: "); 88 try { 89 transit = sc.nextBoolean (): 90 91 catch (Exception InputMismatch) { 92 System.out.println ("Please answer (true) or (false) "); 93 94 System.out.println ("Is the flight international? answer true or false: "); 95 try { 96 international = sc.nextBoolean () ; 97 98 catch (Exception InputMismatch) { 99 System.out.println ("Please answer (true) or (false) "); 100 boolean FlightCheck = true; for (int i = 0; i < Flights.size (); i++) { if (flightNumber == Flights.get (i).getFlightNum () ) { 101 102 104 FlightCheck false; 105 106 if (FlightCheck = false) { System.out.println ("Flight " + flightNumber + "already exists"); 109 110 else{ Flight flight = new Flight (flightNumber, cap, transit, international); 112 System.out.println (Flights); O ahmed.alsomali.pkg20428164.AhmedAlsomali20428164 > O main > while (option != 9) > switch (option) case 1: > for (int i = 0; i < Flights.size(); i++) > if (flightNumber == Flights.get(0).getFlightNum0) > Dutput x A Ahmed Alsomali 20428164 (run) x Ahmed Alsomali 20428164 (run) #2 x Select an option: 1- NewFlight Please input flight number: Please input flight passenger capacity (maximum) : Does the flight make more than one stop to its destination? answer true or false: false Is the flight international? answer true or false: false Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - variable flightNumber might not have been initialized at ahmed.alsomali.pkg20428164.AhmedAlsomali20428164.main (AhmedAlsomali20428164.java:112) C:\Users\ahmdh\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 8 seconds) Abmed Alsomali 20428164 (run)
public static void main (String [] args) {
ArrayList<Flight> Flights = new ArrayList<Flight>();
Scanner sc = new Scanner (System.in);
int option = 0;
while (option != 9) {
System.out.println ("Select an option: 1- NewFlight");
option = sc.nextInt () :
switch (option) {
case l:
int flightNumber, cap = 0; boolean transit, international = false;
System.out.println ("Please input flight number: ");
try {
flightNumber = sc.nextInt ();
catch (Exception InputMismatch) {
System.out.println ("Please input an integer number");
System.out.println ("Please input flight passenger capacity (maximum) : ");
try {
cap = sc.nextInt () ;
}
catch (Exception InputMismatch) {
System.out.println ("Please input an integer number");
System.out.println ("Does the flight make more than one stop to its destination? answer true or false: ");
try {
transit = sc.nextBoolean ();
}
catch (Exception InputMismatch) {
System.out.println ("Please answer (true) or (false) ");
System.out.println ("Is the flight international? answer true or false: ");
try {
international = sc.nextBoolean () ;
}
catch (Exception InputMismatch) {
System.out.println ("Please answer (true) or
(false) ");
boolean FlightCheck = true;
for (int i = 0; i < Flights.size (); i++) {
expand button
Transcribed Image Text:public static void main (String [] args) { ArrayList<Flight> Flights = new ArrayList<Flight>(); Scanner sc = new Scanner (System.in); int option = 0; while (option != 9) { System.out.println ("Select an option: 1- NewFlight"); option = sc.nextInt () : switch (option) { case l: int flightNumber, cap = 0; boolean transit, international = false; System.out.println ("Please input flight number: "); try { flightNumber = sc.nextInt (); catch (Exception InputMismatch) { System.out.println ("Please input an integer number"); System.out.println ("Please input flight passenger capacity (maximum) : "); try { cap = sc.nextInt () ; } catch (Exception InputMismatch) { System.out.println ("Please input an integer number"); System.out.println ("Does the flight make more than one stop to its destination? answer true or false: "); try { transit = sc.nextBoolean (); } catch (Exception InputMismatch) { System.out.println ("Please answer (true) or (false) "); System.out.println ("Is the flight international? answer true or false: "); try { international = sc.nextBoolean () ; } catch (Exception InputMismatch) { System.out.println ("Please answer (true) or (false) "); boolean FlightCheck = true; for (int i = 0; i < Flights.size (); i++) {
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education