Question
Requirements: You are to write a class called Point this will represent a geometric point in a Cartesian plane (but x and y should be
Requirements: You are to write a class called Point this will represent a geometric point in a Cartesian plane (but x and y should be ints). Point should have the following:
Data: that hold the x-value and the y-value. They should be ints and must be private.
Constructors:
A default constructor that will set the values to (3, -5)
A parameterized constructor that will receive 2 ints (x then y) and set the data to what is received.
A copy constructor that will receive a Point. If it receives null, then it should throw new IllegalArgumentException(
If it is OK, the it should initialize the data (of the new instance being created) to be the same as the Point that was received.
Methods:
A toString() method that receives nothing and returns a String representing the current
instance. It should be in the form (x, y) (with a space after the comma).
A method called inQuadrant(int theQuadrant) which returns true if the current instance is in theQuadrant, false otherwise. The quadrants are defined like in Math and do not include the axes themselves. If theQuadrant is not in the range 1-4, then inQuadrant should:
throw new IllegalArgumentException(
A method called onXAxis() which returns true if the current instance is on the x-axis, false otherwise.
A method called translate(int xmove, int ymove) that will return nothing and translates, or shifts, the data by the x and y distances that are received. So if a Point has data x=3 and y=5, translate(5,2) will cause it to change its data to x=8 and y=7.
A method called equals(Object obj) which returns true if it is equal to obj. Note that it receives an Object; there is a particular way that this method should be implemented (see notes/demos).
another class called term:
Write a class called Term. It will represent a Mathematical term in a polynomial (for example 3x4) Your Term class should implement TermInterface.
It should
It should - -
-
have data to represent the coefficient and power. For simplicity, we will let them be ints.
have 3 constructors A default constructor which will set the coefficient to 2 and the power to 3 A parameterized constructor which will receive the coefficient and the power (as ints) and set the data to what is received. A copy constructor which will receive another Term and set the coefficient and power to be the same as the Term that is received (thus copying it). If the copy constructor receives a value of null, it should throw a new IllegalArgumentException(your descriptive String here);
It should reuse the comments).
have methods to operate on the data. The methods are described in TermInterface (you can even
Using TermInterface
An interface is used to list the methods that must be implemented in your code. So in that sense, it enforces the design (since you cant misspell a method name or leave out a method). Your Term class should start out like this:
public class Term implements TermInterface
{... TermInterface must be in the same package as your Term class if you are compiling it at home. So you will have to download it from Canvas, put it in your program (either in same file or same project) and also submit it to HyperGrade.
The best way to use it is to copy all the code and use it as the outline for your methods. You can also use the comments as your method comments. Note that none of the methods in TermInterface have a body ( instead they just have a ; ). Do not change the TermInterface.java, but after you copy the methods, you will have to take out the ; and then implement the code.
If you use an interface and do not implement one of the methods (or you misspell it). It will not compile. The error you will get will say that Term is not abstract and does not implement
public interface TermInterface
{
// toString() - returns its representation as a String 3x^2 for
example,
// But to make it look better, follow this logic in order...
// - if coefficient is 0, return "0"
// - else if the power is 0, return the coefficient (as
a String, concatenate with "")
// - else if the coefficient is 1 and the power is 1,
return "x"
// - else if the coefficient is -1 and the power is 1,
return "-x"
// - else if the power is 1, return coefficient and "x"
// - else if coefficient is 1, return "x^" and the power
// - else if the coefficient is -1, return "-x^" and the
power
// - else return coefficient and "x^" and power
public String toString();
//evaluate - evalutes with whatever double is received
public double evaluate(double value);
//degree - if coefficient is 0, then (it is a constant so) returns
0.
// else returns the power
public int degree();
//derivative - return a new Term that is the derivative. The
derivative
// is calculated by:
// the coefficient of the
derivative is the original coefficient times the power
// the power of the derivative
is the original power minus 1
public Term derivative();
//addIn: add another Term to itself.
//The Term that is received is not changed.
// if the Term that is received is null, throw a new
IllegalArgumentException(
// if the powers are not the same, throw a new
IllegalArgumentException(
public void addIn(Term anotherTerm);
//multiplyBy: multiply itself by anotherTerm - result is a new Term
that is created and returned.
//The original Term and the Term that is received are not changed.
// if the Term that is received is null, throw a new
IllegalArgumentException(
public Term multiplyBy(Term anotherTerm);
//equals: returns true if it is the same as what is received.
// If both coefficients are 0, they are automatically equal
// otherwise, both coefficients AND both exponents must be the
same
public boolean equals(Object obj);
}
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