Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this question, specify and design a class called Location 3 D and implement it in a file Location 3 D . java. This class
In this question, specify and design a class called LocationD and implement it in a file LocationDjava. This class can be used to keep track of the position of a location in threedimensional space. For example, point A in the below figure has three coordinates: and
pts The LocationD class contains the following instance variables:
Instance variables to store the three coordinates of a location.
An array of LocationD to store the nearest neighbors of the current location. For example, in the above figure, points are the nearest neighbors of
You are required to implement the following methods:
pts One noargument constructor. This constructor sets null to all the variables with nonprimitive data types and sets zero to double variables.
public LocationD
pts One copy constructor that uses the given parameter obj to set the current object's instance variables. Need to be a deep copy. The precondition is that obj should not be null and should be an instance of LocationD
public LocationD Object obj
pts The clone method. Need to be deep copy.
pts The get and set methods of all the instance variables.
pts tostring method to generate a string representation of a location.
public String toString
This method should organize the String information in the order of coordinates
pts equals method
This method returns true if the given object's are the same as of the given Location D instance which activates this method. Otherwise, this method returns false. The precondition is that obj should not be null and should be an instance of the LocationD class.
public boolean equals Object obj
pts A method to rotate the location by a specified angle around a specified axis.
public void rotatedouble theta, int axis
To compute these rotations, you will need a bit of trigonometry. Suppose you have a location with coordinates and After rotating this location by angle the location will have new coordinates, which we will call and The equations for the new coordinates use the java.lang methods Math.sin and Math.cos as shown below:
After a rotation around the asis ie axis :
After a rotation around the asis ie axis :
After a rotation around the asis ie axis :
Question pts
Write a class BankAccount to keep track of a balance in a bank account with a varying annual interest rate. The class has the following methods:
pts The constructor will set both the balance and the annual interest rate to some initial values.
pts The noarguments constructor that sets both the balance and the interest rate to zero.
pts The methods to change or retrieve the current balance or interest rate.
pts The methods to make a deposit add to the balance or a withdrawal subtract from the balance
pts The method to add interest to the balance at the current interest rate. This method should have a parameter indicating how many years' worth of interest are to be added eg year indicates that the account should have year's interest added You can use the following compound interest formula to calculate the interest:
Compound Interest Amount Principal
Amount
where,
principal
rate of interest
number of times interest is compounded per year
time in years
Implement all the above methods. The correct declaration of class and instance variables gets pts
Question pt
Write a main method to test the classes locationD and bankAccount.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started