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 how to program late objects
Questions and Answers of
Java How To Program Late Objects
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
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
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
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
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
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
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
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
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
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
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
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
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
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.
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Many programs written with inheritance could be written with composition instead, and vice versa. Rewrite class BasePlus-CommissionEmployee (Fig. 9.11) of the
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
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
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
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
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
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
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
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
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
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.
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
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
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
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
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,
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
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
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,
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
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
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
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
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
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
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
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
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
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
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
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
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 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
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
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
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
Write your own versions of String search methods indexOf and lastIndexOf.
Showing 100 - 200
of 421
1
2
3
4
5