catch (Exception InputMismatch) { System.out.printin ("Please input an integer number"): System.out.printin ("Does the flight make more than one stop to its destination? answer true or false: ") : try ( transit - sc.nextBoolean (): catch (Exception InputMismatch) ( System.out.printin ("Please answer (true) or (false) "): System.out.printin ("Is the flight international? answer true or false: "): try ( international - sc.nextBoolean (): catch (Exception InputMismatch) ( System.out.printin ("Please answer (true) or (false) "): boolean FlightCheck - true: for (int i - 0; i< Flights.size (): i++) { if (flightNumber -- Flights.get (i).getFlightNum () ){ FlightCheck - false: if (FlightCheck - false) { System.out.printin ("Flight " + flightNumber + "already exists"): elsel Flight flight - new Flight (flightNumber, cap, transit, international): System.out.printin (Flights): g20428164.AhmedAlsomali20428 164> O main > while (option !- 9) > switch (option) > case 1: > for (nti - 0; i < Fights.size); i++) > if (fightNumber - Fights.get().getFightNum0) > li 20428164 (run) x Ahmed Alsomali 20428 164 (run) #2 x Pption: 1- NlewFlight at flight number: at flight passenger capacity (maximum) : light make more than one stop to its destination? ansver true or false: ght international? ansver true or false: in thread "main" java.lang. Runtime Exception: Uncompilable source code - variable flightlumber might not have been initialized ahmed. alsomali.pkg20428164.AhmedAlsomali20428164.main (AhmedAlsomali20428164.java:112) nmdh\AppData\Local\NetBeans\Cache\8.2\executor-snippess\run.xml:53: Java returned: 1

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
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)
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++) {
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Exception Handling Keywords
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education