Question: 3 . 5 ( Keyword new ) What s the purpose of keyword new? Explain what happens when you use it . 3 . 6
Keyword new Whats the purpose of keyword new? Explain what happens when you use it
Default Constructors What is a default constructor? How are an objects instance variables initialized if a class has only a default constructor?
Instance Variables Explain the purpose of an instance variable.
Using Classes without Importing Them Most classes need to be imported before they can be used in an app. Why is every app allowed to use classes System and String without first importing them?
Using a Class without Importing It Explain how a program could use class Scanner without importing it
set and get Methods Explain why a class might provide a set method and a get method for an instance variable.
Modified Account Class Modify class Account Fig to provide a method called withdraw that withdraws money from an Account. Ensure that the withdrawal amount does not exceed the Accounts balance. If it does, the balance should be left unchanged and the method should print a message indicating "Withdrawal amount exceeded account balance." Modify class AccountTest Fig to test method withdraw.
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 variablesa 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 ie 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 If the price per item is not positive, it should be set to Write a test app named InvoiceTest that demonstrates class Invoices capabilities.
Employee Class Create a class called Employee that includes three instance variablesa 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 Employees capabilities. Create two Employee objects and display each objects yearly salary. Then give each Employee a raise and display each Employees yearly salary again.
Date Class Create a class called Date that includes three instance variablesa 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 Dates capabilities.
Removing Duplicated Code in Method main In the AccountTest class of Fig. method main contains six statements lines and that each display an Account objects name and balance. Study these statements and youll notice that they differ only in the Account object being manipulatedaccount or account In this exercise, youll define a new displayAccount method that contains one copy of that output statement. The methods parameter will be an Account object and the method will output the objects name and balance. Youll 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 of Fig. to declare method displayAccount Fig after the closing right brace of main and before the closing right brace of class AccountTest. Replace the comment in the methods body with a statement that displays accountToDisplays name and balance.
Fig.
public static void displayAccountAccount accountToDisplay
place the statement that displays
accountToDisplay's name and balance here
Method displayAccount to add to class Account.
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 youve completed displayAccounts declaration, modify main to replace the statements that display each Accounts name and balance with calls to displayAccounteach receiving as its argument the account or account object, as appropr
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
