Java Programming
9th Edition
ISBN: 9780357616635
Author: Joyce Farrell
Publisher: CENGAGE L
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 12, Problem 7RQ
Program Description Answer
Except the keyword catch, a try block will include the elements such as the keyword try, curly braces and the statements that might cause Exceptions.
Hence, the correct answer is option “B”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
The __________ family of methods can be used to convert a string to a specific data type without throwing an exception. a. TryConvert b. Parse c. TryParse d. SafeConvert
Exception handling and File I/O coding intellj
Exercise 3.
File I/O Please create a file and add the following line: 1,5,7,9,13,58,70
Exercise 4,
Assuming you have a file on your laptop, and it has the following: John,23 Please create a Person object from your main method by reading the file. You have to create Person class (String name, int age) Please read the file and show the sum of all the numbers.
Java
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
- The program from the previous question is Pylint compliant (note the appropriate use of global constants, docstrings, and the main function). However, it still has room for improvement. Using the functional decomposition skills you learned earlier, refactor the program so that it behaves exactly as before but now defines and calls the following functions: read_int: As defined previously. get_names: Prompts the user for student names and returns them as a list. get_marks: Takes a list of student names, prompts the user for each student's mark, and returns the marks as a mapped list. • grades: Takes a list of marks and returns a mapped list of the corresponding letter grades. • print_results: Takes mapped lists of student names, their marks, and their corresponding grades and prints out the class results. After refactoring, your main function should look like this: def main(): ""Prompts the user to enter student names and marks, calculates their grades, and prints the results names =…arrow_forwardJava Exceptions: Your parents gave you an emergency cash card that has 2 restrictions: it can't be used to purchase alcohol, and the purchase price must be less than $100. Write a program segment in main() that will read 2 inputs from the user describing a purchase you are trying to make using the cash card: the item purchased (eg runners) and the purchase price (eg 79.99). Your code must check for the 2 restrictions mentioned above and generate exceptions if either one of them occurs (InvalidItemException or InvalidPurchasePriceException. Assume that these have already been coded so you don't need to write them). Your code must also deal with each exception by writing out an appropriate (specific) message stating what the problem is. If there is no problem your code should generate a "Payment accepted" message.arrow_forward1. Write an application named GoToo Far in which you declare an array of five integers and store five values in the array. Write a try block in which you loop to display each successive element of the array, increasing a subscript by 1 on each pass through the loop. Create a catch block that catches the eventual ArrayIndexOutOfBoundsException and displays the message, "Now you've gone too far". Save the file as GoTooFar.java.arrow_forward
- True or False ___(16) The break; statement in Java inside the inner loop of a nested loop stops the execution from the inner loop only. ___(17) Exception is a way to handle errors in Java programming. ___(18) The term length( ) in a string class is a variable that contain the total number of characters in a stringarrow_forwardThis code is correct but can you add to the code this instructions: If the father's age is equal to the mother's age and the age is odd, then the child is Female The code should call `createKidPerson` in main. #include <iostream>using namespace std; typedef struct { int age; char gender;} Person; void displayPerson(Person); Person createKidPerson(Person father, Person mother); int main(void) { Person father; Person mother; father.gender = 'M'; mother.gender = 'F'; //ask the user for the age of the Male Person and the age of the Female Person. cout<<"Enter the Male Person's age: "; cin>>father.age; cout<<"Enter the Female Person's age: "; cin>>mother.age; //create a new Person and call createKidPerson() function Person kid = createKidPerson(father, mother); displayPerson(kid); return 0;} Person createKidPerson(Person father, Person mother) { Person p; if(father.age>=mother.age) //if…arrow_forwardCreate methods "read" and "write" methods to handle the input and output to files. in Javaarrow_forward
- C2- Write a Python program that reads the contents of a file named ‘Book.txt’ (you must write exception handling if the file doesn’t exist) The program should also determine and print the following: The number of words in the file The number of distinct words (without repetition) The number of uppercase letters in the file The number of lowercase letters in the file The number of digits in the file The number of whitespace characters in the filearrow_forwardC PROGRAMMING HELP I need help fixing an old assignment of mine. The point of the script is to read the pasted/attached Number_new.txt file's contents, meant to represent a classes' final grades out of 100 percent, and print an .exe screen as well as another .txt file that repeats the grade number with a letter grade and a PASS or FAIL next to it. At the end it needs to say how many students passed and how many failed. Nothing too complicated with the grading, just 90.0 and up is an A, 80.0 to 89.99 is a B, etc. And of course, anything below 60.0 is an F/FAIL. Please NO IOSTREAM.H OR CACIO.H! I cant use those header files. Below is the script: #include<stdio.h>#include<math.h>#define THEFILE "Number_new.txt" int main(){ float r0[10]; float rr[10]; FILE *fp; char line[81]; fp = fopen(THEFILE, "Number_new.txt"); if (fp != NULL) { /* The file is open. */ printf("%7s %7s %7s %7s %7s %7s %7s %7s %7s %7s\n", "0", "0.01",…arrow_forwardC++ Code: Fractions and Recipesarrow_forward
- JAVA PPROGRAM ASAP Please Modify this program ASAP BECAUSE IT IS HOMEWORK ASSIGNMENT so it passes all the test cases. The program must pass the test case when uploaded to Hypergrade. Also, for test cases 1-4 it wants only to input Please enter the file name or type QUIT to exit: then input the file and display the Total number of words. For test cases 5 and 7 it wants to only to input Please enter the file name or type QUIT to exit then input input5.txt and then display File: input5.txt does not exist.\n then display Please enter the file name again or type QUIT to exit:\n then type input1.txt to display the total number of words or type quit to exit the program. For test case 6 it wants only to Please enter the file name again or type QUIT to exit:\n then type quit to exit the porgram. Chapter 9. PC #10. Word Counter (page 610) Write a program that asks the user for the name of a file. The program should display the number of words that the file contains. Input…arrow_forwardCreate a simple calculator application that asks a user to enter twonumbers and the operation (e.g. +, -, x, etc.) that they’d like to perform onthe numbers. Display the answer to the equation. Every equation enteredby the user should be written to a text file. Use defensive programming towrite this program in a manner that is robust and handles unexpectedevents and user inputs.arrow_forwardYou might either press "F5" or select "Start Debugging" to begin debugging. When an exception is thrown, Visual Studio goes into a special mode.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT