All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
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
Ask a Question
Search
Search
Sign In
Register
study help
computer science
java an introduction to problem solving and progra
Questions and Answers of
Java An Introduction to Problem Solving and Progra
Write an exception class that is appropriate for indicating that a time entered by a user is not valid. The time will be in the format hour:minute followed by “am” or “pm.”
Write a program that uses the class Calculator in Listing 9.12 to create a more powerful calculator. This calculator will allow you to save one result in memory and call the result back. The commands
Write a program that allows the user to compute the remainder after the division of two integer values. The remainder of x/y is x%y. Catch any exception thrown and allow the user to enter new values.
Write a program that converts a time from 24-hour notation to 12-hour notation. The following is a sample interaction between the user and the program:Enter time in 24-hour notation:13:07That is the
Define DiscountPolicy as an interface instead of the abstract class described in Exercise 10.Exercise 10.Create an abstract class DiscountPolicy. It should have a single abstract method
Derive a class CombinedDiscount from DiscountPolicy, as described in Exercise 10. It should have a constructor that has two parameters of type DiscountPolicy. It should define the method
Derive a class BuyNItemsGetOneFree from DiscountPolicy, as described in Exercise 10. The class should have a constructor that has a single parameter n. In addition, the class should define the method
Create an abstract class DiscountPolicy. It should have a single abstract method computeDiscount that will return the discount for the purchase of a given number of a single item. The method has two
Derive a class BulkDiscount from DiscountPolicy, as described in the previous exercise. It should have a constructor that has two parameters, minimum and percent. It should define the method
Create a JavaFX application that will draw a spiral using line segments. The equations for the points on a spiral are:You should draw 150 points. Start θ at 0 and increase it by 0.1 for each new
Derive a class RegularPay from PayCalculator, as described in the previous exercise. It should have a constructor that has a parameter for the pay rate. It should not override any of the methods.
Create 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 clicked. Add additional
Create an abstract class PayCalculator that has an attribute payRate given in dollars per hour. The class should also have a method computePay(hours) that returns the pay for a given amount of time.
Create a JavaFX application that uses a TextField to get a message and encode or decode it using the classes described in Programming Project 5. Use buttons to control the kind of cipher used and to
Derive a class ExaggeratingKid from SchoolKid, as described in the previous exercise. The new class should override the accessor method for the age, reporting the actual age plus 2. It also should
Modify the Student class in Listing 8.2 so that it implements the comparable interface. Define the compareTo method to order Student objects based on the value in studentNumber. In a main method
For this Programming Project, start with implementations of the Person, Student, and Undergraduate classes as depicted in Figure 8.4 and the polymorphism demo in Listing 8.6. Define the Employee,
Create an interface MessageDecoder that has a single abstract method decode(cipherText), where cipherText is the message to be decoded. The method will return the decoded message. Modify the classes
Create a class SchoolKid that is the base class for children at a school. It should have attributes for the child’s name and age, the name of the child’s teacher, and a greeting. It should have
Create the classes RightTriangle and Rectangle, each of which is derived from the abstract class ShapeBase in Listing 8.19. Then derive a class Square from the class Rectangle. Each of these three
Create a class Square derived from DrawableShape, as described in the previous exercise. A Square object should know the length of its sides. The class should have an accessor method and a mutator
Suppose we want to implement a drawing program that creates various shapes using keyboard characters. Implement an abstract base class DrawableShape that knows the center (two integer values) and the
Draw a hierarchy for the components you might find in a graphical user interface. Note that some components can trigger actions. Some components may have graphics associated with them. Some
Implement your base class for the hierarchy from the previous exercise.Previous exercise.Consider a program that will keep track of the items in a school’s library. Draw a class hierarchy,
Define a class called Diamond that is derived from either the class ShapeBasics (Listing 8.12) or the abstract class ShapeBase (Listing 8.19). A diamond has the same sort of top half as a Triangle
Write a static method blur(double[][]picture) that you could use on a part of a picture file to obscure a detail such as a person’s face or a license plate number. This method computes the weighted
Write a static method findFigure(picture,threshold), where picture is a twodimensional array of double values. The method should return a new two-dimensional array whose elements are either 0.0 or
Write a sequential search of an array of integers, assuming that the array is sorted into ascending order. Consider an array that contains the four integers 2, 4, 6, and 8. How can you tell that 5 is
Your application won’t actually function as a calculator at this point. You are just designing the interface.
Revise the class TimeBook in Listing 7.14 to use an enumeration for the days of the week instead of named constants.Listing 7.14 Class that records the t ime worked by each of a company's employees
Create a JavaFX application to create the interface for a calculator. Use a BorderPane in the stage with a TextField at the top. The text field would be used to store the number being entered in the
Revise the method selectionSort that appears in Listing 7.10 so that it calls the method described in the previous exercise.Listing 7.10/**Class for sorting an array of base type int from smallest to
Do Programming Project 15 except use a class named Player to store a player’s name and score. Use a single array of type Player. Be sure to include a constructor with this class that sets the name
Overload the method selectionSort in Listing 7.10 so that it sorts an array whose indices range from first to last, where 0 ≤ first ≤ last, and last is less than the length of the array.Listing
Write a program that manages a list of up to 10 players and their high scores in the computer’s memory. Use two arrays to manage the list. One array should store the player’s name and the other
Write a static method for selection sort that will sort an array of characters.
Practice Program 5.4 asked you to define a Trivia class that contained strings representing a trivia question and answer to that question. Add an integer for the number of points that the question is
Revise the class OneWayNoRepeatsList, as given in Listing 7.9, so that it allocates an extra element in the array entry and ignores entry[0], as suggested earlier near the end of the section entitled
Practice Program 2 used two arrays to implement a simple phone book. A more scalable solution is to make an array of an object that stores the name and corresponding phone number. Modify the program
Write a method beyondLastEntry(position) for the class OneWayNo-RepeatsList, as given in Listing 7.9, that returns true when position is beyond the last entry on the list.Listing 7.9 /** An object of
Create a GUI application that draws the following picture of a magic wand, using polygons and polylines:
Create a class Polynomial that is used to evaluate a polynomial function of x:The coefficients a are floating-point numbers, the exponents of x are integers, and the largest exponent n—called the
Sudoku is a popular logic puzzle that uses a 9 by 9 array of squares that are organized into 3 by 3 subarrays. The puzzle solver must fill in the squares with the digits 1 to 9 such that no digit is
Suppose that we are selling boxes of candy for a fund-raiser. We have five kinds of candy to sell: Mints, Chocolates with Nuts, Chewy Chocolates, Dark Chocolate Creams, and Sugar-Free Suckers. We
ELIZA was a program written in 1966 that parodied a psychotherapist session. The user typed sentences and the program used those words to compose a question.Create a simple GUI application based on
Write a static method remove(int v,int[] in) that will return a new array of the integers in the given array, but with the value v removed. For example, if v is 3 and in contains 0, 1, 3, 2, 3, 0, 3,
Write a GUI application that displays a picture of a pine tree formed by drawing a triangle on top of a small rectangle that makes up the visible trunk. The tree should be green and have a gray trunk.
Write a static method removeDuplicates(Character[] in) that returns a new array of the characters in the given array, but without any duplicate characters. Always keep the first copy of the character
Traditional password entry schemes are susceptible to “shoulder surfing” in which an attacker watches an unsuspecting user enter his or her password or PIN number and uses it later to gain access
Write a static method isStrictlyIncreasing(double[] in) that returns true if each value in the given array is greater than the value before it, or false otherwise.
Define the following methods for the class Ledger, as described in the previous exercise:getAverageSale()—returns the average value of all the salesgetCountAbove(v)—returns the number of sales
Repeat Programming Project 10 from Chapter 5 but use an array to store the movie ratings instead of separate variables. All changes should be internal to the class, so the main method to test the
Define a class called TicTacToe. An object of type TicTacToe is a single game of tic-tactoe. Store the game board as a single two-dimensional array of base type char that has three rows and three
Create a class Ledger that will record the sales for a store. It will have the attributes sale—an array of double values that are the amounts of all sales salesMade—the number of sales
The class TimeBook in Listing 7.14 is not really finished. Complete the definition of this class in the way described in the text. In particular, be sure to add a default constructor, as well as set
Write 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 for each
Add a method insertionSort to the class ArraySorter, as given in Listing 7.10, that performs an insertion sort of an array. To simplify this project, our insertion sort algorithm will use an
Write a program in a class FlowerCounter that computes the cost of flowers sold at a flower stand. Five kinds of flowers—petunia, pansy, rose, violet, and carnation—are stocked and cost,
Add a method bubbleSort to the class ArraySorter, as given in Listing 7.10, that performs a bubble sort of an array. The bubble sort algorithm examines all adjacent pairs of elements in the array
Write a program in a class CountPoor that counts the number of families that are considered poor. Write and use a class Family that has the attributesincome—a double value that is the income for
A palindrome is a word or phrase that reads the same forward and backward, ignoring blanks and considering uppercase and lowercase versions of the same letter to be equal. For example, the following
Write a program in a class CountFamiles that counts the number of families whose income is below a certain value. Read an integer k from the keyboard and then create an array of double values of size
Write a program that will read a line of text that ends with a period, which serves as a sentinel value. Display all the letters that occur in the text, one per line and in alphabetical order, along
Write a program in a class NumberAboveAverage that counts the number of days that the temperature is above average. Read ten temperatures from the keyboard and place them in an array. Compute the
Write a program that plays a simplified dice version of blackjack. Instead of selecting from a deck of cards a 14-sided die is rolled to represent a card. The rules of the game for one round, as
Create a program that tests the class Android described in the previous exercise.Previous exercise.Create a class Android whose objects have unique data. The class has the following
Create a JavaFX application that displays a button with the text “Button 1”. Underneath the button add a label with the text “Label 1”. Repeat with and additional “Button 2” and “Label
Repeat Programming Project 10 from Chapter 5, but include constructors.Programming Project 10Consider a class Movie that contains information about a movie. The class has the following attributes:The
Write a program that will record the votes for one of two candidates by using the class VoteRecorder, which you will design and create. Vote Recorder will have static variables to keep track of the
Create a program that tests the class Merlin described in the previous exercise. Use the toString method to verify that a unique instance has been created.Previous exercise.Sometimes we would like a
Sometimes we would like a class that has just a single unique instance. Create a class Merlin that has one attribute, theWizard, which is static and of type Merlin. The class has only one constructor
Write and fully test a class that represents rational numbers. A rational number can be represented as the ratio of two integer values, a and b, where b is not zero. The class has attributes for the
Write a Java enumeration LetterGrade that represents letter grades A through F, including plus and minus grades. Define a private instance variable to hold a boolean value that is true if the grade
Write a new class TruncatedDollarFormat that is the same as the class DollarFormat from Listing 6.14, except that it truncates rather than rounds to obtain two digits after the decimal point. When
Consider a class ScienceFairProjectRating that will be used to help judge a science fair project. It will use the class RatingScore described in the previous exercise. The attributes for the new
Consider a class that could be used to play a game of hangman. The class has the following attributes:The secret word.The disguised word, in which each unknown letter in the secret word is replaced
Create a class that will bundle together several static methods for tax computations. This class should not have a constructor. Its attributes arebasicRate—the basic tax rate as a static double
Define a utility class for displaying values of type double. Call the class DoubleOut. Include all the methods from the class DollarFormat in Listing 6.14, all the methods from the class OutputFormat
Consider a class Movie that contains information about a movie. The class has the following attributes:The movie nameThe MPAA rating (e.g., G, PG, PG-13, R)The number of people who have rated this
Repeat Programming Project 18 from Chapter 4, but use a method that displays a circular disk as a subtask.Programming Project 18What does the following fragment of code display? What do you think the
Create a JavaFX application that displays something like the following picture. You should have methods for drawing a monkey face and a hand. Hear no evil See no evil Speak no evil
Do Programming Project 17 from Chapter 4, the Edoc calculator, except write a method that takes the number of candy, Edoc, and Margorp as input parameters and returns the amount of experience that
Consider a class RatingScore that represents a numeric rating for something such as a movie. Its attributes areA description of what is being ratedThe maximum possible ratingThe ratingIt will have
Consider a class BasketballGame that represents the state of a basketball game. Its attributes areThe name of the first teamThe name of the second teamThe score of the first teamThe score of the
Write a program to answer questions like the following: Suppose the species Klingon ox has a population of 100 and a growth rate of 15 percent, and it lives in an area of 1500 square miles. How long
Write a program that uses the Purchase class in Listing 5.13 to set the following prices:Oranges: 10 for $2.99Eggs: 12 for $1.69Apples: 3 for $1.00Watermelons: $4.39 eachBagels: 6 for $3.50Then
Repeat Exercise 1 for a collection of coins instead of a credit card.Exercise 1Design a class to represent a credit card. Think about the attributes of a credit card; that is, what data is on the
Create a class that represents a grade distribution for a given course. Write methods to perform the following tasks:Set the number of each of the letter grades A, B, C, D, and F.Read the number of
Repeat Exercise 1 for a coin instead of a credit card.Exercise 1Design a class to represent a credit card. Think about the attributes of a credit card; that is, what data is on the card? What
Add methods to the Person class from Self-Test Question 16 to perform the following tasks:Set the name attribute of a Person object.Set the age attribute of a Person object.Test whether two Person
Repeat Exercise 1 for a credit card account instead of a credit card. An account represents the charges and payments made using a credit card.Exercise 1Design a class to represent a credit card.
Write a grading program for an instructor whose course has the following policies: Two quizzes, each graded on the basis of 10 points, are given.One midterm exam and one final exam, each graded
What does the following fragment of code display? What do you think the programmer intended the code to do, and how would you fix it?int sum = 0;intproduct = 1;int max = 20;for (int i = 1; i <=
What does the following fragment of code display? What do you think the programmer intended the code to do, and how would you fix it?int product = 1;int max = 20;for (int i = 0; i <= max;
You have an augmented reality game in which you catch Edoc and acquire Edoc candy. You need 12 candies to evolve an Edoc into a Margorp. An evolution earns you back one candy. Each evolution also
Create an applet that draws a pattern of circles whose centers are evenly spaced along a horizontal line. Use six constants to control the pattern: the number of circles to draw, the diameter of the
Write a JavaFx application that displays a series of pictures of a person with arms, legs, and of course a head. Use a happy face for the head. Use ovals for the body, arms, and legs. Draw a sequence
Imagine a program that compresses files by 80 percent and stores them on storage media. Before the compressed file is stored, it must be divided into blocks of 512 bytes each. Develop an algorithm
Repeat the previous project, but position the centers of the circles on a spiral. The center of each circle will depend on both an angle and a distance from the origin. A constant change in both the
Suppose that we want to compute the geometric mean of a list of positive values. To compute the geometric mean of k values, multiply them all together and then compute the kth root of the value. For
Showing 200 - 300
of 407
1
2
3
4
5