Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 11, Problem 2FTE
// Assume inputFile references a Scanner object,
try
{
input = inputFile.nextlnt();
}
finally
{
inputFile.close();
}
catch (InputMismatchException e)
{
System.out.pri ntln(e.getMessage{));
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Simple try-catch Program
This lab is a simple program that demonstrates how try-catch works. You will notice the output when you enter incorrect
input (for example, enter a string or double instead of an integer). Type up the code, execute and submit the results ONLY. Do at
least 2 valid inputs and 1 invalid. NOTE: The program does not stop executing after it encounters an error!
CODE:
import java.util.Scanner;
public class TryCatch Example Simple {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num = 0;
System.out.println("Even number tester.\n");
System.out.println("Enter your name: ");
String name = input.nextLine();
while (true)
{
try {
System.out.println("Enter an integer : ");
Check this code for this assignment: It runs successfully on Netbeans IDE but there is no output.// Create a Scanner object to read user input Scanner input = new Scanner(System.in);
// Prompt the user to enter the street number System.out.print("Enter street number: "); int streetNumber = input.nextInt(); input.nextLine();
// Prompt the user to enter the street name System.out.print("Enter street name: "); String streetName = input.nextLine();
// Prompt the user to enter the number of rooms in the house System.out.print("Enter number of rooms: "); int numRooms = input.nextInt(); input.nextLine();
// Create an array to store the room types String[] roomTypes = { "living", "dining", "bedroom1", "bedroom2", "kitchen", "bathroom" };
// Create an array to store the area of each room int[] roomAreas = new int[6];
// Prompt the user to enter the area of each room…
// DebugFive2.java
// Decides if two numbers are evenly divisible
import java.util.Scanner;
public class DebugFive2
{
publicstaticvoidmain(Stringargs[])
{
int num;
int num2;
Scanner input =newScanner(System.in);
System.out.print("Enter a number ");
num = input.nextInteger()
System.out.print("Enter another number ");
num2 = inputnextInt();
if((num % num2 ==0) && (num2 % num) ==0)
System.out.println("One of these numbers is evenly divisible into the other");
else
System.out.println("Neither of these numbers is evenly divisible into the other");
}
}
Chapter 11 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 11.1 - Prob. 11.1CPCh. 11.1 - Prob. 11.2CPCh. 11.1 - Prob. 11.3CPCh. 11.1 - Prob. 11.4CPCh. 11.1 - Prob. 11.5CPCh. 11.1 - Prob. 11.6CPCh. 11.1 - Prob. 11.7CPCh. 11.1 - Prob. 11.8CPCh. 11.1 - Prob. 11.9CPCh. 11.1 - When does the code in a finally block execute?
Ch. 11.1 - What is the call stack? What is a stack trace?Ch. 11.1 - Prob. 11.12CPCh. 11.1 - Prob. 11.13CPCh. 11.1 - Prob. 11.14CPCh. 11.2 - What does the throw statement do?Ch. 11.2 - Prob. 11.16CPCh. 11.2 - Prob. 11.17CPCh. 11.2 - Prob. 11.18CPCh. 11.2 - Prob. 11.19CPCh. 11.3 - What is the difference between a text file and a...Ch. 11.3 - What classes do you use to write output to a...Ch. 11.3 - Prob. 11.22CPCh. 11.3 - What class do you use to work with random access...Ch. 11.3 - What are the two modes that a random access file...Ch. 11.3 - Prob. 11.25CPCh. 11 - Prob. 1MCCh. 11 - Prob. 2MCCh. 11 - Prob. 3MCCh. 11 - Prob. 4MCCh. 11 - FileNotFoundException inherits from __________. a....Ch. 11 - Prob. 6MCCh. 11 - Prob. 7MCCh. 11 - Prob. 8MCCh. 11 - Prob. 9MCCh. 11 - Prob. 10MCCh. 11 - Prob. 11MCCh. 11 - Prob. 12MCCh. 11 - Prob. 13MCCh. 11 - Prob. 14MCCh. 11 - Prob. 15MCCh. 11 - This is the process of converting an object to a...Ch. 11 - Prob. 17TFCh. 11 - Prob. 18TFCh. 11 - Prob. 19TFCh. 11 - True or False: You cannot have more than one catch...Ch. 11 - Prob. 21TFCh. 11 - Prob. 22TFCh. 11 - Prob. 23TFCh. 11 - Prob. 24TFCh. 11 - Find the error in each of the following code...Ch. 11 - // Assume inputFile references a Scanner object,...Ch. 11 - Prob. 3FTECh. 11 - Prob. 1AWCh. 11 - Prob. 2AWCh. 11 - Prob. 3AWCh. 11 - Prob. 4AWCh. 11 - Prob. 5AWCh. 11 - Prob. 6AWCh. 11 - The method getValueFromFile is public and returns...Ch. 11 - Prob. 8AWCh. 11 - Write a statement that creates an object that can...Ch. 11 - Write a statement that opens the file...Ch. 11 - Assume that the reference variable r refers to a...Ch. 11 - Prob. 1SACh. 11 - Prob. 2SACh. 11 - Prob. 3SACh. 11 - Prob. 4SACh. 11 - Prob. 5SACh. 11 - Prob. 6SACh. 11 - What types of objects can be thrown?Ch. 11 - Prob. 8SACh. 11 - Prob. 9SACh. 11 - Prob. 10SACh. 11 - What is the difference between a text file and a...Ch. 11 - What is the difference between a sequential access...Ch. 11 - What happens when you serialize an object? What...Ch. 11 - TestScores Class Write a class named TestScores....Ch. 11 - Prob. 2PCCh. 11 - Prob. 3PCCh. 11 - Prob. 4PCCh. 11 - Prob. 5PCCh. 11 - FileArray Class Design a class that has a static...Ch. 11 - File Encryption Filter File encryption is the...Ch. 11 - File Decryption Filter Write a program that...Ch. 11 - TestScores Modification for Serialization Modify...Ch. 11 - Prob. 10PC
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
You want to write a for loop that displays I love to program 50 times. Assume that you will use a counter varia...
Starting Out with C++: Early Objects (9th Edition)
Answer Problem 13 using SQL. PROBLEM 13 13. Using the commands SELECT, PROJECT, and JOIN, write a sequence of i...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Determine the resultant internal normal force, shear force, and bending moment at point C in the beam.
Mechanics of Materials (10th Edition)
Here is the code for the displayValue method, shown earlier in this chapter: public static void displayValue(in...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Order Status The Middletown Wholesale Copper Wire Company sells spools of copper wiring for 100 each. Write a p...
Starting Out with C++ from Control Structures to Objects (9th Edition)
This removes an item at a specific index in a list. a. the remove method b. the delete method c. the del statem...
Starting Out with Python (4th Edition)
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 following code is in Java: // Assume inputFile references a Scanner object. try { input = inputFile.nextInt(); } finally { inputFile.close(); } catch (InputMismatchException e) { System.out.println(e.getMessage()); } 1)What is the issue with this code?2) How can it be fixed?arrow_forwardoption: myGuess (low, high, scnr ); myGuess (mid, high, scnr); myGuess(mid + 1, high, scnr); myGuess(low, mid, scnr);arrow_forwardPlease Solve it in javaarrow_forward
- using System; namespace ErrorHandlingApplication{class DivNumbers{int result; DivNumbers(){result = 0;}public void division(int num1, int num2){try{result = num1 / num2;}catch (DivideByZeroException e){Console.WriteLine("Exception caught: {0}", e);}finally{Console.WriteLine("Result: {0}", result);}}static void Main(string[] args){DivNumbers d = new DivNumbers();d.division(25, 0);Console.ReadKey();}}} Modify this c# program on which enables users to enter value desired.arrow_forwardimport java.util.Scanner; public class InstrumentInformation { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); Instrument myInstrument = new Instrument(); StringInstrument myStringInstrument = new StringInstrument(); String instrumentName, manufacturerName, stringInstrumentName, stringManufacturer; int yearBuilt, cost, stringYearBuilt, stringCost, numStrings, numFrets; boolean bowed; instrumentName = scnr.nextLine(); manufacturerName = scnr.nextLine(); yearBuilt = scnr.nextInt(); scnr.nextLine(); cost = scnr.nextInt(); scnr.nextLine(); stringInstrumentName = scnr.nextLine(); stringManufacturer = scnr.nextLine(); stringYearBuilt = scnr.nextInt(); stringCost = scnr.nextInt(); numStrings = scnr.nextInt(); numFrets = scnr.nextInt(); bowed = scnr.nextBoolean(); myInstrument.setName(instrumentName); myInstrument.setManufacturer(manufacturerName);…arrow_forwardimport java.util.Scanner; public class MealEstablishmentDirectory { public static void main (String[] args) { Scanner scnr = new Scanner(System.in); int newRating; String newState; MealEstablishment mealEstablishment1 = new MealEstablishment(); System.out.println("Default values: "); mealEstablishment1.print(); newRating = scnr.nextInt(); newState = scnr.next(); mealEstablishment1.setRating(newRating); mealEstablishment1.setState(newState); System.out.println("After mutator methods: "); mealEstablishment1.print(); } }arrow_forward
- public int getPowerUse(){ return super.getPowerUse() + contents * powerRating; //////////////////////////////////////////////// if (args[0].equals("REFRIGERATOR")) { String manufacturer = args[1]; String serialNo = args[2]; int basePower = Integer.parseInt(args[3]); int powerRating =Integer.parseInt(args[4]); int capacity = Integer.parseInt(args[5]); Refrigerator rf=new Refrigerator(manufacturer,serialNo, basePower, powerRating, capacity); things[rf.getId()]=rf; returnval = rf.getId(); }arrow_forwardThis is the code that needs to be corrected: // This application gets a user's name and displays a greeting import java.util.Scanner; public class DebugThree3 { public static void main(String args[]) { String name; name = getName(); displayGreeting(name); } public static String getName(name) { String name; Scanner input = new Scanner(System.in); System.out.print("Enter name "); name = input.nexlLine(); return name; } public static displayGreeting(String name) { System.outprintln("Hello, " + name + "!"); } }arrow_forwardanswer itarrow_forward
- BAGEL FILES import javax.swing.JFrame; public class Bagel{//-----------------------------------------------------------------// Creates and displays the controls for a bagel shop.//-----------------------------------------------------------------public static void main (String[] args){JFrame frame = new JFrame ("Bagel Shop");frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new BagelControls()); frame.pack();frame.setVisible(true);}} import java.awt.*;import java.awt.event.*; import javax.swing.*; public class BagelControls extends JPanel{private JComboBox bagelCombo;private JButton calcButton;private JLabel cost;private double bagelCost;public BagelControls(){String[] types = {"Make A Selection...", "Plain","Asiago Cheese", "Cranberry"};bagelCombo = new JComboBox(types);calcButton = new JButton("Calc");cost = new JLabel("Cost = " + bagelCost);setPreferredSize (new Dimension (400,…arrow_forwardimport java.util.Scanner; public class CharMatch { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String userString; char charToFind; int strIndex; userString = scnr.nextLine(); charToFind = scnr.next().charAt(0); strIndex = scnr.nextInt(); /* Your code goes here */ }}arrow_forwardPlease help me fix the code Make it looks like the expected import java.util.Scanner; public class NumberLoops { public static void main(String[] args) { double num; double result = 1; int i; Scanner sc = new Scanner(System.in); // Create a Scanner object // Take user input for the Positive Number System.out.print("Enter a positive integer: "); num = sc.nextDouble(); // Read user input // if the input number is not an integer if(num % 1 != 0) { // print the message System.out.println("Not an Integer: " + num); System.exit(0); } // if the number is not a positive number if(numarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Memory Management Tutorial in Java | Java Stack vs Heap | Java Training | Edureka; Author: edureka!;https://www.youtube.com/watch?v=fM8yj93X80s;License: Standard YouTube License, CC-BY