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 programming
Big Java, Enhanced Early Objects 7th Edition Cay S Horstmann - Solutions
Make an XML document describing a book, with child elements for the author name, the title, and the publication year.
Add a description of the book’s language to the document of Exercise • R25.5. Should you use an element or an attribute?Data from exercise R25.5 Make an XML document describing a book, with child elements for the author name, the title, and the publication year.
What is mixed content? What problems does it cause?
Design an XML document that describes a purse containing three quarters, a dime, and two nickels.
Explain why a paint program, such as Microsoft Paint, is a WYSIWYG program that is also “what you see is all you’ve got”.
Consider the XML fileWhat are the values of the following XPath expressions?a. /purse/coin[1]/valueb. /purse/coin[2]amec. /purse/coin[2]ame/@langd. name(/purse/coin[2]/*[1])e. count(/purse/coin)f. count(/purse/coin[2]ame) 0.5 half dollar 0.25 quarter
With the XML file of Exercise •• R25.10 , give XPath expressions that yielda. the value of the first coin.b. the number of coins.c. the name of the first child element of the first coin element.d. the name of the first attribute of the first coin’s name element. (The expression @* selects the
Harry Hopeless doesn’t want to build a DOM tree to produce an XML document.Instead, he uses the following code: System.out.println(" "); for (LineItem anItem: items) { Product p = anItem.getProduct(); System.out.println("
Design a DTD that describes a bank with bank accounts.
Design a DTD that describes a library patron who has checked out a set of books.Each book has an ID number, an author, and a title. The patron has a name and telephone number.
Write the DTD file for the following XML document Comtrade Tornado 2495 60 AMAX Powerstation 75 2999 62
Design a DTD for invoices, as described in How To 25.3.Data from how to 25.3 Rams 1 3. LESENE 2212 HOW TO 25.3 Writing a DTD You write a DTD to describe a set of XML documents of the same type. The DTD specifies which elements contain child elements (and the order in which they may appear) and
Design a DTD for simple English sentences, as described in Special Topic 25.1.Data from special topic 25.1 Special Topic 25.1 Grammars, Parsers, and Compilers Grammars are very important in many areas of computer science to describe the structure of computer programs or data formats. To introduce
Design a DTD for arithmetic expressions, as described in Special Topic 25.1.Data from special topic 25.1 Special Topic 25.1 Grammars, Parsers, and Compilers Grammars are very important in many areas of computer science to describe the structure of computer programs or data formats. To introduce the
Write a program that can read XML files, such as: 0.5 half dollar Your program should construct a Purse object and print the total value of the coins in the purse.
Building on Exercise •• E25.1 , make the program read an XML file as described in that exercise. Then print an XML file of the form Data from exercise E25.1 Write a program that can read XML files, such as: 0.5 half dollar 3 0.25 quarter 2
Repeat Exercise •• E25.1 , using a DTD for validation.Data from exercise E25.1 Write a program that can read XML files, such as: 0.5 half dollar Your program should construct a Purse object and print the total value of the coins in the purse.
Write a program that can read XML files, such as:Your program should construct a Bank object and print the total value of the balances in the accounts. 3 1295.32
Repeat Exercise •• E25.4 , using a DTD for validation.Data from exercise E25.4 Write a program that can read XML files, such as: 3 1295.32
Enhance Exercise •• E25.4 as follows: First read the XML file in, then add ten percent interest to all accounts, and write an XML file that contains the increased account balances.Data from exercise E25.4 Write a program that can read XML files, such as: 3 1295.32
Write a DTD file that describes documents that contain information about countries: name of the country, its population, and its area. Create an XML file that has five different countries. The DTD and XML should be in different files. Write a program that uses the XML file you wrote and prints:•
Write a parser to parse invoices using the invoice structure described in How To 25.1. The parser should parse the XML file into an Invoice object and print out the invoice in the format used in Chapter 12.Data from how to 25.1 ww M Curst SPO HOW TO 25.1 Designing an XML Document Format This How To
Modify Exercise •• P25.2 to support separate shipping and billing addresses. Supply a modified DTD with your solution.Data from exercise P25.2Write a parser to parse invoices using the invoice structure described in How To 25.1. The parser should parse the XML file into an Invoice object and
Write a document builder that turns an invoice object, as defined in Chapter 12, into an XML file of the format described in How To 25.2.Data from how to 25.2 M cars C HOW TO 25.2 Writing an XML Document What is the best way to write an XML document? This How To shows you how to produce a Document
Modify Exercise •• P25.4 to support separate shipping and billing addresses.Data from exercise P25.4Write a document builder that turns an invoice object, as defined in Chapter 12, into an XML file of the format described in How To 25.2.
Write a program that can read an XML document of the form 5 10 20 30 and draw the shape in a window.
Write a program that can read an XML document of the form 5 10 20 30 and draw the shape in a window.
Write a program that can read an XML document of the form 5 10 20 30 Support shape attributes "rectangle", "round rectangle", and "ellipse". Draw the shape in a window.
Write a program that can read an XML document of the form 5 10 and draw the shape in a window.
Write a program that can read an XML document of the form 5 10 20 30 5 10 25 40 Hello, World! 20 30 and show the drawing in a window.
Repeat Exercise ••• Graphics P25.10, using a DTD for validation.Data from Exercise P25.10Write a program that can read an XML document of the form: 5 10 20 30 5 10 25 40 Hello, World! 20 30 and show the drawing in a window.
Following Exercise P12.2 , design an XML format for the appointments in an appointment calendar. Write a program that first reads in a file with appointments, then another file of the formatData from Exercise P12.2Write a program to design an appointment calendar. An appointment includes the date,
Modify the LargestInArray.java program in Section 7.3.10 to mark both the smallest and the largest elements.
Add a method removeMin to the student class of Section 7.4 that removes the minimum score without calling other methods.Data from section 7.4
Write a method that implements the algorithm developed in Section 7.5.Data from section 7.5Manipulating physical objects can give you ideas for discovering algorithms.
Write a class DataSet that stores a number of values of type double. Provide a constructor public DataSet(int maximumNumberOfValues) and a method public void add(double value) that adds a value, provided there is still room. Provide methods to compute the sum, average, maximum, and minimum value.
Consider the following class:public class Sequence{private int[] values;public Sequence(int size) { values = new int[size]; }public void set(int i, int n) { values[i] = n; }public int get(int i) { return values[i]; }public int size() { return values.length; }}Add a method public boolean
Add a method public Sequence sum (Sequence other) to the Sequence class of Exercise •• E7.12 that yields the sum of this sequence and another. If the sequences don’t have the same length, assume that the missing elements are zero. For example, the sum of 1 4 9 16 9 7 4 9 11 and 11 11 7 9 16 4
Add a method to the Table class below that computes the average of the neighbors of a table element in the eight directions shown in Figure 15:public double neighborAverage(int row, int column)However, if the element is located at the boundary of the array, include only the neighbors that are in
Given the Table class of Exercise •• E7.17 , add a method that returns the sum of the ith row (if horizontal is true) or column (if horizontal is false):public double sum(int i, boolean horizontal)Data from Exercise E 7.17Add a method to the Table class below that computes the average of the
Improve the program of Exercise •• E7.19 to work correctly when the data set contains negative values.Data from Exercise E 7.19Write a program that reads a sequence of input values and displays a bar chart of the values, using asterisks, like
Improve the program of Exercise •• E7.19 by adding captions for each bar. Prompt the user for the captions and data values. The output should look like this:Egypt **********************France ****************************************Japan ****************************Uruguay
Consider the following class: public class Sequence{private ArrayList values;public Sequence() { values = new ArrayList(); }public void add(int n) { values.add(n); }public String toString() { return values.toString(); }}Add a method public Sequence append (Sequence other) that creates a new
Add a method public Sequence merge(Sequence other) to the Sequence class of Exercise • E7.23 that merges two sequences, alternating elements from both sequences. If one sequence is shorter than the other, then alternate as long as you can and then append the remaining elements from the longer
Add a method public Sequence mergeSorted(Sequence other) to the Sequence class of Exercise • E7.23 that merges two sorted sequences, producing a new sorted sequence. Keep an index into each sequence, indicating how much of it has been processed already. Each time, append the smallest unprocessed
A smartphone keeps track of the x- and y-position of a person once per minute. Use this data to solve a vexing problem: Where did the person last park their car? Look for positions that indicate a stopped vehicle, then a person walking out of the car.
In this assignment, you will implement a simulation of a popular casino game usually called video poker. The card deck contains 52 cards, 13 of each suit. At the beginning of the game, the deck is shuffled. You need to devise a fair method for shuffling. (It does not have to be efficient.) The
A pet shop wants to give a discount to its clients if they buy one or more pets and at least five other items. The discount is equal to 20 percent of the cost of the other items, but not the pets.Use a class Item to describe an item, with any needed methods and a constructor public Item(double
Generate the image of a checkerboard.
Implement a class Cloud that contains an array list of Point2D.Double objects. Support methods:Draw each point as a tiny circle. Write a graphical application that draws a cloud of 100 random points. public void add (Point 2D. Double aPoint) public void draw (Graphics2D g2)
Implement a class Polygon that contains an array list of Point2D.Double objects. Sup port methods:Draw the polygon by joining adjacent points with a line, and then closing it up by joining the end and start points. Write a graphical application that draws a square and a pentagon using two Polygon
Write a class Chart with methods: public void add(int value) public void draw (Graphics2D g2) that displays a stick chart of the added values, like this: You may assume that the values are pixel positions.
Write a class BarChart with methods:that displays a bar chart of the added values. You may assume that all added values are positive. Stretch the bars so that they fill the entire area of the screen. You must figure out the maximum of the values, then scale each bar. public void add(double value)
Write a class PieChart with methods:that displays a pie chart of the added values. Assume that all data values are positive. public void add(double value) public void draw (Graphics2D g2)
Consider a car share system in which drivers pick up other riders, enabling them to make money during their commute while reducing traffic congestion. Riders wait at pickup points, are dropped off at their destinations, and pay for the distance traveled.Drivers get a monthly payment. An app lets
Suppose you want to design a social network for internship projects at your university.Students can register their skills and availability. Project sponsors describe projects, required skills, expected work effort, and desired completion date. A search facility lets students find matching projects.
Your task is to write a program that simulates a vending machine. Users select a product and provide payment. If the payment is sufficient to cover the purchase price of the product, the product is dispensed and change is given. Otherwise, the payment is returned to the user. Name an appropriate
Your task is to write a program that reads a customer’s name and address, followed by a sequence of purchased items and their prices, and prints an invoice.Discuss which of the following would be good classes for implementing this program:a. Invoiceb. InvoicePrinterc. PrintInvoiced.
Your task is to write a program that computes paychecks. Employees are paid an hourly rate for each hour worked; how ever, if they worked more than 40 hours per week, they are paid at 150 percent of the regular rate for those overtime hours. Name an actor class that would be appropriate for
Look at the public interface of the java.lang.System class and discuss whether or not it is cohesive.••
Suppose an Invoice object contains descriptions of the products ordered, and the billing and shipping addresses of the customer. Draw a UML diagram showing the dependencies between the classes Invoice, Address, Customer, and Product.••
Suppose a vending machine contains products, and users insert coins into the vending machine to purchase products. Draw a UML diagram showing the dependen cies between the classes VendingMachine, Coin, and Product.••
On which classes does the class Integer in the standard library depend?••
On which classes does the class Rectangle in the standard library depend?•
Classify the methods of the class Scanner that are used in this book as accessors and mutators.•
Classify the methods of the class Rectangle as accessors and mutators.•
Which of the following classes are immutable?a. Rectangleb. Stringc. Random•
Which of the following classes are immutable?a. PrintStreamb. Datec. Integer•••
Consider a method:Describe the side effects of the read method. Which of them are not recommended, according to Section 8.2.4? Which redesign eliminates the unwanted side effect?What is the effect of the redesign on coupling?•• public class DataSet { } /** Reads all numbers from a scanner and
What side effect, if any, do the following three methods have?public class Coin:••• { } public public void print () System.out.println(name + } } public void print (PrintStream stream) { stream.println(name + " " + value); } public String toString() { + value); return name + " " + value;
Ideally, a method should have no side effects. Can you write a program in which no method has a side effect? Would such a program be useful?••
How can you write a method that swaps two floating-point numbers?java.awt.Point.••
Draw a memory diagram that shows why the following method can’t swap two BankAccount objects:• public static void falseSwap(BankAccount a, BankAccount b) { } BankAccount temp = a; a = b; b temp;
Consider an enhancement of the Die class of Chapter 6 with a static variable• public class Die { private int sides; private static Random generator = new Random(); public Die(int s) {...} public int cast() { . . . } } Draw a memory diagram that shows three dice: Die d4 new Die (4); Die d6 new Die
Try compiling the following program. Explain the error message that you get.• public class Print13 { } public void print(int x) { System.out.println(x); } public static void main (String[] args) { } int n = 13; print (n);
Look at the methods in the Integer class. Which are static? Why?••
Look at the methods in the String class (but ignore the ones that take an argument of type char[]). Which are static? Why?••
Suppose you are asked to find all words in which no letter is repeated from a list of words. What simpler problem could you try first?••
You need to write a program for DNA analysis that checks whether a substring of one string is contained in another string. What simpler problem can you solve first?••
Consider the task of finding numbers in a string. For example, the string “In 1987, a typical personal computer cost $3,000 and had 512 kilobytes of RAM.” has three numbers. Break this task down into a sequence of simpler tasks.•
Is a Java program without import statements limited to using the default and java.lang packages?•
Suppose your homework assignments are located in the directory /home/me/cs101 (c:\Users\Me\cs101 on Windows). Your instructor tells you to place your homework into packages. In which directory do you place the class hw1.problem1.TicTacToe Tester?
Consider the task of fully justifying a paragraph of text to a target length, by putting as many words as possible on each line and evenly distributing extra spaces so that each line has the target length. Devise a plan for writing a program that reads a paragraph of text and prints it fully
The in and out variables of the System class are public static variables of the System class. Is that good design? If not, how could you improve on it?••
Every Java program can be rewritten to avoid import statements. Explain how, and rewrite RectangleComponent.java from Section 2.9.3 to avoid import statements.•
What does JUnit do when a test method throws an exception? Try it out and report your findings.
Implement the Coin class described in Section 8.2. Modify the CashRegister class so that coins can be added to the cash register, by supplying a method:The caller needs to invoke this method multiple times, once for each type of coin that is present in the payment. void receive Payment(int
Modify the giveChange method of the CashRegister class so that it returns the number of coins of a particular type to return:The caller needs to invoke this method for each coin type, in decreasing value. int giveChange (Coin coinType)
Real cash registers can handle both bills and coins. Design a single class that expresses the commonality of these concepts. Redesign the CashRegister class and provide a method for entering payments that are described by your class. Your primary challenge is to come up with a good name for this
As pointed out in Section 8.2.3, the Scanner.next method is a mutator that returns a value. Implement a class Reader that reads from System.in and does not suffer from that shortcoming. Provide methods:•• public boolean hasMoreElements () // Checks whether there is another element public String
Reimplement the BankAccount class so that it is immutable. The deposit and withdraw methods need to return new BankAccount objects with the appropriate balance.•
Reimplement the Day class of Worked Example 2.1 to be mutable. Change the methods addDays, nextDay, and previousDay to mutate the implicit parameter and to return void. Also change the demonstration program.Data from worked example 2.1.•• WORKED EXAMPLE 2.1 How Many Days Have You Been Alive?
Write static methods:that compute the volume and surface area of a cube with height h, sphere with radius r, a cylinder with circular base with radius r and height h, and a cone with circular base with radius r and height h. Place them into a class Geom etry. Then write a program that prompts the
Modify the application of How To 7.1 so that it can deal with multiple students.First, ask the user for all student names. Then read in the scores for all quizzes, prompting for the score of each student. Finally, print the names of all students and their final scores. Use a single class and only
Repeat Exercise ••• E8.9 , using multiple classes. Provide a GradeBook class that collects objects of type Student.Data from Exercise E8.9Modify the application of How To 7.1 so that it can deal with multiple students.First, ask the user for all student names. Then read in the scores for all
Write methods:that compute the area and the perimeter of the ellipsee. Add these methods to a class Geometry. The chal lenging part of this assignment is to find and implement an accurate formula for the perimeter. Why does it make sense to use a static method in this case?•• public static
Write methods:that compute the angle between the x-axis and the line joining two points, measured in degrees, and the slope of that line. Add the methods to the class Geometry. Supply suitable preconditions. Why does it make sense to use a static method in this case?••• public static double
Write methods:that test whether a point is inside or on the boundary of an ellipse. Add the methods to the class Geometry.•• public static boolean isInside (Point2D.Double p, Ellipse2D.Double e) public static boolean isOnBoundary (Point2D.Double p, Ellipse2D.Double e)
Using the Picture class from Worked Example 6.2, write a method:that superimposes two pictures, yielding a picture whose width and height are the larger of the widths and heights of pic1 and pic2. In the area where both pictures have pixels, average the colors.Data from worked example 6.2••
Using the Picture class from Worked Example 6.2, write a method:that superimposes two pictures, yielding a picture whose width and height are the larger of the widths and heights of pic1 and pic2. In the area where both pictures have pixels, use pic1, except when its pixels are green, in which
Showing 400 - 500
of 791
1
2
3
4
5
6
7
8
Step by Step Answers