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
// 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");
}
}
option:
myGuess (low, high, scnr );
myGuess (mid, high, scnr);
myGuess(mid + 1, high, scnr);
myGuess(low, mid, scnr);
for the class ArrayAverage write a code that calculates the average of the listed numbers with a double result
for the class ArrayAverageTester write a for each loop and print out the result
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
State whether each of the following is true or false. If false, explain why. Java considers the variables numbe...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Explain why overloaded prefix and postfix and operator functions should return a value.
Starting Out with C++: Early Objects (9th Edition)
What is the purpose of closing a file?
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
The ________ object is assumed to exist and it is not necessary to include it as an object when referring to it...
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Which category of C++ reference variables always produces aliases?
Concepts of Programming Languages (11th Edition)
Write a complete Java program that reads one line of text containing exactly three wordsseparated by any kind o...
Java: An Introduction to Problem Solving and Programming (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
- 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_forwardpublic 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_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_forwardDEUGGING PROBLEM // Prompts user for a size using Scanner // Creates a frame with the specified size // that is twice as tall as wide import javax.swing.*; import java.util.*; public class DebugFourteen1 extends JFrame { public DebugFourteen1(int size) { super("This is my frame"); setSize(size, size + 2); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { Scanner kb = new Scanner(System.in); int size; System.out.print("Enter width for frame >> "); size = kb.nextLine(); DebugFourteen1 frame = new DebugFourteen1(size); frame.setVisible(); } }arrow_forwardUML diagram for the java code below public class CourseDBManager implements CourseDBManagerInterface { private CourseDBStructure dataMgr = new CourseDBStructure(20); public void readFile(File inputFile) throws FileNotFoundException{ try { Scanner fileData = new Scanner(inputFile); while(fileData.hasNext()) { String id = fileData.next(); int crn = fileData.nextInt(); int numCredits = fileData.nextInt(); String roomNum = fileData.next(); String instructor = fileData.nextLine(); add(id, crn, numCredits, roomNum, instructor); } fileData.close(); } catch(FileNotFoundException e) { System.out.print("File not found"); e.getMessage(); } } public void add(String id, int crn, int credits, String roomNum, String instructor) { CourseDBElement newElement = new CourseDBElement(id, crn, credits, roomNum, instructor); dataMgr.add(newElement); } public…arrow_forward
- Question 2. package sortsearchassigncodeex1; import java.util.Scanner; import java.io.*; // // public class Sortsearchassigncodeex1 { // public static void fillArray(Scanner inputFile, int[] arrIn){ int indx = 0; //Complete code { arrIn[indx] = inputFile.nextInt(); indx++; } }arrow_forwardRules: Corner cases. Throw the specified exception for the following corner cases: Throw an IllegalArgumentException if the client calls either addFirst() or addLast() with a null argument. Throw a java.util.NoSuchElementException if the client calls either removeFirst() or removeLast when the deque is empty. Throw a java.util.NoSuchElementException if the client calls the next() method in the iterator when there are no more items to return. Unit testing. Your main() method must call directly every public constructor and method to help verify that they work as prescribed (e.g., by printing results to standard output). Performance requirements. Your implementation must achieve the following worst-case performance requirements: A deque containing n items must use at most 48n + 192 bytes of memory, not including the memory for the items themselves. Each deque operation (including construction) must take constant time. Each iterator operation (including construction) must take…arrow_forwardpublic void actionPerformed(ActionEvent ae) {try {SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH);Date lk1 = from.getDate();Date lk2 = to.getDate();long df = Math.abs(lk1.getTime() - lk2.getTime());long deiffrent = TimeUnit.DAYS.convert(df, TimeUnit.MILLISECONDS);day.setText(String.valueOf(deiffrent));if (day.getText().equals("")) {JOptionPane.showMessageDialog(null, "Day field is empty");return;} int days = Integer.parseInt(day.getText());if (numofroom.getText().equals("")) {JOptionPane.showMessageDialog(null, "Number of rooms field is empty");return;} int room = Integer.parseInt(numofroom.getText()); if (ae.getSource() == studio){ double f = room * 300 * days;String a = String.valueOf(f);double vat1 = f * 0.15;String b = String.valueOf(vat1);double total1 = f + vat1;String c = String.valueOf(total1);if (ae.getSource() == calculate) {ty.setText("STUDIO" + "," + lk1 + "," + lk2);subtotolfield.setText(a);vat_f.setText(b);totolfield.setText(c);}} else if…arrow_forward
- What is printed by the code below? Note: There are two separate classes here. public class SampleClass public void resetVar (int intVar) intVar = 0; public class TestSampleClass public static void main (String[] args) int counter 10; SampleClass myTestClass = new SampleClass(): myTestClass.resetVar (counter): System.out.printin (counter); it doesn't print anything.arrow_forwardWrite a statement that creates a Scanner object named myInput and connects it to the System.in object. javaarrow_forwardpublic String getJoblitle() { return joblitle; 11 12 13 44 45 46 47 48 49 50 public void setJoblitle(String joblitle) { this.jobTitle - joblitle; public int getCurrentEmploynent() { return currentEmploynent; 1. public void selCurrentEnployent (int current Fmployment) { this.currentEmploynent - currentEmployment; 53 54 55 56 -57 goverride public String tostring () { return "CurrentEmploynentStatsclass [areaName=" + arealame + 58 + "year=" + year + ", jobtitle-" + joblitle , currentEnploynent-" + currenttmployment + "]": 59 61 62 63 64 } What algorithm does this method perform? public statie Currentiploynentstatsclass mysteryethod (CurrentEmploynentstatsclass] array) ( int holder = array[0).getCurrenttmploynent(); Currenttmploynentstatsclass variable = array[®]; for(int i- 0, i holder) { holder = holderx; variable - array[1]; return variable; 36. What is the above method returning? 37. What is the Big O time of the above method?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,
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,
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