Need quoter for Assignments enclosed
Module 4 Assignment Criteria For this assignment, you will process a large dataset. A university posts its employees’ salaries at liveexample.pearsoncmg.com/data/Salary.txt. Each line in the file consists of a faculty member’s first name, last name, rank, and salary (see Programming Exercise 12.24). 1. Create pseudo-code for this project 2. Write a program to display the total salary for assistant professors, associate professors, full professors, and all faculty, respectively, and display the average salary for assistant professors, associate professors, full professors, and all faculty, respectively. After running your program, the results should look similar to the image below. Once finished, zip your project folder and upload to the dropbox. Don’t forget to include your pseudocode. Module 5 Assignment Criteria For this assignment, you will generate and display a pie chart. 1. Write pseudo-code for the project. 2. Write a program that uses a pie chart to display the percentages of the overall grade represented by projects, quizzes, midterm exams, and the final exam, as shown in the image below. a. Projects take 20 percent and are displayed in red. b. Quizzes take 10 percent and are displayed in blue. c. Midterm exams take 30 percent and are displayed in green. d. Final exams take 40 percent and is displayed in orange. 3. Use the Arc class to display the pie slices. If interested, you may explore JavaFx’s PieChart class for additional study. Once finished, zip your project folder and upload to the dropbox. Don’t forget to include your pseudocode. Chapter 13 Exception Handling Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * Chapter 12 Exception Handling and Text IO * Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * Motivations When a program runs into a runtime error, the program terminates abnormally. How can you handle the runtime error so that the program can continue to run or terminate gracefully? This is the subject we will introduce in this chapter. Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * Objectives To get an overview of exceptions and exception handling (§12.2). To explore the advantages of using exception handling (§12.2). To distinguish exception types: Error (fatal) vs. Exception (nonfatal) and checked vs. unchecked (§12.3). To declare exceptions in a method header (§12.4.1). To throw exceptions in a method (§12.4.2). To write a try-catch block to handle exceptions (§12.4.3). To explain how an exception is propagated (§12.4.3). To obtain information from an exception object (§12.4.4). To develop applications with exception handling (§12.4.5). To use the finally clause in a try-catch block (§12.5). To use exceptions only for unexpected errors (§12.6). To rethrow exceptions in a catch block (§12.7). To create chained exceptions (§12.8). To define custom exception classes (§12.9). To discover file/directory properties, to delete and rename files/directories, and to create directories using the File class (§12.10). To write data to a file using the PrintWriter class (§12.11.1). To use try-with-resources to ensure that the resources are closed automatically (§12.11.2). To read data from a file using the Scanner class (§12.11.3). To understand how data is read using a Scanner (§12.11.4). To develop a program that replaces text in a file (§12.11.5). To read data from the Web (§12.12). To develop a Web crawler (§12.13). * Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * Exception-Handling Overview Show runtime error Fix it using an if statement With a method Run Quotient Run QuotientWithIf Run QuotientWithMethod * Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * Exception Advantages Now you see the advantages of using exception handling. It enables a method to throw an exception to its caller. Without this capability, a method must handle the exception or terminate the program. Run QuotientWithException * Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * Handling InputMismatchException By handling InputMismatchException, your program will continuously read an input until it is correct. Run InputMismatchExceptionDemo * Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * Exception Types IllegalArgumentException Many more classes Many more classes Many more classes IndexOutOfBoundsException NullPointerException ArithmeticException Object RuntimeException Exception IOException VirtualMachineError ClassNotFoundException Throwable Error LinkageError Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * System Errors System errors are thrown by JVM and represented in the Error class. The Error class describes internal system errors. Such errors rarely occur. If one does, there is little you can do beyond notifying the user and trying to terminate the program gracefully. IllegalArgumentException Many more classes Many more classes Many more classes IndexOutOfBoundsException NullPointerException ArithmeticException Object RuntimeException Exception IOException VirtualMachineError ClassNotFoundException Throwable Error LinkageError Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * Exceptions Exception describes errors caused by your program and external circumstances. These errors can be caught and handled by your program. IllegalArgumentException Many more classes Many more classes Many more classes IndexOutOfBoundsException NullPointerException ArithmeticException Object RuntimeException Exception IOException VirtualMachineError ClassNotFoundException Throwable Error LinkageError Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * Runtime Exceptions RuntimeException is caused by programming errors, such as bad casting, accessing an out-of-bounds array, and numeric errors. IllegalArgumentException Many more classes Many more classes Many more classes IndexOutOfBoundsException NullPointerException ArithmeticException Object RuntimeException Exception IOException VirtualMachineError ClassNotFoundException Throwable Error LinkageError Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * Checked Exceptions vs. Unchecked Exceptions RuntimeException, Error and their subclasses are known as unchecked exceptions. All other exceptions are known as checked exceptions, meaning that the compiler forces the programmer to check and deal with the exceptions. Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * Unchecked Exceptions In most cases, unchecked exceptions reflect programming logic errors that are not recoverable. For example, a NullPointerException is thrown if you access an object through a reference variable before an object is assigned to it; an IndexOutOfBoundsException is thrown if you access an element in an array outside the bounds of the array. These are the logic errors that should be corrected in the program. Unchecked exceptions can occur anywhere in the program. To avoid cumbersome overuse of try-catch blocks, Java does not mandate you to write code to catch unchecked exceptions. Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * Unchecked Exceptions Unchecked exception. IllegalArgumentException Many more classes Many more classes Many more classes IndexOutOfBoundsException NullPointerException ArithmeticException Object RuntimeException Exception IOException VirtualMachineError ClassNotFoundException Throwable Error LinkageError Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * Declaring, Throwing, and Catching Exceptions method1() { try { invoke method2; } catch (Exception ex) { Process exception; } } method2() throws Exception { if (an error occurs) { throw new Exception(); } } catch exception throw exception declare exception Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * Declaring Exceptions Every method must state the types of checked exceptions it might throw. This is known as declaring exceptions. public void myMethod() throws IOException public void myMethod() throws IOException, OtherException Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * Throwing Exceptions When the program detects an error, the program can create an instance of an appropriate exception type and throw it. This is known as throwing an exception. Here is an example, throw new TheException(); TheException ex = new TheException(); throw ex; Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * Throwing Exceptions Example /** Set a new radius */ public void setRadius(double newRadius) throws IllegalArgumentException { if (newRadius >= 0) radius = newRadius; else throw new IllegalArgumentException( "Radius cannot be negative"); } Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * Catching Exceptions try { statements; // Statements that may throw exceptions } catch (Exception1 exVar1) { handler for exception1; } catch (Exception2 exVar2) { handler for exception2; } ... catch (ExceptionN exVar3) { handler for exceptionN; } Liang, Introduction to Java Programming, Eleventh Edition, (c) 2017 Pearson Education, Inc. All rights reserved. * Catching Exceptions main method { ... try { ... invoke method1; statement1; } catch (Exception1 ex1) { Process ex1; } statement2; } method1 { ... try { ... invoke method2; statement3; } catch (Exception2 ex2) { Process ex2; } statement4; } Call Stack An exception is thrown in method3 method2 { ... try { ... invoke method3; statement5; } catch