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
How to fix this code to work...
from tkinter import *from tkinter import ttkfrom tkinter import messagebox
class Student: def __init__(self, id, fn, ln, dob, m='undefined'): self.id = id self.firstName = fn self.lastName = ln self.dateOfBirth = dob self.major = m
list_of_student = []window = Tk()window.geometry("800x750")window.title("Simple Student Management System")list_of_students = []id = 1001
def add_student(): global list_of_students global id if FirstnameEntry.get() =='': messagebox.showerror('erorr', "First name is required") return if LastnameEntry.get() =='': messagebox.showerror('erorr', "Last name is required") return if DateofbirthEntry.get() =='': messagebox.showerror('erorr', "Date of Birth is required") return if MajorEntry.get() =='': instance = Student(id, FirstnameEntry.get(), LastnameEntry.get(), DateofbirthEntry.get()) else: instance = Student(id, FirstnameEntry.get(), LastnameEntry.get(),…
ExampleTwo
This program loops through fileLoop.txt, computation, and display results
package charioloop;
import java.util.Scanner;
import java.io.*;
//
public class Charioloop {
public static void main(String[] args) throws IOException
{
//Create a reference to the physical file
File loopfile = new File("fileLoop.txt");
// connect a Scanner to the file
Scanner getAll = new Scanner( loopfile );
int num = 0, square = 0;
while(num != -1){
num = getAll.nextInt();
square = num * num ;
System.out.println("The square of " + num + " is " + square);
}
getAll.close();
}
}
/*
Create fileLoop.txt in
I:\\Ajava\161\WPPractice\IO\charstream\charioloop
My fileLoop.txt looks like this:
2
3\
2
10
-1
Note:- Study this program and follow the given instruction and execute type the code and provide also output for this java program as soon as possible.
Java. Refer to attachment.
import java.util.*;
public class PoD{
public static void main( String [] args ) {Scanner in = new Scanner( System.in );FruitBasket fruitBasket = new FruitBasket();
while(in.hasNextLine()){String line = in.nextLine();String[] fruitDetails = line.split(" ");Fruit nextFruit = new Fruit(fruitDetails[0],fruitDetails[1], Double.parseDouble(fruitDetails[2]));fruitBasket.addFruit(nextFruit);}
System.out.println("--- BEFORE SORT ---");System.out.println(fruitBasket);Collections.sort(fruitBasket.basket);System.out.println("--- AFTER SORT ---");System.out.println(fruitBasket);
in.close();System.out.print("END OF OUTPUT");}}
import java.util.*;
public class FruitBasket{//attributesprotected ArrayList<Fruit> basket = new ArrayList<Fruit>();
//constructorpublic FruitBasket(){}//Setterspublic void addFruit(Fruit fruitToAdd){this.basket.add(fruitToAdd);}public String toString(){String basketContents = "FRUIT BASKET:\n";for (Fruit fruit: basket){basketContents…
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
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 (3rd Edition)
Prime Numbers A prime number is a number that is only evenly divisible by itself and 1. For example, the number...
Starting Out with Python (3rd Edition)
Write a line of Java code that will give the name ANSWER to the int value 42. In other words, make answer a nam...
Absolute Java (6th Edition)
State whether each of the following is true or false. If false, explain why. All expression containing the | | ...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
(Multiples of 2 with an Infinite Loop) Write a program that keeps printing the multiples of the integer 2, name...
C How to Program (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
- Java. Refer to attachment. import java.util.*; public class PoD { public static void main( String [] args ) {Scanner in = new Scanner( System.in );FruitBasket fruitBasket = new FruitBasket(); while(in.hasNextLine()){String line = in.nextLine();String[] fruitDetails = line.split(" ");Fruit nextFruit = new Fruit(fruitDetails[0],fruitDetails[1], Double.parseDouble(fruitDetails[2]));fruitBasket.addFruit(nextFruit);} System.out.println("--- BEFORE SORT ---");System.out.println(fruitBasket);Collections.sort(fruitBasket.basket); System.out.println("--- AFTER SORT ---");System.out.println(fruitBasket); in.close();System.out.print("END OF OUTPUT");}} import java.util.*; public class FruitBasket{//attributesprotected ArrayList<Fruit> basket = new ArrayList<Fruit>(); //constructorpublic FruitBasket(){}//Setterspublic void addFruit(Fruit fruitToAdd){this.basket.add(fruitToAdd);}public String toString(){String basketContents = "FRUIT BASKET:\n";for (Fruit fruit: basket)…arrow_forwardI need help with fixing this java program as described in the image below: import java.util.Scanner;import java.io.FileInputStream;import java.io.IOException; public class LabProgram { public static void main(String[] args) throws IOException { Scanner scnr = new Scanner(System.in); // Read the file name from the user String fileName = scnr.nextLine(); // Open the CSV file try (Scanner fileScanner = new Scanner(new FileInputStream(fileName))) { while (fileScanner.hasNextLine()) { // Read each line from the CSV file String line = fileScanner.nextLine(); // Split the line into showtime, title, and rating String[] movieData = line.split(","); // Extract showtime, title, and rating String showtime = movieData[0]; String title = movieData[1].length() > 44 ? movieData[1].substring(0, 44) : movieData[1]; String rating = movieData[2]; // Print the…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_forward
- When coding a program that uses an input file, how would you create a new scanner object as on input file? The name of the input text file is critterinventory.txt.arrow_forwardWrite an application that determines whether the first two files are located in the same folder as the third one. If the files are in the same folder display All files are in the same folder, otherwise display Files are not in the same folder. Test the program when the files are in the same folder and when they are not. import java.nio.file.*; import java.io.IOException; public class CompareFolders { public static void main(String[] args) { Path file1 = Paths.get("/root/sandbox/TestData1.txt"); Path file2 = Paths.get("/root/sandbox/TestData2.txt"); Path file3 = Paths.get("/root/sandbox/test/TestData3.txt"); // Write your code here } }arrow_forwardPlease remove breaks and simplify the code if possible. import java.io.*;import java.util.Scanner; class WindowApp{public static void main(String [] args) {try {Window [] window = read();System.out.println("Creating window data from file data, loading it into an array, and displaying");for (int i= 0; i < window.length; i++) {if(window[i] == null) {break;}System.out.println("--- Window " + i+ ": " + window[i]);window[i].display();System.out.println();}System.out.println("\nTurning on visibility");for (int i= 0; i < window.length; i++) {if(window[i] == null) {break;}System.out.println("--- Window " + i+ ": " + window[i]);window[i].setVisible(true);window[i].displayNormal();System.out.println();}System.out.println("\nResizing (flipping width and height) and displaying");for (int i= 0; i < window.length; i++) {if(window[i] == null) {break;}window[i].resize(window[i].getHeight(), window[i].getWidth());System.out.println("--- Window " + i+ ": " +…arrow_forward
- Please run this program. Thank you import javax.swing.*; import java.awt.*; public class MyProgram {//begin of class public static void main(String [ ] args) {//begin of main Window win = new Window(); }//end of main }//end of class class Window extends JFrame {//begin of JFrame public Window( ) {//begin of window super("Event and Action Listener"); setSize(500,100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); Container ca = getContentPane(); ca.setBackground(Color.lightGray); }//end of window }//end of JFramearrow_forwardThere is an ERROR in this code: import java.util.Scanner; public class TestPhoneBook { public static String lookupName(String targetName, PhoneBook[]anArray){String targetPhoneNumber="";boolean result=false;for (int idx = 0; idx<anArray.length && !result; idx++) { if(anArray[idx].getName().equalsIgnoreCase(targetName)){ ERRORtargetPhoneNumber = anArray[idx].getPhoneNumber(); result=true;} public static void main(String args[]) { ERRORScanner kbd = new Scanner(System.in);PhoneBook[]arrObj = new PhoneBook[3];arrObj[0]= new PhoneBook("John Ficks", "657-9875");arrObj[1]= new PhoneBook("Howard Williams", "908-1001");arrObj[2]= new PhoneBook("George Clemens", "808-5001");System.out.println("Enter name to look up");String targetName = kbd.nextLine(); String targetPhone = lookupName(targetName, arrObj);System.out.println("The phone number is "+targetPhone);}} jAVA 2 CODE: package PhoneBook; public class PhoneBook {String name;String phone_number;PhoneBook(String newName,…arrow_forwardDebug // Program describes two files // tells you which one is newer and which one is larger import java.nio.file.*; import java.nio.file.attribute.*; import java.io.IOException; public class DebugThirteen1 { publicstaticvoidmain(String[] args) { Path file1 = Paths.get("/root/sandbox/DebugDataOne1"); Path file2 = Paths.get("/root/sandbox/DebugDataOne2.txt"); try { BasicFileAttributes attr1 = Files.readAttributes(file1, BasicFileAttributes.class); System.out.println("File: " + file1getFileName()); System.out.println("Creation time " + attr1.creationTime()); System.out.println("Last modified time " + attr1lastModifiedTime()); System.out.println("Size " + attr1.size()); BasicFileAttributes attr2 = Files.readAttributes(file2, BasicFileAttributes.class); System.out.println("\nFile: " + file2.getFileName); System.out.println("Creation time " + attr2.creationTime()); System.out.println("Last modified time " + attr2.lastModifiedTime()); System.out.println("Size " + attr2.size());…arrow_forward
- Write (JAVA) methods for Browser button and Paste button. Browse Button: When user clicks “Browse” Button, a file explorer should open so that user can select an image file. Selected image file must be converted according to the panel_1 size and display on the panel_1 and also file path should be shown on textfield (“txtPath”). Paste Button: When user clicks “Paste” Button, area selected from xmin, xmax, ymin, and ymax textfields will be copied from panel_1 and pasted (or show) in panel_2. Note: Write custom methods if required for your solution.arrow_forwardin java Write code that prints: firstNumber … 2 1Print a newline after each number. Ex: If the input is: 3 the output is: 3 2 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import java.util.Scanner; public class ForLoops { publicstaticvoidmain (String [] args) { intfirstNumber; inti; Scannerinput=newScanner(System.in); firstNumber=input.nextInt(); for () { System.out.println(i); } } }arrow_forwardWrite an application that displays the sizes of the files lyric1.txt and lyric2.txt in bytes as well as the ratio of their sizes to each other. Here is the code so far: import java.nio.file.*; import java.nio.file.attribute.*; import java.io.IOException; public class FileSizeComparison { public static void main(String[] args) { Path textFile = Paths.get("/root/sandbox/lyric1.txt"); Path wordFile = Paths.get("/root/sandbox/lyric2.txt"); // Write your code here } }arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
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