Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
7th Edition
ISBN: 9780134802213
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 11, Problem 16MC
This is the process of converting an object to a series of bytes that represent the object’s data.
- a. serialization
- b. deserialization
- c. dynamic conversion
- d. casting
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Modify the code to read integer values from the keyboard, store them into a 15 element array, then write the array into a file named userin.txt
CODE
import java.util.Scanner;import java.io.*;
public class Storeintoarr {
public static void main(String[] args) throws IOException { File loopfile = new File("fileLoop.txt"); Scanner getAll = new Scanner( loopfile ); // connect a Scanner to the file int num = 0, square = 0; int[] items = new int[10]; int i = 0; while(getAll.hasNextInt()){ num = getAll.nextInt(); square = num * num ; //System.out.println("The square of " + num + " is " + square); items[i] = num; System.out.println("items[i] is " + items[i]); i = i + 1; } getAll.close(); }}
I just need help creating this Java code as described below in the image:
import java.util.Scanner;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.PrintWriter;import java.io.IOException;
public class LabProgram { public static void main(String[] args) throws IOException { Scanner scnr = new Scanner(System.in); /* TODO: Declare any necessary variables here. */ /* TODO: Read a file name from the user and read the tsv file here. */ /* TODO: Compute student grades and exam averages, then output results to a text file here. */ }}
i am having trouble with my code,
I believe I need to change the bold information but don't know what to replace it with in order to display my required output
import java.io.*;import java.util.*;
public class AccountBalance { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); List<Account> list = new ArrayList<>(); try { FileInputStream file = new FileInputStream("accounts-with-names.dat"); DataInputStream input = new DataInputStream(file); // Read data from the file and store it in an array or list here
while (input.available() > 0) { String name = input.readUTF(); long accountNumber = input.readLong(); double balance = input.readDouble(); boolean cashBack = input.readBoolean(); Account acc = new Account(name, accountNumber, balance, cashBack); list.add(acc); }…
Chapter 11 Solutions
Starting Out with Java: From Control Structures through Objects (7th 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
A new class of objects can be created conveniently bythe new class (called the subclass) starts with the charac...
Java How To Program (Early Objects)
Type in and run the 12 programs presented in this chapter. Compare the output produced by each program with the...
Programming in C
Give an example of a data constraint.
Database Concepts (8th Edition)
How many hello output lines does this program print?
Computer Systems: A Programmer's Perspective (3rd Edition)
A subclass can have a method with the same name as a method in the superclass.
Starting Out with Python (3rd Edition)
Average Rainfall Write a program that calculates the average monthly rainfall for three months. The program sho...
Starting Out with C++: Early Objects
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
- 1. Modify it so that it write the contents of String[] into a file named fileLoop1.txt: package stringio; // // import java.util.Scanner; import java.io.*; // public class Stringio { // public static void main(String[] args) throws IOException { File loopfile = new File("fileLoop.txt"); Scanner getAll = new Scanner( loopfile ); // connect a Scanner to the file String num; String[] items = new String[10]; int i = 0; while(getAll.hasNextLine()){ num = getAll.nextLine(); // square = num * num ; //System.out.println("The square of " + num + " is " + square); items[i] = num; System.out.println("items[i] is " + items[i]); i = i + 1; } getAll.close(); } }arrow_forwardOutput to a file can be achieved with a _____ object, which is constructed with a File and has the same methods as System.out (the class name is case sensitive)(Just Words)arrow_forwardI have this homework where I have to search a word in a file and count how many words in and how long takes to find it. My code working well but counts the empty lines as words and I don't want the empty lines to be counted . would you look at it and see what I can add to it so the code will not count the empty lines in the file. Here the code import java.io.File;import java.io.FileNotFoundException;//scanner class for user inputimport java.util.Scanner;public class Uppgift2 {//main functionpublic static void main(String[] args) {//string to store input file nameString input_file;//check if argument is passed in command lineif (args.length == 0) {//if arg. is not passed initialise file to wordlist1.txtinput_file = "wordlist1.txt";} else {//else store the argumentinput_file = args[0];}try {//opening file in read modeFile fp = new File(input_file);//scanner object for input fileScanner scan = new Scanner(fp);//scanner object to take word inputScanner search = new…arrow_forward
- Write 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_forwardSO I NEED INPUTTING THIS FILE FOR THE OUTPUT TO BE THE SAME AS THE INCLUDED DOCUMENT. I POSTED THE FILE AT THE BOTTOM OF THE CODE TOO. import java.io.File;import java.io.FileNotFoundException;import java.util.ArrayList;import java.util.Scanner; public class WordCount {//______________________public static ArrayList<String> readFile(String fileName) throws FileNotFoundException {ArrayList<String> list=new ArrayList<String>();File file=new File(fileName);Scanner sc=new Scanner(file);String word;while(sc.hasNext()) {word=sc.next();list.add(word);}sc.close();return list;}//______________________public static int differentWords(ArrayList<String> list) {for(int i=0;i<list.size();i++) {for(int j=0;j<list.size();j++) {if(list.get(i).equals(list.get(j)))list.remove(j);}}return list.size();}//_______________________public static void sort(ArrayList<String> list) {int i,j;String key;int n=list.size();for (i = 1; i < n; i++){key = list.get(i);j = i - 1;while…arrow_forwardHey, this is my code below and I cannot seem to get the import.java.io.*; to create and save information on a txt file. Any help would be great. There is a person class with get and set for firstname, lastname, etc. However I could not fit it in due to space. Code in bold is what I tried for the txt. import java.io.FileNotFoundException;import java.io.PrintWriter;import java.util.ArrayList;import java.util.Scanner; import mainInterface.Interface; public class StaffManager { protected static ArrayList<Staff> Staffs = new ArrayList<Staff>(); public static void main(String[] args) throws FileNotFoundException{ staffManMenu(); //Call writeToFile writeToFile(); } // method to write the staff data to a file titled StaffFile.txt public static void writeToFile() throws FileNotFoundException{ //create object PrintWriter write = new PrintWriter(new File("StaffData.txt")); for(Staff s : Staffs) { write.println("First Name: "…arrow_forward
- PLZ help with the following IN JAVA There are two common classes used for reading from a text file. They are: PrintWriter and BufferedReader FileInputStream and Scanner BufferedReader and Scanner None of the abovearrow_forwardHow to read to and from a text file in JAVA so the user can close the program and pick up where they left off when opening again.arrow_forwardplease edit this code so it does not contain breaks, while(true) and BufferedReader. Also keep getting this error " *** IOException *** phonebook.text (No such file or directory) the desired output has been given in the picture. here is the code to edit: import java.io.*; import java.util.Scanner; public class Phonebook { public static void main(String[] args) { int lookupCount = 0; int revLookupCount = 0; int phoneEntryCount = 0; Scanner inputReader = new Scanner(System.in); try { File file = new File("phonebook.txt"); BufferedReader phonebookReader; PhonebookEntry phonebookEntry[] = new PhonebookEntry[100]; phonebookReader = new BufferedReader(new FileReader(file)); String line = phonebookReader.readLine(); while (line != null) { if (phoneEntryCount >= 100) { throw new Exception( "Phonebook capacity exceeded - increase size of underlying array"); } phonebookEntry[phoneEntryCount++] = new PhonebookEntry(line); line = phonebookReader.readLine(); } phonebookReader.close(); mainLoop:…arrow_forward
- B3- Write a Python program that reads the marks from a file named marks.txt and then increments each mark by 5 and saves the updated marks in a new file called updatedMarks.txt. You can assume that the marks are written on a separate line each in the marks.txt file. Finally, read the new marks from the new file and print them to the output screen.arrow_forwardthis file is named HW3.Java can someone run it through a GNU compiler and please show me the outputs the input arguements are $ java HW3 p1 p1.txt 6 import java.io.FileWriter;import java.io.IOException;public class HW3 {public static void main(String[] args) throws IOException {// 0th argument contains the name of algorithmString algo = args[0];// 1st argument contains the name of file// Make a new fileFileWriter fw = new FileWriter(args[1]);if (algo.equals("p1")) {// 2nd argument comes in the form of string.// convert it to intger and run a loopfor (int i = 1; i <= Integer.parseInt(args[2]); i++) {double[] x = new double[(int) Math.pow(10, i)];// use start and end for recording timelong start = System.currentTimeMillis();prefixAverage1(x);long end = System.currentTimeMillis();double totalTime = Math.log10(end - start);fw.write(String.valueOf(totalTime));String newLine = System.getProperty("line.separator");fw.write(newLine);}} else if (algo.equals("p2")) {for (int i = 1; i <=…arrow_forwardWrite a java program in a single file that: Main: Creates 10 random doubles, all between 1 and 11, Calls a method that writes 10 random doubles to a text file, one number per line. Calls a method that reads the text file and displays all the doubles and their sum accurate to two decimal places.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
C - File I/O; Author: Tutorials Point (India) Ltd.;https://www.youtube.com/watch?v=cEfuwpbGi1k;License: Standard YouTube License, CC-BY
file handling functions in c | fprintf, fscanf, fread, fwrite |; Author: Education 4u;https://www.youtube.com/watch?v=aqeXS1bJihA;License: Standard Youtube License