questions for final

docx

School

Georgetown University *

*We aren’t endorsed by this school

Course

216

Subject

Computer Science

Date

Apr 3, 2024

Type

docx

Pages

7

Uploaded by JusticeMusic925

Report
1. The ___________ class is part of the java.lang package, so no import statement is necessary to use this class. Character 2. - A superclass reference variable can reference objects of a subclass. T/F True - An inner class is a class that is defined outside another class. T/F False 3. Each exception object has a method named ________ that can be used to retrieve the default error message for the exception. getMessage 4. What is the hierarchy of NumberFormatException class is? Object ->Throwable -> Exception ->RuntimeException ->IllegalAgumentException-> NumberFormatException 5. Displaying an image in a JavaFX application is a two-step process. What are the steps? Select two - Load the image into memory - Display the image - Open the image - Download the image on the application LOAD & DISPLAY 6. RadioButton controls normally appear individually and doesn’t allow the user to select one of several possible options. T/F False 7. JaaFX provides several classes that can be used to draw simple shapes, such as lines, circles, rectangles and more. T/F TRue
Answers 1. With inheritance, private variables of the superclass are not inherited a) True b) False 2.. A subclass can not override a method of the superclass by providing a new implementation. a) True b) False 3.You can instantiate an object from an abstract class.  a) True b) False 4. All Java classes extend the Object class a) True b) False 5.  An interface is a collection of abstract methods and constants a) True b) False 6. Aggregation is a strong type of Association  a) True b) False 7. Unchecked Exceptions represent defects in the program (bugs) a) True b) False 1. In a few words when is it best the throw and catch? It’s best to use to avoid exceptions so that code doesn't break before the full execution. 2. T/F Aggregation OWNS another class? 3. When a subclass object uses a superclass reference it is called?  a) inheritance  b) downcasting   c) upcasting  d) concrete 4. T/F overriding uses the same name and the same parameters? 5. What keyword is used when creating an inheritance hierarchy?
Extends keyword 6. Which access modifier only allows its contents to be accessed by its own class? a) public b) protected c) private d) default 7. T/ F a runtime exception is a checked exception?
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
7 import javax.swing.JOptionPane; 8 public class PA5_FV{ 9 final static int MAX_CAR = 50; 10 public static void main(String[] args){ 11 12 //forming mainline 13 String[] carMake = new String[MAX_CAR]; 14 String[] carModel = new String[MAX_CAR]; 15 String [] carBodyStyle = new String[MAX_CAR]; 16 int [] carYear = new int [MAX_CAR]; 17 double [] carPrice = new double [MAX_CAR]; 18 double [][] discountTable = {{6.2,6.5,10,7,2}, 19 {2.7,4.5,5,6}, 20 {8.4,3.9,4.5,5}, 21 {4.6,2.9,3.3,4.5}, 22 {8.2,2.5,3,3.5}, 23 {8,2.0,2.5,5}}; 24 25 26 27 int numCar = getInput(carMake, carModel, carBodyStyle, carYear, carPrice); 28 double discountP = calculatePercentageDiscount(carBodyStyle, discountTable, carYear, numCar); 29 displayCarReport(carMake,carModel ,carBodyStyle, carYear ,carPrice,discountTable, numCar, discountP); 30 31 } // end main method 32 33 public static int getInput(String[] carMake,String[] carModel,String[] carBodyStyle, int [] carYear, double [] carPrice){ 34 int numCar = 0; 35 do { 36 carMake[numCar] = getCarMake(); 37 carModel[numCar] = getCarModel(); 38 carBodyStyle[numCar] = getCarBodyStyle(); 39 carYear[numCar] = getCarYear(); 40 carPrice[numCar] = getCarPrice(); 41 numCar++; 42 } while (JOptionPane.showConfirmDialog( null , "Do you want to enter another vehicle information?" )==0); 43 return numCar; 44 } //end getInput method 45 46 47 public static String getCarMake(){
48 String make = " " ; 49 do { 50 make = JOptionPane.showInputDialog( "Please Enter the Make of the Vehicle " ); 51 if (make.equals( " " )){ 52 JOptionPane.showMessageDialog( null , "Invalid entry! Make can not be empty. Please Try again" ); 53 } 54 } while (make.equals( " " )); 55 56 return make; 57 } // end getCarMake 58 59 public static String getCarModel(){ 60 String model = " " ; 61 do { 62 model = JOptionPane.showInputDialog( "Please Enter the Model of the Vehicle " ); 63 if (model.equals( " " )){ 64 JOptionPane.showMessageDialog( null , "Invalid entry! Model can not be empty. Please Try again" ); 65 } 66 } while (model.equals( "" )); 67 68 return model; 69 } // end getCarModel 70 71 72 public static String getCarBodyStyle(){ 73 String bodyStyle = " " ; 74 do { 75 bodyStyle = JOptionPane.showInputDialog( "Enter the Body Style of the Vehicle\n" 76 + "- Small \n" 77 + "- Medium \n" 78 + "- Full Size \n" 79 + "- Luxury" ); 80 if (bodyStyle.equals( "" )){ 81 JOptionPane.showMessageDialog( null , "Invalid entry! Body Style can not be empty. Please Try again" ); 82 } 83 } while (bodyStyle.equals( "" )); 84 85 return bodyStyle; 86 87
88 } // end getCarBodyStyle method 89 90 91 public static int getCarYear(){ 92 int year = 0; 93 boolean valid = false ; 94 do { 95 try { 96 year = Integer.parseInt(JOptionPane.showInputDialog( "Enter the year of the vehicle" )); 97 if (year>=0){ 98 valid = true ; 99 } 100 else { 101 JOptionPane.showMessageDialog( null , "The year can not be negetive" ); 102 } 103 } catch (NumberFormatException e){ 104 JOptionPane.showMessageDialog( null , "The year can not be a string" ); 105 } 106 } while (!valid); 107 return year; 108 109 } // end getCarYear method 110 111 112 113 public static double getCarPrice(){ 114 double price = 0; 115 boolean valid = false ; 116 do { 117 try { 118 price = Double.parseDouble(JOptionPane.showInputDialog( "Enter price of the vehicle" )); 119 if (price>0) 120 valid = true ; 121 } catch (NumberFormatException e){ 122 JOptionPane.showMessageDialog( null , "Error! The price can not be a string" ); 123 } 124 } while (!valid); 125 return price; 126 } //end getCarPrice method
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
127 128 129 public static double calculatePercentageDiscount(String[] carBodyStyle, double [][] discountTable, int [] carYear, int numCar){ 130 double discountPercentage=0; 131 double discountAmount = 0; 132 double newPrice = 0; 133 for ( int i=0; i<numCar; i++){ 134 for ( int j=0; j<numCar; j++){ 135 discountPercentage = discountTable[i][j]; 136 } 137 138 } 139 140 return discountPercentage; 141 } //end calculatePercentageDiscount 142 143 public static void displayCarReport(String[] carMake, String[] carModel ,String[] carBodyStyle, int [] carYear , double [] carPrice, double [][] discountTable, int numCar, double discountP){ 144 String output = "VEHICLE INFORMATION: \n\n" ; 145 for ( int i=0; i<numCar; i++){ 146 output+= "Make: " + carMake[i] + "\n" 147 + "Model: " + carModel[i] + "\n" 148 + "Body Style: " + carBodyStyle[i] + "\n" 149 + "Year: " + carYear[i] + "\n" 150 + "Price: " + carPrice[i] + "\n" 151 + "Price after discount " + discountP + "\n\n" ; 152 } 153 JOptionPane.showMessageDialog( null , output); 154 } 155 156 } //end displayCarReport Our team is excited to present our project, which was designed for airlines and allows users to make flight reservations to 3 chosen destinations.