Starting Out with Java: Early Objects (6th Edition)
6th Edition
ISBN: 9780134462011
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 10, 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 10 Solutions
Starting Out with Java: Early Objects (6th Edition)
Ch. 10.1 - Prob. 10.1CPCh. 10.1 - Prob. 10.2CPCh. 10.1 - Prob. 10.3CPCh. 10.1 - Prob. 10.4CPCh. 10.1 - Prob. 10.5CPCh. 10.1 - Prob. 10.6CPCh. 10.1 - Prob. 10.7CPCh. 10.1 - Prob. 10.8CPCh. 10.1 - Prob. 10.9CPCh. 10.1 - When does the code in a finally block execute?
Ch. 10.1 - What is the call stack? What is a stack trace?Ch. 10.1 - Prob. 10.12CPCh. 10.1 - Prob. 10.13CPCh. 10.1 - Prob. 10.14CPCh. 10.2 - What does the throw statement do?Ch. 10.2 - Prob. 10.16CPCh. 10.2 - Prob. 10.17CPCh. 10.2 - Prob. 10.18CPCh. 10.2 - Prob. 10.19CPCh. 10.3 - What is the difference between a text file and a...Ch. 10.3 - What classes do you use to write output to a...Ch. 10.3 - Prob. 10.22CPCh. 10.3 - What class do you use to work with random access...Ch. 10.3 - What are the two modes that a random access file...Ch. 10.3 - Prob. 10.25CPCh. 10 - Prob. 1MCCh. 10 - Prob. 2MCCh. 10 - Prob. 3MCCh. 10 - Prob. 4MCCh. 10 - FileNotFoundException inherits from __________. a....Ch. 10 - Prob. 6MCCh. 10 - Prob. 7MCCh. 10 - Prob. 8MCCh. 10 - Prob. 9MCCh. 10 - Prob. 10MCCh. 10 - Prob. 11MCCh. 10 - Prob. 12MCCh. 10 - Prob. 13MCCh. 10 - Prob. 14MCCh. 10 - Prob. 15MCCh. 10 - This is the process of converting an object to a...Ch. 10 - Prob. 17TFCh. 10 - Prob. 18TFCh. 10 - Prob. 19TFCh. 10 - True or False: You cannot have more than one catch...Ch. 10 - Prob. 21TFCh. 10 - Prob. 22TFCh. 10 - Prob. 23TFCh. 10 - Prob. 24TFCh. 10 - Find the error in each of the following code...Ch. 10 - // Assume inputFile references a Scanner object,...Ch. 10 - Prob. 3FTECh. 10 - Prob. 1AWCh. 10 - Prob. 2AWCh. 10 - Prob. 3AWCh. 10 - Prob. 4AWCh. 10 - Prob. 5AWCh. 10 - Prob. 6AWCh. 10 - The method getValueFromFile is public and returns...Ch. 10 - Prob. 8AWCh. 10 - Write a statement that creates an object that can...Ch. 10 - Assume that the reference variable r refers to a...Ch. 10 - Prob. 1SACh. 10 - Prob. 2SACh. 10 - Prob. 3SACh. 10 - Prob. 4SACh. 10 - Prob. 5SACh. 10 - Prob. 6SACh. 10 - What types of objects can be thrown?Ch. 10 - Prob. 8SACh. 10 - Prob. 9SACh. 10 - Prob. 10SACh. 10 - What is the difference between a text file and a...Ch. 10 - What is the difference between a sequential access...Ch. 10 - What happens when you serialize an object? What...Ch. 10 - TestScores Class Write a class named TestScores....Ch. 10 - Prob. 2PCCh. 10 - Prob. 3PCCh. 10 - Prob. 4PCCh. 10 - Prob. 5PCCh. 10 - FileArray Class Design a class that has a static...Ch. 10 - File Encryption Filter File encryption is the...Ch. 10 - File Decryption Filter Write a program that...Ch. 10 - TestScores Modification for Serialization Modify...Ch. 10 - Prob. 11PC
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What is denormalization?
Database Concepts (8th Edition)
Define a method hypotenuse that calculates the hypotenuse of a right triangle when the lengths of the other two...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
If a method in a subclass has the same name as a method in the superclass, but uses a different parameter list,...
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Repeat Exercise 1 for a collection of coins instead of a credit card. Design a class to represent a credit card...
Java: An Introduction to Problem Solving and Programming (8th Edition)
What is the fundamental mechanism of chip formation?
Degarmo's Materials And Processes In Manufacturing
The ____________ is always transparent.
Web Development and Design Foundations with HTML5 (8th 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