Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming Program 1 Advanced Class Creation Create an BankAccount Class that has an account id number (of type integer), balance (of type double), and

Java Programming

Program 1 Advanced Class Creation

Create an BankAccount Class that has an account id number (of type integer), balance (of type double), and rate (of type double) as private data. Define three overloaded constructors, one full constructor which brings in parameters to set all attrributes, one partial constructor which brings in one p[arameter to set account id and uses 0 for the balance and rate, and a non-arg constructor which uses default value for each attribute. Make sure to include error handlings, either selection or try/catch, to make sure the balance and rate are not negative.Add get and set methods for these three variables to work with these attributes. Create a deposit method and a withdraw method for user to deposit or withdraw user specified amount to or from the BankAccount.

In main method defined in another class file BankAccountTest, create 2-3 objects of BankAccount and work with their values and output them to the user to test your new class.

Program 2 Composition

Take the BankAccount Class from the first program and copy it into this program. You will use it as one of the classes in this one.

Create a BankCustomer class with 3 BankAccount objects inside it as private variables (of type BankAccount) as well as one customer name (of type String). [The three accounts are for checking, savings, and money market.] The constructors you make are up to you in this BankCustomer class, you can create one or two or more overloaded constructors: full constructor, partial constructor, and/or non-arg constructor. Create getter and setter methods for these four attributes, three BankAccount variables and one String ustomerName, to work with these attributes. Create a method to get total balance of all 3 BankAccount objects.

In main method of BankCustomerTest class file, create two BankCustomers, with their names and all account information and the values in them for the user. Then add 1000 to the checking account of the first one and 500 to the savings account of the second one and print all account information and the values in them for the user to test your new class and working with its internal objects through the outer class.

Program 3 -Inheritance and polymorphism

Part 1 Inheritance

Create a Rental class for a company who rents moving trucks for people with the following 3 attributes: name (of type string), number of days (of type integer), and additional fees (of type double). [The additional fees are for things like moving boxes purchased as part of the rental.] Make all the getters and setters as well as a full constructor for this class that takes all three variables and sets them. Make an abstract method called payRental() in this class as well.

Create a weekDayRental class that inherits from the Rental and takes all three values in its constructor and passes them to the parent. Override the payRental() method in this class that multiplies the number of days by $79 [fixed amount the company advertises] and adds the additional fees and prints this value for the user.

Create a weekEndRental class with a weekend rate (of type double) that inherits from the Rental and takes this value as well as the three values for a Rental in its constructor and passes them to the parent. Make a getter and setter for the weekend rate. Override the payRental() method in this class that multiplies the number or days by the weekend rate and adds the additional fees and prints this value for the user.

Part 2 polymorphism

Make test code in a separate class, RentalTest to test the Rental class and its two subclasses. In its main() methods, create an array of 4 Rental customers, two of them should be doing weekday rentals and another two should be doing weekend rentals, loop through the array so each element polymorphically calls payReantal method and prints the rental amount.

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

More Books

Students also viewed these Databases questions