
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
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?

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++) {](https://content.bartleby.com/qna-images/question/274ad608-8212-43be-a4da-26680d5ad513/436b486a-1f31-4de8-b16f-4946494164eb/rc3h1sn_thumbnail.png)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

Knowledge Booster
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
- This is a problem for you to figure out a correct regular expression using any Java compiler you are familiar or any java online interpreter to solve. YOUR NEED TO TYPE OUT YOUR REGULAR EXPRESSION (NOT HAND WRITTEN IN WORKSHEET) SO I CAN CUT AND PASTE YOUR REGULAR EXPRESSION TO VALIDATE YOUR ANSWER IN THE RUNNING JAVA PROGRAM WHEN I GRADE. Your answer should be replacing the string "^(\\d*)" in line 21 and submit this string. The "^(\\d*)" regular expression now is way too simple so it only able to validate the 1st test case out of 9 test cases. The line you will be changing is Pattern patt = Pattern.compile("^(\\d*)"); =============================================== import java.util.regex.Matcher;import java.util.regex.Pattern; public class RegularExp { public static void main(String[] args) { if (isANumber("12345")) System.out.println("true"); else System.out.println("false"); if (isANumber("-.23")) System.out.println("true"); else System.out.println("false"); if…arrow_forwardWrite a Java program that can "make change." Your program should take two numbers as input, one that is a monetary amount charged and the other that is a monetary amount given. It should then return the number of each kind of bill and coin to give back as change for the difference between the amount given and the amount charged. The values assigned to the bills and coins can be based on the monetary system of any current or former government. Try to design your program so that it returns the fewest number of bills and coins as possible.arrow_forwardWrite a program in java that completes the following prompt: You are a fundraising distributor who needs to to pre-sell a limited number of doughnut coupon books. Each buyer can buy as many as 4 coupon books. No more than 100 coupon books can be sold. Implement a program called Fundraiser that prompts the user for the desired number of coupon books and then displays the number of remaining coupon books. Repeat until all coupon books have been sold, and then display the total number of buyers.arrow_forward
- I have been working on writing a java program (that goes with another I just got finished- see below CollegeCourse & Student) that prompts user to put in letter grades (A-F) for 5 different courses for a total of 10 different students. So I need to prompt user to input a student ID, then the 1st course ID, then the grade, then the 2nd course ID- then grade, the the 3rd course ID then grade, then the 4th course ID then grade, then finally the 5th course ID then grade. Then it needs to go through the same thing 10 times (for a total of 10 students). It also says the user is asked to "Enter ID for student #s" where s is an integer from 1 through 10, indicating the student (and I don't really know how to do that but I tried as I googled java); AND "Enter course ID #n, where n is an integer from 1 through 5, indicating the course number. And last it needs to verify for grade entry that only the A, B, C, D, or F are entered.I started writing notes to try to keep track of where thing are…arrow_forwardIn Java Write a program that checks the properness of a given variable name. Morespecifically, your program should specify whether a user-entered variable nameis (1) illegal, (2) legal but uses poor style, or (3) good. There are differentopinions as to what constitutes a good style for a variable name. For thisprogram, check for good style using these rules:· Only use letters and digits.· Use a lowercase letter for the first character.You do not need to check for an uppercase letter for the first letter in the secondand third words, ...etc.Your program should repeatedly prompt the user for variable names until the userenters "q" or "Q." the program terminates when the user enters the "q" or "Q." Sample session:This program checks the properness of a proposed Java variable name.Enter a variable name (q or Q to quit): streetAddress2Good!Enter a variable name (q or Q to quit): street address2Illegal.Enter a variable name (q or Q to quit): StreetAddress2Legal, but uses poor style.Enter a…arrow_forwardSo, I'm trying to convert this python code into Java, and I'm struggling to work out some of the final kinks of it, I think. Here's what I have so far: class Person { public String Name; public int Age; public String isStudent; public Person(String Name, int Age) { this.Name = name; this.Age = age; this.isStudent = "False"; } public void birthday() { age += 1; } public void straw() { string result = ""; result += name + " is "; if (isStudent = "True") { result += "a student "; } else { result += "not a student "; } result += "and is " + age + " years old"; System.out.println(result); } } class Student extends Person { public Student(String name, int age){ super(name, age); this.isStudent = "True"; } } public class Main { public static void main(String[] args) { Student z = new Student("Bob", 20); z.straw(); z.birthday(); z.straw(); Person r = new Person("Rob", 22);…arrow_forward
- In Java.arrow_forwardThis assignment will help you to get started with NetBeans and using Java compiler: To begin, put a block comment at the beginning of your Java file (and every Java source file in the future) with the assignment number, assignment title, program author [your name], and the date it's due. Next, similar to the programs presented in the first chapter of the textbook, use System.out object to display the following information: Your first name The name of the operating system you are using The name of your project (or simply the folder name if not using the IDE) The name of the class that contains the main() method in your source file. Note: Your program should print each of the above items on a separate output line. "The name of the class that contains the main() method in your source file.public class MyClass { public static void main(String[]) { System.out.println( "Hi" ); }}arrow_forwardHello, I am working on homework for my computer science class in Java. The assignment is to write code in java that can take an input from the command line, which will be a sentence with improper capitalization. For example "joey DoEsnt Like cAts. HoWeveR She doES." and the code is supposed to fix all the capitalization errors. I am stuck on how to approach this problem.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education