Answered step by step
Verified Expert Solution
Link Copied!

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 Location3D and implement it in a file Location3D.java. This class can be used to keep track of the position of a location in three-dimensional space. For example, point A in the below figure has three coordinates: x=1.0,y=0, and z=1.0.
(5 pts) The Location3D class contains the following instance variables:
Instance variables to store the three coordinates x,y,z of a location.
An array of Location3D to store the 3 nearest neighbors of the current location. For example, in the above figure, points B,C,D are the 3 nearest neighbors of A.
You are required to implement the following methods:
(1)(5 pts) One no-argument constructor. This constructor sets null to all the variables with non-primitive data types and sets zero to double variables.
public Location3D()
(2)(10 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 Location3D.
public Location3D (Object obj)
(3)(10 pts) The clone method. Need to be deep copy.
(4)(5 pts) The get and set methods of all the instance variables.
(5)(10 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 x,y,z.
1
(6)(10 pts) equals method
This method returns true if the given object's x,y,z are the same as x,y,z of the given Location 3D 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 Location3D class.
public boolean equals (Object obj)
(7)(10 pts) A method to rotate the location by a specified angle around a specified axis.
public void rotate(double theta, int axis)
To compute these rotations, you will need a bit of trigonometry. Suppose you have a location with coordinates x,y, and z. After rotating this location by angle , the location will have new coordinates, which we will call x',y', and z'. The equations for the new coordinates use the java.lang methods Math.sin and Math.cos, as shown below:
After a rotation around the x-asis (i.e., axis =0):
x'=x
y'=ycos()-zsin()
z'=ysin()+zcos()
After a rotation around the y-asis (i.e., axis =1):
x'=xcos()+zsin()
y'=y
After a rotation around the z-asis (i.e., axis =2):
x'=xcos()-ysin()
y'=xsin()+ycos()
z'=z
Question 2(30 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:
(5 pts) The constructor will set both the balance and the annual interest rate to some initial values.
(5 pts) The no-arguments constructor that sets both the balance and the interest rate to zero.
(5 pts) The methods to change or retrieve the current balance or interest rate.
(5 pts) The methods to make a deposit (add to the balance) or a withdrawal (subtract from the balance).
(5 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 (e.g.,1 year indicates that the account should have 1 year's interest added). You can use the following compound interest formula to calculate the interest:
Compound Interest = Amount - Principal
Amount =P(1+rn)nt
where,
P= principal
r= rate of interest
2
n= number of times interest is compounded per year
t= time (in years)
Implement all the above methods. The correct declaration of class and instance variables gets 5 pts.
Question 3(5 pt
Write a main method to test the 2 classes location3D and bankAccount.
image text in transcribed

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

Students also viewed these Databases questions

Question

Evaluate the importance of diversity in the workforce.

Answered: 1 week ago

Question

Identify the legal standards of the recruitment process.

Answered: 1 week ago