New Semester
Started
Get
50% OFF
Study Help!
--h --m --s
Claim Now
Question Answers
Textbooks
Find textbooks, questions and answers
Oops, something went wrong!
Change your search query and then try again
S
Books
FREE
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Tutors
Online Tutors
Find a Tutor
Hire a Tutor
Become a Tutor
AI Tutor
AI Study Planner
NEW
Sell Books
Search
Search
Sign In
Register
study help
computer science
java an introduction to problem solving and progra
Java An Introduction To Problem Solving And Programming 8th Edition Walter Savitch - Solutions
Modify the program in the previous exercise so that it reads the name of the file from the keyboard.Previous exerciseWrite a program that will write the Gettysburg Address to a text file. Place each sentence on a separate line of the file.
Write a program similar to the one in Listing 10.10 that can write an arbitrary number of Species objects to a binary file. (Species appears in Listing 5.19 of Chapter 5.) Read the file name and the data for the objects from a text file that you create by using a text editor. Then write another
Write some code that asks the user to enter either of the words append or new. According to the user response, open either an existing text file to which data can be appended or a new, empty text file to which data can be written. In either case, the file’s name is a string given by the variable
Write a program that reads from a file created by the program in the previous programming project and displays the following information on the screen: the data for the species having the smallest population and the data for the species having the largest population. Do not assume that the objects
Write a program that will record the purchases made at a store. For each purchase, read from the keyboard an item’s name, its price, and the number bought. Compute the cost of the purchase (number bought times price), and write all this data to a text file. Also, display this information and the
Programming Project 2 asks you, among other things, to write a program that creates a binary file of objects of the class Species. Write a program that reads from a file created by that program and writes the objects to another file after modifying their population figures as they would be in 100
Modify the class LapTimer, as described in Exercise 13 of Chapter 9, as follows:Add an attribute for a file stream to which we can write the timesAdd a constructorLapTimer(n, person, fileName)for a race having n laps. The name of the person and the file to record the times are passed to the
Text messaging is a popular means of communication. Many abbreviations are in common use but are not appropriate for formal communication. Suppose the abbreviations are stored, one to a line, in a text file named abbreviations.txt. For example, the file might contain these
Write a class TelephoneNumber that will hold a telephone number. An object of this class will have the attributesareaCode—a three-digit integerexchangeCode—a three-digit integernumber—a four-digit integerand the methodsTelephoneNumber(aString)—a constructor that creates and returns a new
Modify the TelephoneNumber class described in Exercise 6 so that it is serializable. Write a program that creates an array whose base type is TelephoneNumber by reading data from the keyboard. Write the array to a binary file using the method writeObject. Then read the data from the file using the
Write a class ContactInfo to store contact information for a person. It should have attributes for a person’s name, business phone, home phone, cell phone, e-mail address, and home address. It should have a toString method that returns this data as a string, making appropriate replacements for
Revise the class Pet, as shown in Listing 6.1 of Chapter 6, so that it is serializable. Write a program that allows you to write and read objects of type Pet to a file. The program should ask the user whether to write to a file or read from a file. In either case, the program next asks for the file
Write a program that reads every line in a text file, removes the first word from each line, and then writes the resulting lines to a new text file.
Write a program that reads records of type Pet from a file created by the program described in the previous programming project and displays the following information on the screen: the name and weight of the heaviest pet, the name and weight of the lightest pet, the name and age of the youngest
Repeat the previous exercise, but write the new lines to a new binary file instead of a text file.Previous exerciseWrite a program that reads every line in a text file, removes the first word from each line, and then writes the resulting lines to a new text file.
Write a program that will make a copy of a text file, line by line. Read the name of the existing file and the name of the new file—the copy—from the keyboard. Use the methods of the class File to test whether the original file exists and can be read. If not, display an error message and abort
In many races competitors wear a RFID tag on their shoes or bibs. When the racer crosses a sensor a computer logs the racer’s number along with the current time. Sensors can be placed along the course to accurately calculate the racer’s finish time or pace and also to verify that the racer
Suppose you are given a text file that contains the names of people. Every name in the file consists of a first name and last name. Unfortunately, the programmer who created the file of names had a strange sense of humor and did not guarantee that each name was on a single line of the file. Read
Based on the log file described in Programming Project 10 write a program to detect cheating.This could occur if:A racer misses a sensor, which is a sign that the racer may have taken a shortcut.A race split is suspiciously fast, which is a sign that the racer may have hopped in a vehicle.In this
Suppose that you have a binary file that contains numbers whose type is either int or double. You don’t know the order of the numbers in the file, but their order is recorded in a string at the beginning of the file. The string is composed of the letters i (for int) and d (for double) in the
Write a Java program that serves as a primitive web browser. For this assignment it merely needs to input a server name and display the HTML that is sent by the web server. A web server normally listens on port 80. Upon connection the server expects to be sent a string that identifies what web page
Suppose that we want to store digitized audio information in a binary file. An audio signal typically does not change much from one sample to the next. In this case, less memory is used if we record the change in the data values instead of the actual data values. We will use this idea in the
Repeat any of the previous programming projects using a JavaFX graphical user interface.Previous programming projectsWrite a Java program that serves as a primitive web browser. For this assignment it merely needs to input a server name and display the HTML that is sent by the web server. A web
Write a program RecoverSignal that will read the binary file written by StoreSignal, as described in the previous exercise. Display the integer values that the data represents on the screen.
Write a JavaFX application that uses a text field to get the name of a file, reads the file byte by byte, and displays the bytes as characters. (Exercise 15 describes how to convert a byte value to a character.) Display the first 20 characters in a label. If a byte does not correspond to a legal
Even though a binary file is not a text file, it can contain embedded text. To find out if this is the case, write a program that will open a binary file and read it one byte at a time. Display the integer value of each byte as well as the character, if any, that it represents in ASCII.Technical
A palindrome is a string that reads the same forward and backward, such as "radar". Write a static recursive method that has one parameter of type String and returns true if the argument is a palindrome and false otherwise. Disregard spaces and punctuation marks in the string, and consider upper-
What output will be produced by the following code?public class Demo{public static void main(String[] args){System.out.println("The output is:");foo(23);System.out.println();}public static void foo(int number){if (number > 0){foo(number / 2);System.out.print(number % 2);}}}
What output will be produced by the following code?public class Demo{public static void main(String[] args){System.out.println("The output is:");bar(11156);System.out.println();}public static void bar(int number){if (number > 0){int d = number % 10;boolean odd = (number / 10) % 2 == 1;bar(number
Write a recursive method that will compute the number of odd digits in a number.
The Fibonacci sequence occurs frequently in nature as the growth rate for certain idealized animal populations. The sequence begins with 0 and 1, and each successive Fibonacci number is the sum of the two previous Fibonacci numbers. Hence, the first ten Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8,
Write a recursive method that will compute the sum of the digits in a positive number.
Imagine a candy bar that has k places where it can be cut. You would like to know how many different sequences of cuts are possible to divide the bar into pieces. For example, if k is 3, you could cut the bar at location 1, then location 2, and finally at location 3. We indicate this sequence of
Once upon a time in a kingdom far away, the king hoarded food and the people starved. His adviser recommended that the food stores be used to help the people, but the king refused. One day a small group of rebels attempted to kill the king but were stopped by the adviser. As a reward, the adviser
Write a recursive method that will compute the sum of all the values in an array.
Write a recursive method that will find and return the largest value in an array of integers. Split the array in half and recursively find the largest value in each half. Return the larger of those two values.
Given the definition of a 2D array such as the following:String[][] data = {{"A","B"},{"1","2"},{"XX","YY","ZZ"}};write a recursive program that outputs all combinations of each subarray in order. In the above example, the desired output (although it doesn’t have to be in this order) is:A 1 XXA 1
Write a recursive ternary search algorithm that splits the array into three parts instead of the two parts used by a binary search.
Write a recursive method that will compute cumulative sums in an array. To find the cumulative sums, add to each value in the array the sum of the values that precede it in the array. For example, if the values in the array are [2, 3, 1, 5, 6, 2, 7], the result will be [2, (2) + 3, (2 + 3) + 1, (2
A description of the File class is available on Oracle’s Java Web site at http:// docs.oracle.com/javase/7/docs/api/java/io/File.html. To use this class you must import java.io.File. For this program the relevant methods of the File class are described below:Write the static recursive method
Suppose we want to compute the amount of money in a bank account with compound interest. If the amount of money in the account is m, the amount in the account at the end of the month will be 1.005m. Write a recursive method that will compute the amount of money in an account after t months with a
Create a JavaFX application that will draw a fractal curve using line segments. Fractals are recursively defined curves. The curve you will draw is based on a line segment between points p and p :To draw the curve from p to p , you first split the segment into thirds. Then add two segments and
Suppose we have a satellite in orbit. To communicate to the satellite, we can send messages composed of two signals: dot and dash. Dot takes 2 microseconds to send, and dash takes 3 microseconds to send. Imagine that we want to know the number of different messages, M(k), that can be sent in k
Do Programming Project 17 from Chapter 4, the Edoc calculator, except use a recursive function to calculate or help you calculate the maximum amount of experience points you can earn.Project 17 from Chapter 4You have an augmented reality game in which you catch Edoc and acquire Edoc candy. You need
Write a recursive method that will count the number of vowels in a string. Each time you make a recursive call, use the String method substring to construct a new string consisting of the second through last characters. The final call will be when the string contains no characters.
Do Programming Project 9 from Chapter 8 using lambda functions to implement the button click events.Programming Project 9Create a JavaFX application that acts as a simple calculator. Create buttons for digits 0-9 and a text field that concatenates digits for the current number as the buttons are
Write a recursive method that will remove all the vowels from a given string and return what is left as a new string. Use the + operator to perform string concatenation to construct the string that is returned.
Write a recursive method that will duplicate each character in a string and return the result as a new string. For example, if "book" is the argument, the result would be "bbooookk".
Write a recursive method that will reverse the order of the characters in a given string and return the result as a new string. For example, if "book" is the argument, the result would be "koob".
Repeat Exercise 2 in Chapter 7, but use an instance of ArrayList instead of an array. Do not read the number of values, but continue to read values until the user enters a negative value.Exercise 2 in Chapter 7Write a program in a class CountFamiles that counts the number of families whose income
Write a program that creates Pet objects from data read from the keyboard. Store these objects into an instance of ArrayList. Then sort the Pet objects into alphabetic order by pet name, and finally display the data in the sorted Pet objects on the screen. The class Pet is given in Chapter 6,
Repeat Exercise 3 in Chapter 7, but use an instance of ArrayList instead of an array. Do not read the number of families, but read data for families until the user enters the word done.Exercise 3 in Chapter 7Write a program in a class CountPoor that counts the number of families that are considered
Repeat the previous programming project, but sort the Pet objects by pet weight instead of by name. After displaying the sorted data on the screen, write the number and percentage of pets that are under 5 pounds, the number and percentage of pets that are 5 to 10 pounds, and the number and
Repeat Exercise 5 in Chapter 7, but use an instance of ArrayList instead of an array.Exercise 5 in Chapter 7Write a program in a class CharacterFrequency that counts the number of times a digit appears in a telephone number. Your program should create an array of size 10 that will hold the count
Repeat the previous programming project, but read the input data from a file and send the output to another file. If you have covered binary files, use binary files; otherwise, use text files. Read the file names from the user.Previous programming projectRepeat the previous programming project, but
Repeat Exercises 6 and 7 in Chapter 7, but use an instance of ArrayList instead of an array. We will no longer need to know the maximum number of sales, so the methods will change to reflect this.Exercises 6 and 7 in Chapter 7Define the following methods for the class Ledger, as described in the
Use the class ClassObjectIODemo shown in Listing 10.10 of Chapter 10 to create a file of Species objects. The class Species is given in Chapter 10, Listing 10.9. Then write a program that reads the Species objects from the file you created into an instance of ArrayList, sorts these instances
Write a static method removeDuplicates(ArrayList data) that will remove any duplicates of characters in the object data. Always keep the first copy of a character and remove subsequent ones.
Define a variation on StringLinkedListSelfContained from Listing 12.7 that stores objects of type Species, rather than of type String. Write a program that uses that linked-list class to create a linked list of Species objects, asks the user to enter a Species name, and then searches the linked
Write a static methodgetCommonStrings(ArrayList list1,ArrayList list2)that returns a new instance of ArrayList containing all of the strings common to both list1 and list2.
Repeat the previous programming project, but read the input data from a file and send the output to another file. If you have covered binary files, use binary files; otherwise, use text files. Read the file names from the user.Previous programming projectDefine a variation on
Write a program that will read sentences from a text file, placing each sentence in its own instance of ArrayList. (You will create a sentence object by adding words to it one at a time as they are read.) When a sentence has been completely read, add the sentence to another instance of ArrayList.
Define a variation on StringLinkedListSelfContained from Listing 12.7 that stores objects of type Employee, rather than objects of type String. Write a program that uses this linked-list class to create a linked list of Employee objects, asks the user to enter an employee’s Social Security
Repeat Exercise 12 in Chapter 7, but use an instance of ArrayList instead of an array. Make the following slight changes to the methods to reflect that an ArrayList object can grow in size:Change the constructor’s parameter from the maximum degree to the desired degree.The method setConstant
Repeat the previous programming project, but read the input data from a file and send the output to another file. If you have covered binary files, use binary files; otherwise, use text files. Read the file names from the user.Previous programming projectDefine a variation on
Write a program that will read a text file that contains an unknown number of movie review scores. Read the scores as Double values and put them in an instance of ArrayList. Compute the average score.
Write a parameterized class definition for a doubly linked list that has a parameter for the type of data stored in a node. Make the node class an inner class. Choosing which methods to define is part of this project. Also, write a program to thoroughly test your class definition.
Revise the class StringLinkedList in Listing 12.5 so that it can add and remove items from the end of the list.Listing 12.5public class StringLinkedList{private ListNode head;public StringLinkedList(){head = null;}/**Displays the data on the list.*/public void showList(){ListNode position =
Create an application that will keep track of several groups of strings. Each string will be a member of exactly one group. We would like to be able to see whether two strings are in the same group as well as perform a union of two groups. Use a linked structure to represent a group of strings.
Suppose we would like to create a data structure for holding numbers that can be accessed either in the order that they were added or in sorted order. We need nodes having two references. If you follow one trail of references, you get the items in the order they were added. If you follow the other
For this project, we will create a data structure known as a queue. A queue can be thought of as a line. Items are added at the end of the line and are taken from the front of the line. You will create a class LinkedQueue based on one of the linked-list classes given in this chapter. It should have
Draw a picture of an initially empty data structure, as described in the previous exercise, after adding the numbers 2, 8, 4, and 6, in this order.
Repeat the previous programming project, but use a circular linked list to implement the queue. Recall from Figure 12.10 that a circular linked list has one external reference, which is to the list’s last node.Previous programming projectFor this project, we will create a data structure known as
Write some code that will use an iterator to duplicate every item in an instance of StringLinkedListWithIterator in Listing 12.9. For example, if the list contains "a", "b", and "c", after the code runs, it will contain "a", "a", "b", "b", "c", and "c".Listing 12.9./**Linked list with an iterator.
Suppose that we would like to perform a bird survey to count the number of birds of each species in an area. Create a class BirdSurvey that is like one of the linked-list classes given in this chapter. (The linked list you use will affect what your new class can do, so give some thought to your
Consider a text file of names, with one name per line, that has been compiled from several different sources. A sample is shown below:Brooke TroutDinah SoarsJed DyeBrooke TroutJed DyePaige TurnerThere are duplicate names in the file. We would like to generate an invitation list but don’t want to
Write some code that will use an iterator to interchange the items in every pair of items in an instance of StringLinkedListWithIterator in Listing 12.9. For example, if the list contains "a", "b", "c", "d", "e", and "f", after the code runs, it will contain "b", "a", "d", "c", "f", and "e". You
You have a list of student ID’s followed by the course number (separated by a space) that the student is enrolled in. The listing is in no particular order. For example, if student 1 is in CS100 and CS200 while student 2 is in CS105 and MATH210 then the list might look like this:1 CS1002 MATH2102
The class StringLinkedListWithIterator (Listing 12.9) is its own iterator, but it does not quite implement the Java Iterator interface. Redefine the class StringLinkedListWithIterator so that it implements the Iterator interface. This interface declares the methods next, remove, and hasNext as
Write a program that creates two instances of the generic class LinkedList given in Listing 12.12. The first instance is stadiumNames and will hold items of type String. The second instance is gameRevenue and will hold items of type Double. Within a loop, read data for the ball games played during
Write a program that checks a text file for several formatting and punctuation matters. The program asks for the names of both an input file and an output file. It then copies all the text from the input file to the output file, but with the following two changes: (1) any string of two or more
Write a program that will write the Gettysburg Address to a text file. Place each sentence on a separate line of the file.
Show the modifications needed to add exponentiation to the class Calculator in Listing 9.12. Use ^ to indicate the exponentiation operator and the method Math.pow to perform the computation.Listing 9.12. import java.util.Scanner; /** Simple line-oriented calculator program. The class can also be
Write an application that implements a trip-time calculator. Define and use a class TripComputer to compute the time of a trip. TripComputer should have the private attributestotalTime—the total time for the triprestStopTaken—a boolean flag that indicates whether a rest stop has been taken at
Revise the class RoomCounter described in the previous exercise to use an assertion instead of an exception to prevent the number of people in the room from becoming negative.Previous exerciseSuppose that you are going to create an object used to count the number of people in a room.We know that
Suppose that you are in charge of customer service for a certain business. As phone calls come in, the name of the caller is recorded and eventually a service representative returns the call and handles the request. Write a class ServiceRequests that keeps track of the names of callers. The class
Suppose that you are going to create an object used to count the number of people in a room.We know that the number of people in the room can never be negative. Create a RoomCounter class having three public methods:addPerson—adds one person to the roomremovePerson—removes one person from
Write a JavaFX program that moves an image toward the location of the mouse. The image shouldn’t jump directly to the mouse coordinates (which is what happens in Listing 9.16) but should move a few pixels toward the mouse location every time cycle. You can choose the time cycle to control the
Revise the class Rational described in the previous exercise to use an assertion instead of an exception to guarantee that the denominator is never zero.Previous exerciseCreate a class Rational that represents a rational number. It should have private attributes forThe numerator (an integer)The
Modify the Bouncing Ball example from Listing 9.18, except instead of animating a red circle, animate an image of your choice.Listing 9.18import javafx.application.Application;import javafx.scene.canvas.Canvas;import javafx.scene.Scene;import javafx.stage.Stage;import
Create a class Rational that represents a rational number. It should have private attributes forThe numerator (an integer)The denominator (an integer) and the following methods:Rational(numerator, denominator)—a constructor for a rational number.Accessor methods getNumerator and getDenominator
Create a JavaFX application that implements a short survey. The first question should ask the user for his or her favorite color and present the choices “red”, “orange”, “blue”, and “green” in radio buttons. The second question should ask the user for his or her age and present the
Create a class SongCard that represents a gift card for the purchase of songs online. It should have the following private attributes:songs—the number of songs on the cardactivated—true if the card has been activatedand the following methods:SongCard(n)—a constructor for a card with n
Write a program to enter employee data, including Social Security number and salary, into an array. The maximum number of employees is 100, but your program should also work for any number of employees less than 100. Your program should use two exception classes, one called SSNLengthException for
Write code that reads a string from the keyboard and uses it to set the variable myTime of type TimeOfDay from the previous exercise. Use try-catch blocks to guarantee that myTime is set to a valid time.Previous exercise.Write a class TimeOfDay that uses the exception classes defined in the
Define an exception class called DimensionException to use in the driver program from Programming Project 4 in Chapter 8. Modify that driver program to throw and catch a DimensionException if the user enters something less than or equal to zero for a dimension.Programming Project 4 in Chapter
Write a class TimeOfDay that uses the exception classes defined in the previous exercise. Give it a method setTimeTo(timeString) that changes the time if timeString corresponds to a valid time of day. If not, it should throw an exception of the appropriate type.Previous exercise.Derive exception
Modify the driver program from Practice Program 3 in Chapter 8 to use three exception classes called CylinderException, LoadException, and TowingException. The number of cylinders must be an integer from 1 to 12, the load capacity must be a number from 1 to 10 (possibly with a fractional part), and
Derive exception classes from the class you wrote in the previous exercise. Each new class should indicate a specific kind of error. For example, InvalidHourException could be used to indicate that the value entered for hour was not an integer in the range 1 to 12.Previous exercise. Write an
Write a program that converts dates from numerical month-day format to alphabetic month-day format. For example, input of 1/31 or 01/31 would produce January 31 as output. The dialogue with the user should be similar to that shown in Programming Project 2. You should define two exception classes,
Showing 100 - 200
of 407
1
2
3
4
5
Step by Step Answers