Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[ USING JAVA ] 7.10 (Modified Account Class) Modify class Account (Fig. 7.8) to provide a method called withdraw that withdraws money from an Account.

[ USING JAVA ]

image text in transcribed

image text in transcribed

7.10 (Modified Account Class) Modify class Account (Fig. 7.8) to provide a method called withdraw that withdraws money from an Account. Ensure that the withdrawal amount does not exceed the Account's balance. If it does, the balance should be left unchanged and the method should print a message indicating "Withdrawa 1 amount exceeded account balance." Modify class AccountTest (Fig. 7.9) to test method withdraw. 7.11 (Invoice Class) Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables-a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. Provide a set and a get method for each instance variable. In addition, provide a method named getInvoiceAmount that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as a double value. If the quantity is not positive, it should be set to 0 . If the price per item is not positive, it should be set to 0.0. Write a test app named InvoiceTest that demonstrates class Invoice's capabilities. 7.12 (Emp7oyee Class) Create a class called Employee that includes three instance variables-a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app named EmployeeTest that demonstrates class Employee's capabilities. Create two Employee objects and display each object's yearly salary. Then give each Employee a 10\% raise and display each Employee's yearly salary again. 7.13 (Date Class) Create a class called Date that includes three instance variables-a month (type int), a day (type int) and a year (type int). Provide a constructor that initializes the three instance variables and assumes that the values provided are correct. Provide a set and a get method for each instance variable. Provide a method displayDate that displays the month, day and year separated by forward slashes (/). Write a test app named DateTest that demonstrates class Date's capabilities. 7.I4 (Removing Duplicated Code in Method main) In the AccountTest class of Fig. 7.9, method main contains six statements (lines 13-14, 15-16, 28-29, 30-31, 40-41 and 42-43) that each display an Account object's name and balance. Study these statements and you'll notice that they differ only in the Account object being manipulated-account 1 or account2. In this exercise, you'll define a new displayAccount method that contains one copy of that output statement. The method's parameter will be an Account object and the method will output the object's name and balance. You'll then replace the six duplicated statements in main with calls to displayAccount, passing as an argument the specific Account object to output. Modify class AccountTest class of Fig. 7.9 to declare the following displayAccount method after the closing right brace of main and before the closing right brace of class AccountTest: public static void displayAccount(Account accountToDisplay) \{ // place the statement that displays \} // accountToDisplay's name and balance here Replace the comment in the method's body with a statement that displays accountToDisplay's name and balance. Recall that main is a static method, so it can be called without first creating an object of the class in which main is declared. We also declared method displayAccount as a static method. When main needs to call another method in the same class without first creating an object of that class, the other method also must be declared static. Once you've completed displayAccount's declaration, modify main to replace the statements that display each Account's name and balance with calls to displayAccount-each receiving as its argument the account 1 or account 2 object, as appropriate. Then, test the updated AccountTest class to ensure that it produces the same output as shown in Fig. 7.9

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Office 365 For Beginners 2022 8 In 1

Authors: James Holler

1st Edition

B0B2WRC1RX, 979-8833565759

More Books

Students also viewed these Databases questions

Question

How did you feel about taking piano lessons as a child? (general)

Answered: 1 week ago