Tausif K.

asked • 11/20/20

java program to

a) An interface Polygon containing the members as given below: float area, float perimeter void calcArea( ); abstract method to calculate area of a particular polygon given its dimensions void calcPeri( ); abstract method to calculate perimeter of a particular polygon given its dimensions void display( ); method to display the area and perimeter of the given polygon. Create a class Square that implements Polygon and has the following member: float side Square(float s); constructor to initialize side of square Create another class Rectangle that implements Polygon and has the following member: float length float breadth Rectangle(int len, int bre); constructor to initialize length and breadth of a rectangle 10 10 1,2 10,11 12 8/7/2020 Academic Documents (A-Z): L. Outside the package, create a class that imports the above package an instantiates an object of the Square class and an object of the Rectangle class. Call the above methods on each of the classes to calculate the area and perimeter given the side and the length/breadth of the Square class and the Rectangle class respectively.

(b) Create a class called CalcAverage that has the following method: public double avgFirstN(int N) This method receives an integer as a parameter and calculates the average of first N natural numbers. If N is not a natural number, throw an exception IllegalArgumentException with an appropriate message.

(c) Create a class Number having the following features: Attributes:          int               first number          int               second number          result          double                 stores the result of arithmetic operations performed on a and b Member functions: ·         Number(x, y) : constructor to initialize the values of a and b ·         add( ) : stores the sum of a and b in result ·         sub( ) : stores difference of a and b in result ·         mul( ) : stores product in result ·         div( ) : stores a divided by b in result Test to see if b is 0 and throw an appropriate exception since division by zero is undefined. Display a menu to the user to perform the above four arithmetic operations. (d) Create a class  BankAccount having the members as given below: accNo integer custName string accType string (indicates ‘Savings’ or ‘Current’) balance float Include the following methods in the BankAccount class: ·         void deposit(float amt); ·         void withdraw(float amt); ·         float getBalance(); deposit(float amt) method allows you to credit an amount into the current balance. If amount is negative, throw an exception NegativeAmount to block the operation from being performed. 8/7/2020 Academic Documents (A-Z): L. withdraw(float amt) method allows you to debit an amount from the current balance. Please ensure a minimum balance of Rs. 1000/- in the account for savings account and Rs. 5000/- for current account, else throw an exception InsufficientFunds and block the withdrawal operation. Also throw an exception NegativeAmount to block the operation from being performed if the amt parameter passed to this function is negative. getBalance( ) method returns the current balance. If the current balance is below the minimum required balance, then throw an exception LowBalanceException accordingly. Have constructor to which you will pass, accno, cust_name, acctype and initial balance. And check whether the balance is less than 1000 or not in case of savings account and less than 5000 in case of a current account. If so, then raise a LowBalanceException. In either case if the balance is negative then raise the NegativeAmount exception accordingly.          (e) Create a class with following specifications. Class Emp                                                            empId                   int                          empName   string                designation string                     basic           double                        hra              double        readOnly Methods ·         printDET( ) ·         kalculateHRA( ) ·         printDET( ) methods will show details of the EMP.                                       calculateHRA( ) method will calculate HRA based on basic. There will 3 designations supported by the application.                                                If designation  is “Manager”  - HRA will be 10% of BASIC if designation  is “Officer”  - HRA will be 12% of BASIC if category is “CLERK”  - HRA will be 5% of BASIC Have constructor to which you will pass, empId, designation, basic and price. And checks whether the BASIC is less than 500 or not. If it is less than 500 raise a custom Exception as given below Create LowSalException class with proper user message to handle BASIC less than 500.  

(e) Create a class USERTRAIL with following specifications.                   val1, val2 type    int Method 8/7/2020 Academic Documents (A-Z): L. boolean show( ) will check if val1 and val2 are greater or less than Zero Have constructor which will val1, val2 and check whether if it is less than 0  then raise a custom Exception (name: Illegal value exception.)

Patrick B.

All of this code is not going to fit here... send email so I can pass you the source code files.
Report

11/21/20

1 Expert Answer

By:

Patrick B. answered • 11/21/20

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.