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 how to program late objects
Java How To Program Late Objects Version 8th Edition Paul Deitel, Deitel & Associates - Solutions
Demonstrate that the escape sequence \t causes a tab to be issued to the output. Note that your output will depend on how tabs are set on your system. Use the string"before\tafterbefore\t\tafter"
Demonstrate what happens when you include a single backslash (\) in a string. Be sure that the character after the backslash does not create a valid escape sequence.
Display a string containing \\\\ (recall that \\ is an escape sequence for a backslash). How many backslashes are displayed?
Use the escape sequence \" to display a quoted string.
What happens when the following code executes in JShell:System.out.println("Happy Birthday!Sunny")
Consider the following statement System.out.printf("%s%n%s%n", "Welcome to ", "Java Programming!")Make the following intentional errors (separately) to see what happens.a) Omit the parentheses around the argument list.b) Omit the commas.c) Omit one of the %s%n sequences.d) Omit one of the
What happens when you enter the /imports command in a new JShell session?
Import class Scanner then create a Scanner object input for reading from System.in. What happens when you execute the statement:int number = input.nextInt()and the user enters the string "hello"?
In a new or /reset JShell session, repeat Exercise 25.21 without importing class Scanner to demonstrate that the package java.util is already imported in JShell.Exercise 25.21Import class Scanner then create a Scanner object input for reading from System.in. What happens when you execute the
Demonstrate what happens when you don’t precede a Scanner input operation with a meaningful prompting message telling the user what to input. Enter the following statements:Scanner input = new Scanner(System.in)int value = input.nextInt()
Demonstrate that you can’t place an import statement in a class.
Demonstrate that identifiers are case sensitive by declaring variables id and ID of types String and int, respectively. Also use the /list command to show the two snippets representing the separate variables.
Demonstrate that initialization statements like String month = "April"int age = 65 indeed initialize their variables with the indicated values.
Demonstrate what happens when you:a) Add 1 to the largest possible int value 2,147,483,647.b) Subtract 1 from the smallest possible integer –2,147,483,648.
Demonstrate that large integers like 1234567890 are equivalent to their counterparts with the underscore separators, namely 1_234_567_890:a) 1234567890 == 1_234_567_890b) Print each of these values and show that you get the same result.c) Divide each of these values by 2 and show that you get the
Placing spaces around operators in an arithmetic expression does not affect the value of that expression. In particular, the following expressions are equivalent:17+23 17 + 23 Demonstrate this with an if statement using the condition(17+23) == (17 + 23)
Demonstrate that the parentheses around the argument number1 + number2 in the following statement are unnecessary:System.out.printf("Sum is %d%n", (number1 + number2))
Declare the int variable x and initialize it to 14, then demonstrate that the subsequent assignment x = 27 is destructive.
Demonstrate that printing the value of the following variable is non-destructive:int y = 29
Using the declarations:int b = 7 int m = 9a) Demonstrate that attempting to do algebraic multiplication by placing the variable names next to one another as in bm doesn’t work in Java.b) Demonstrate that the Java expression b * m indeed multiplies the two operands.
Use the following expressions to demonstrate that integer division yields an integer result:a) 8 / 4b) 7 / 5
Demonstrate what happens when you attempt each of the following integer divisions:a) 0 / 1b) 1 / 0c) 0 / 0
Demonstrate that the values of the following expressions:a) (3 + 4 + 5) / 5b) 3 + 4 + 5 / 5 are different and thus the parentheses in the first expression are required if you want to divide the entire quantity 3 + 4 + 5 by 5.
Calculate the value of the following expression:5 / 2 * 2 + 4 % 3 + 9 - 3 manually being careful to observe the rules of operator precedence. Confirm the result in JShell.
Test each of the two equality and four relational operators on the two values 7 and 7. For example, 7 == 7, 7 < 7, etc.
Repeat Exercise 25.38 using the values 7 and 9.Exercise 25.38Test each of the two equality and four relational operators on the two values 7 and 7. For example, 7 == 7, 7 < 7, etc.
Repeat Exercise 25.38 using the values 11 and 9.Exercise 25.38Test each of the two equality and four relational operators on the two values 7 and 7. For example, 7 == 7, 7 < 7, etc.
Demonstrate that accidentally placing a semicolon after the right parenthesis of the condition in an if statement can be a logic error.if (3 == 5); {System.out.println("3 is equal to 5");}
Given the following declarations:int x = 1 int y = 2 int z = 3 int a what are the values of a, x, y and z after the following statement executes?a = x = y = z = 10
Manually determine the value of the following expression then use JShell to check your work:(3 * 9 * (3 + (9 * 3 / (3))))
Create class DateAndTime that combines the modified Time2 class of Exercise 8.7 and the modified Date class of Exercise 8.8 . Modify method incrementHour to call method nextDay if the time is incremented into the next day. Modify methods toString and toUniversalString to output the date in addition
Modify class Employee from Exercise 10.17 so that it implements the Payable interface of Fig. 10.11. Replace the Salaried-Employee objects in the application of Fig. 10.14 with the Employee objects from Exercise 10.17 and demonstrate processing the Employee and Invoice objects
Write a series of single statements. Actually, these statements form the core of an important type of file-processing program—namely, a file-matching program. In commercial data processing, it’s common to have several files in each application system. In an accounts receivable system, for
Using an approach similar to that for Exercise 3.21, find the two largest values of the 10 values entered. Exercise 3.21The process of finding the largest value is used frequently in computer applications. For example, a program that determines the winner of a sales contest would input the
State an example where you can reuse the constructor of a parent class in Java.
Create a class Cylinder with attributes radius and height, each of which has a default value of 1. Provide a method that calculates the cylinders’ volume, which is pi multiplied by the square of the radius multiplied by the height. It has set and get methods for both radius and height. The set
It would be perfectly reasonable for the Time2 class of Fig. 8.5 to represent the time internally as the number of seconds since midnight rather than the three integer values hour, minute and second. Clients could use the same public methods and get the same results. Modify the Time2 class of Fig.
Create class SavingsAccount. Use a static variable annualInterestRateto store the annual interest rate for all account holders. Each object of the class contains a private instance variable savingsBalance indicating the amount the saver currently has on deposit.Provide method
Modify class Time2 of Fig. 8.5 to include a tick method that increments the time stored in a Time2 object by one second. Provide method incrementMinute to increment the minute by one and method incrementHour to increment the hour by one. Write a program that tests the tick method, the
Modify class Date of Fig. 8.7 to perform error checking on the initializer values for variables month, day and year (currently it validates only the month and day). Provide a method nextDay to increment the day by one. Write a program that tests method nextDay in a loop that prints the date during
Write code that generates n random numbers in the range 10–100.
Write an enum type Food, whose constants (APPLE, BANANA, CARROT) take two parameters—the type (vegetable or fruit), and number of calories. Write a program to test the Food enum so that it displays the enum names and their information.
Create a class called Complex for performing arithmetic with complex numbers. Complex numbers have the form realPart + imaginaryPart * i where i isWrite a program to test your class. Use floating-point variables to represent the private data of the class. Provide a constructor that enables an
Create class IntegerSet. Each IntegerSet object can hold integers in the range 0–100. The set is represented by an array of booleans. Array element a[i] is true if integer i is in the set. Array element a[j] is false if integer j is not in the set. The no-argument constructor initializes the
Provide the following methods: The static method union creates a set that’s the set-theoretic union of two existing sets (i.e., an element of the new set’s array is set to true if that element is true in either or both of the existing sets—otherwise, the new set’s element is set to false).
Create class fancyTime with the following capabilities:a) Output the time in multiple formats, such as HH:MM:SS a.m. / p.m. (12 hour format)HH:MM:SS (24 hour format)HH:MM (24 hour format)b) Use overloaded constructors to create Date objects initialized with times of the formats in part (a). In the
Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private instance variables of the class—the numerator and the denominator. Provide a constructor that enables an object of this class to be
Create a class HugeInteger which uses a 40-element array of digits to store integers as large as 40 digits each. Provide methods parse, toString, add and subtract. Method parse should receive a String, extract each digit using method charAt and place the integer equivalent of each digit into the
Create a class TicTacToe that will enable you to write a program to play Tic-Tac-Toe. The class contains a private 3-by-3 two-dimensional array. Use an enum type to represent the value in each cell of the array. The enum’s constants should be named X, O and EMPTY (for a position that does not
In Fig. 8.8, class Employee’s instance variables are never modified after they’re initialized. Any such instance variable should be declared final. Modify class Employee accordingly, then compile and run the program again to demonstrate that it produces the same results.Fig. 8.8 I // Fig. 8.8:
The North American emergency response service, 9-1-1, connects callers to a local Public Service Answering Point (PSAP). Traditionally, the PSAP would ask the caller for identification information—including the caller’s address, phone number and the nature of the emergency, then dispatch the
In a global economy, dealing with currencies, monetary amounts, conversions, rounding and formatting is complex. The new JavaMoney API was developed to meet these challenges. At the time of this writing, it was not yet incorporated into either Java SE or Java EE. You can read about JavaMoney
Many programs written with inheritance could be written with composition instead, and vice versa. Rewrite class BasePlus-CommissionEmployee (Fig. 9.11) of the CommissionEmployee–BasePlusCommissionEmployee hierarchy so that it contains a reference to a CommissionEmployee object, rather than
Every additional line of code is an opportunity for a defect. Discuss the ways in which inheritance promotes defect reduction.
Draw an inheritance hierarchy for types of sports similar to the hierarchy show in Fig. 9.2. Use Sports as the superclass of the hierarchy, then extend Sports with classes IndoorSports and OutdoorSports. Continue to extend the hierarchy as deep (i.e., as many levels) as possible. For example,
Books can come in various formats, like paper books, audio books, ebooks, etc. Create a generic class Book that has as common attributes the title, the year of publication, and the author. The constructor of this class should instantiate all three attributes. Override the toString method of class
Some programmers prefer not to use protected access, because they believe it breaks the encapsulation of the superclass. Discuss the relative merits of using protected access vs. using private access in superclasses.
Write up to two lines of code that perform each of the following tasks:a) Specify that class Orange inherits from class Fruit.b) Declare that you are going to override the toString method from inside the Orange class.c) Call superclass Fruit’s constructor from subclass Orange’s constructor.
Explain two usages of the super keyword, and state some of the advantages of each type of usage.
In this chapter, you studied an inheritance hierarchy in which classBasePlusCommissionEmployee inherited from class CommissionEmployee. However, not all types of employees are CommissionEmployees. In this exercise, you’ll create a more general Employee superclass that factors out the attributes
Other types of Employees might include Salaried-Employees who get paid a fixed weekly salary, PieceWorkers who get paid by the number of pieces they produce or HourlyEmployees who get paid an hourly wage with time-and-a-half—1.5 times the hourly wage—for hours worked over 40 hours.Create class
In this chapter, we created the CommissionEmployee–BasePlusCommissionEmployee inheritance hierarchy to model the relationship between two types of employees and how to calculate the earnings for each. Another way to look at the problem is that CommissionEmployees and BasePlusCommissionEmployees
One instance of polymorphism is overloading. Discuss how overloading can allow you to program general methods that have the same name but achieve different functionality.
Explain how you would create an abstract class called encoder/decoder that serves as a superclass for specific encoder classes such as jpeg and mpeg. List some methods.
Modify the payroll system of Figs. 10.4–10.9 to include private instance variable birth Date in class Employee. Use class Date of Fig. 8.7 to represent an employee’s birthday. Add get methods to class Date. Assume that payroll is processed once per month. Create an array of Employee variables
Implement the Shape hierarchy shown in Fig. 9.3. Each Two-DimensionalShape should contain method getArea to calculate the area of the two-dimensional shape. Each ThreeDimensionalShape should have methods getArea and getVolume to calculate the surface area and volume, respectively, of the
Modify the payroll system of Figs. 10.4–10.9 to include an additional Employee subclass PieceWorker that represents an employee whose pay is based on the number of pieces of merchandise produced. Class PieceWorker should contain private instance variables wage (to store the employee’s wage per
Using interfaces, as you learned in this chapter, you can specify similar behaviors for possibly disparate classes. Governments and companies worldwide are becoming increasingly concerned with carbon footprints (annual releases of carbon dioxide into the atmosphere) from buildings burning various
Write a program that demonstrates how various exceptions are caught with catch (Exception exception) This time, define classes ExceptionA (which inherits from class Exception) and ExceptionB (which inherits from class ExceptionA). In your program, create try blocks that throw exceptions of types
What will be the output of the following code snippet?try {String name = null;System.out.printf("The length of the string is - %d", name.length());}catch (RuntimeException e) {System.out.printf("Runtime Exception");}catch (NullPointerException e) {System.out.println("Null Pointer Exception");}
Create a custom exception class ValidationException. Create a class Phone that has a constructor with two parameters name and serialNumber. Throw a ValidationException from class Phone’s constructor if an empty value is passed for either parameter or if the serial number is not exactly 16 digits.
Write a program that illustrates rethrowing an exception. Define methods someMethod and someMethod2. Method someMethod2 should initially throw an exception. Method someMethod should call someMethod2, catch the exception and rethrow it. Call someMethod from method main, and catch the rethrown
Write a program showing that a method with its own try block does not have to catch every possible error generated within the try. Some exceptions can slip through to, and be handled in, other scopes.
Modify the Tip Calculator app to allow the user to enter the number of people in the party. Calculate and display the amount owed by each person if the bill were to be split evenly among the party members.
Create a mortgage calculator app that allows the user to enter a purchase price, down-payment amount and an interest rate. Based on these values, the app should calculate the loan amount (purchase price minus down payment) and display the monthly payment for 10-, 20- and 30-year loans. Allow the
A bank offers college loans that can be repaid in 5, 10, 15, 20, 25 or 30 years. Write an app that allows the user to enter the amount of the loan and the annual interest rate. Based on these values, the app should display the loan lengths in years and their corresponding monthly payments.
Typically, banks offer car loans for periods ranging from two to five years (24 to 60 months). Borrowers repay the loans in monthly installments. The amount of each monthly payment is based on the length of the loan, the amount borrowed and the interest rate. Create an app that allows the customer
Drivers often want to know the miles per gallon their cars get so they can estimate gasoline costs. Develop an app that allows the user to input the number of miles driven and the number of gallons used and calculates and displays the corresponding miles per gallon.
The formulas for calculating the BMI areCreate a BMI calculator app that allows users to enter their weight and height and whether they are entering these values in English or metric units, then calculates and displays the user’s body mass index. The app should also display the following
While exercising, you can use a heart-rate monitor to see that your heart rate stays within a safe range suggested by your trainers and doctors. According to the American Heart Association (AHA), the formula for calculating your maximum heart rate in beats per minute is 220 minus your age in years
Incorporate the RGBA color chooser you created in the Color Chooser app into the Painter app so that the user can choose any drawing color. Changing a Slider’s value should update the color swatch displayed to the user and set the brushColor instance variable to the current Color.
Create a Contacts app modeled after the Cover Viewer app. Store the contact information in an ObservableList of Contact objects. A Contact should contain first name, last name, email and phone number properties (you can provide others). When the user selects a contact from the contacts list, its
Modify the Contacts app from the preceding exercises to include an image for each Contact. Provide a custom ListView cell factory that displays the Contact’s full name and picture with the names in sorted order by last name.
The property bindings we created in the Color Chooser app allowed a TextField’s text to update when a Slider’s value changed, but not vice versa. JavaFX also supports bi-directional property bindings. Research bidirectional property bindings online, then create bidirectional bindings between
Investigate the capabilities of JavaFX’s WebView control and WebEngine class, then create a JavaFX app that provides basic web browsing capabilities. For an introduction to these classes visit https://docs.oracle.com/javase/8/javafx/embedded-browsertutorial/overview.htm.
Implement a JavaFX app that uses the MyShape hierarchy from GUI and Graphics Case Study Exercise 10.2 to create a fully interactive drawing application. The classes of the MyShape hierarchy require no additional changes. Your app should store the shapes in an ArrayList. The user should be able to
A palindrome is a word that reads the same both forward and backward, such as ‘radar’and ‘madam’. Write an application to check if a string entered by the user is a palindrome or not.
Write an application that uses String method region-Matches to compare two strings input by the user. The application should input the number of characters to be compared and the starting index of the comparison. The application should state whether the compared characters are equal. Ignore the
Write an application that reads a list of strings from the user, stores them in an array of strings, and prints the ones with special characters and the ones without special characters in separate lines. Your application should read strings from the user until they enter ‘#’.Any character that
A website only lets users set a password if the the password contains between 8 and 15 characters, starts with an alphabet, contains at least one uppercase letter, and contains at least one number. Write an application that reads a password string from the user and checks its validity.
Write an application that encodes English-language phrases into pig Latin. Pig Latin is a form of coded language. There are many different ways to form pig Latin phrases. For simplicity, use the following algorithm:To form a pig Latin phrase from an English-language phrase, tokenize the phrase into
Write an application that inputs a telephone number as a string in the form (555) 555-5555. The application should use String method split to extract the area code as a token, the first three digits of the phone number as a token and the last four digits of the phone number as a token. The seven
Write an application that inputs a line of text, tokenizes the line with String method split and outputs the tokens in reverse order. Use space characters as delimiters.
Write an application that inputs a line of text and displays the longest word (the word that has the maximum number of characters) in that sentence.
Write an application that inputs a line of text and a search character and uses String method indexOf to determine the number of occurrences of the character in the text.
Write an application based on the application in Exercise 14.11 that inputs a line of text and uses String method indexOf to determine the total number of occurrences of each letter of the alphabet in the text. Uppercase and lowercase letters should be counted together. Store the totals for each
Write an application that reads a line of text, tokenizes the line using space characters as delimiters, and outputs only the words beginning with capital letters.
Write an application that reads a line of text, tokenizes it using space characters as delimiters and outputs only those words ending with the letters "ED".
Write an application that inputs an integer code for a character and displays the corresponding character. Modify this application so that it generates all possible three-digit codes in the range from 000 to 255 and attempts to print the corresponding characters.
Write your own versions of String search methods indexOf and lastIndexOf.
Showing 100 - 200
of 421
1
2
3
4
5
Step by Step Answers