SlideShare a Scribd company logo
1 of 10
Download to read offline
Read carefully. Im not sure if the point class is correct but posting it too.
In this program, you are to write 3 different classes that should work together as aggregate
classes (“has-a”relationship) and using inheritance (“is-a” relationship). It will also use your
knowledge of .equals methods, constructors, and deep vs. shallow copies. The classes you
should implement are:
1.Point – this should be the same Point.java that you have already implemented in MinilabPoint.
Later, it will beused as part of an aggregate class called Ray (a Ray “has-a” Point as part of its
data – see below for details onRay).
2. Ray – this will implement a Mathematical Ray. It should have the following:
Data: That hold an endpoint (as a Point) and a direction (as an int that stores the number of
degrees fromthe x-axis). that hold the x-value and the y-value. This data will be eventually be
inherited by asubclass (see below) and should not be public. Examples of Rays are shown below:
One Ray has an endpoint of the Point (2, 3) and a directionof 45 (since it is a 45º angle with the
x-axis).The other Ray has an endpoint of the Point (0, 0) and adirection of 135 (since it is a 135º
reference angle with the x-axis).
Constructors: A default constructor that will initialize the endpoint to a new Point that is (3, 4)
and the direction
to 135. A parameterized constructor that will receive the endpoint (as a Point) and the direction
(as an int). If the direction is not between 0 and 359 (inclusive), thenthrow new
IllegalArgumentException(<”your descriptive String here”>);If the direction is OK, then
initialize the data to what is received. Be sure a deep copy is used. A copy constructor that will
receive another Ray. It should initialize its data to be the same as the
Ray that was received. Be sure a deep copy is used.
Methods: A toString() method that returns a String representing the Ray. It should be in the
form endpoint-----> direction Example: (3, 4)----->135It is using 5 dashes, a >, and a
space. Be exact.
A method called translate(int xmove, int ymove) that will return nothing and “translates,” or
shifts,
the endpoint by the distances passed in.
A method called rotate(int angle), which will receive an angle and return nothing. If the
anglereceived is negative, it should:throw new IllegalArgumentException(<”your descriptive
String here”>);
If the angle is OK, then it should change the direction by adding the angle to it. But…if that
makes the direction be >= 360, then the method should change it to be from 0-359. For
example:If (3, 4)----->135 is told to rotate(800) then its direction will change to 835. But
that isactually twice around the circle and ending up at 935. So it should be corrected to finally
be: (3, 4)----->215
A method called equals(Object obj), which receives an Object and returns true if it’s endpoint
and
its direction are both equal to the endpoint and direction of the Object (Ray) that was received.
Itshould be implemented like we did in class.
A method called getEndpoint, which receives nothing and returns the endpoint (as a Point).
Besure it returns a deep copy. A method called setEndpoint(Point p), which receives a Point
and returns nothing. It should set itsendpoint to a deep copy of what is received.
A method called aboveXAxis(), which returns a boolean that will be true if any part of the
Rayextends to above the x-axis (in Quadrant 1 or Quadrant 2).
3. StyleRay – this will be a subclass of Ray and will also store what it looks like as a String
(either “dashed”,
“dotted”, or “double”). Data:
It will also have an endpoint (as a Point) and a direction (as an int). Both of those are
justinherited from the parent class. In addition, StyleRay should have a String which holds the
style(either “dashed”, “dotted”, or “double”).Constructors: Since constructors are not inherited,
you will have to implement these constructors. Insome cases they work similarly to the parent
class’s constructors. A default constructor that will initialize the endpoint to a new Point that is
(3, 4) and the directionto 135 (same as its parent class). In addition, it will initialize its style to
“double”.
A parameterized constructor that will receive the endpoint (as a Point) and the direction (as an
int)and the style (as a String). If the direction is not between 0 and 359 (inclusive), thenthrow
new IllegalArgumentException(<”your descriptive String here”>);Also, if the style that is
received is not equal to “double” or “dashed” or “dotted” thenthrow new
IllegalArgumentException(<”your descriptive String here”>);If the direction and style are OK,
then initialize the data to the Point, int, and String that arereceived. Be sure a deep copy is used.
A copy constructor that will receive another StyleRay. It should initialize its data to be the same
as the StyleRay that was received. Be sure deep copies are used.
Methods: Almost every StyleRay method can be inherited except for the following
A toString() method which will receive nothing and return a String representing the
StyleRay.Depending on the type, the String representation will look like this:
If the style equals “double” it should be endpoint=====> direction
Example: (3, 4)=====> 135It is using 5 equal signs, a >, and a space. Be exact.
If the style equals “dotted” it should be endpoint…..> direction
Example: (3, 4)…..> 135It is using 5 dots, a >, and a space. Be exact.
If the style equals “dashed” it should be endpoint- - -> direction
Example: (3, 4)- - -> 135It is using 3 dashes with a space between each, then a > and aspace.
Be exact.
If the style is anything but the above, something is wrong. It should not happen, but youcan use
a last else in your logic and:throw new IllegalStateException(<”your descriptive String here”>);
A method called equals(Object obj), which receives an Object and returns true if it’s endpoint
and
its direction are both equal to the endpoint and direction of the Object (StyleRay) that was
received. NOTE that it does not check to see if the styles are the same. It should be
implemented like wedid in class.
Point Class:
class Point {
// integers set to private
private int x;
private int y;
//default constructor
public Point ()
{
x=4;
y=-2;
}
//parameterized constructor
public Point (int x, int y)
{
this.x=x;
this.y=y;
}
//Copy Constructor
public Point (Point p)
{
this.x=p.x;
this.y=p.y;
}
//which receives nothing and just returns the x value. (This
//is an example of a “getter,” or “accessor” method)
int getX()
{
return this.x;
}
//receives an int and sets its x value to
//what is received.
void setX(int newX)
{
this.x=newX;
}
// Inquadrant 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
boolean inQuadrant(int theQuadrant)
{
switch(theQuadrant)
{
case 1 :
if(this.x>0 && this.y>0)
{ return true;
}
break;
case 2 :
if(this.x<0 && this.y>0)
{ return true;
}
break;
case 3 :
if(this.x<0 && this.y<0)
{
return true;
}
break;
case 4 :
if(this.x>0 && this.y<0)
{
return true;
}
break;
default :
//If theQuadrant is not in the range 1-4.
throw new IllegalArgumentException("Quadrant should be 1,2,3 or 4.. "
+ "You have entered quadrant as "+theQuadrant);
} return false;
}
void translate(int xmove,int ymove)
{
this.x=this.x+xmove;
this.y=this.y+ymove;
}
// String representing the
//current instance
@Override
public String toString()
{
return "(" + this.x + ", " + this.y + ")";
}
//returns true
@Override
public boolean equals(Object obj) {
if(obj instanceof Point){
Point p = (Point)obj;
if(x == p.x && y == p.y)
return true;
}
return false;
}
}
Solution
I used the same Point class provided.
PROGRAM CODE:
Ray.java
package math;
public class Ray {
private Point endPoint;
public int direction;
protected int x;
protected int y;
Ray()
{
endPoint = new Point(3,4);
direction = 135;
}
Ray(Point endPoint, int direction)
{
this.endPoint = new Point(endPoint);
if(direction >=0 && direction<=359)
{
this.direction = new Integer(direction);
}
else throw new IllegalArgumentException("Direction is out of range");
}
Ray(Ray other)
{
this.endPoint = new Point(other.endPoint);
this.direction = new Integer(other.direction);
}
@Override
public String toString() {
// TODO Auto-generated method stub
return endPoint + "-----> " + direction;
}
void translate(int xmove, int ymove)
{
endPoint.translate(xmove, ymove);
}
void rotate(int angle)
{
if(angle<0)
throw new IllegalArgumentException("Angle is negative");
else
{
direction += angle;
while(direction >= 360)
{
direction -= 360;
}
}
}
@Override
public boolean equals(Object obj) {
if(obj instanceof Ray)
{
Ray ray = (Ray) obj;
if(endPoint.equals(ray.endPoint) && ray.direction == direction)
{
return true;
}
}
return false;
}
public Point getEndpoint()
{
return endPoint;
}
public void setEndpoint(Point p)
{
endPoint = new Point(p);
}
public boolean aboveXAxis()
{
if(endPoint.inQuadrant(1) && endPoint.inQuadrant(2))
return true;
else return false;
}
}
StyleRay.java
package math;
public class StyleRay extends Ray{
String style;
public StyleRay() {
super();
this.style ="double";
}
StyleRay(Point endPoint, int direction, String style)
{
super(endPoint, direction);
if(style.equals("double") || style.equals("dashed")||style.equals("dotted"))
this.style = new String(style);
}
StyleRay(StyleRay other)
{
this(other.getEndpoint(), other.direction, other.style);
}
@Override
public String toString() {
if(style.equals("double"))
return getEndpoint() + "=====> " + direction;
else if(style.equals("double"))
return getEndpoint() + ".....> " + direction;
else if(style.equals("double"))
return getEndpoint() + "- - -> " + direction;
else throw new IllegalArgumentException("Invalid style");
}
@Override
//Super class - Ray does the same job which is required here
public boolean equals(Object obj) {
if(obj instanceof StyleRay)
{
StyleRay styleray = (StyleRay)obj;
Ray ray = new Ray(styleray.getEndpoint(), styleray.direction);
return super.equals(ray);
}
return false;
}
}
Tester.java
package math;
public class Tester {
/**
* @param args
*/
public static void main(String[] args) {
Ray ray1 = new Ray();
System.out.println(ray1);
Ray ray2 = new Ray(new Point(5,5), 110);
System.out.println(ray2);
ray2.rotate(400);
System.out.println(ray2);
StyleRay styleray = new StyleRay(new Point(2,3), 345, "double");
System.out.println(styleray);
}
}
OUTPUT:
(3, 4)-----> 135
(5, 5)-----> 110
(5, 5)-----> 150
(2, 3)=====> 345

More Related Content

Similar to Read carefully. Im not sure if the point class is correct but postin.pdf

Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureZidny Nafan
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureSriram Raj
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaSandesh Sharma
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...vekariyakashyap
 
Built in classes in java
Built in classes in javaBuilt in classes in java
Built in classes in javaMahmoud Ali
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scalashinolajla
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6Nitay Neeman
 
1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdf1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdfjeeteshmalani1
 
Hive Functions Cheat Sheet
Hive Functions Cheat SheetHive Functions Cheat Sheet
Hive Functions Cheat SheetHortonworks
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arraysmaamir farooq
 
Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Bryan O'Sullivan
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascriptMD Sayem Ahmed
 

Similar to Read carefully. Im not sure if the point class is correct but postin.pdf (20)

Java script arrays
Java script arraysJava script arrays
Java script arrays
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
00-review.ppt
00-review.ppt00-review.ppt
00-review.ppt
 
130717666736980000
130717666736980000130717666736980000
130717666736980000
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharma
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
 
Built in classes in java
Built in classes in javaBuilt in classes in java
Built in classes in java
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6
 
1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdf1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdf
 
Hive Functions Cheat Sheet
Hive Functions Cheat SheetHive Functions Cheat Sheet
Hive Functions Cheat Sheet
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arrays
 
Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Real World Haskell: Lecture 4
Real World Haskell: Lecture 4
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
 
WD programs descriptions.docx
WD programs descriptions.docxWD programs descriptions.docx
WD programs descriptions.docx
 

More from bharatchawla141

Explain how HPV leads to cervical cancer and oral cancer. Include.pdf
Explain how HPV leads to cervical cancer and oral cancer. Include.pdfExplain how HPV leads to cervical cancer and oral cancer. Include.pdf
Explain how HPV leads to cervical cancer and oral cancer. Include.pdfbharatchawla141
 
Consider L = {a^nb^2nc^P p 0}. Prove L is not a context-free langu.pdf
Consider L = {a^nb^2nc^P  p  0}. Prove L is not a context-free langu.pdfConsider L = {a^nb^2nc^P  p  0}. Prove L is not a context-free langu.pdf
Consider L = {a^nb^2nc^P p 0}. Prove L is not a context-free langu.pdfbharatchawla141
 
Differentiate between analog and digital signals.SolutionIn ana.pdf
Differentiate between analog and digital signals.SolutionIn ana.pdfDifferentiate between analog and digital signals.SolutionIn ana.pdf
Differentiate between analog and digital signals.SolutionIn ana.pdfbharatchawla141
 
describe two properties of iPS and ES cells, including the meaning i.pdf
describe two properties of iPS and ES cells, including the meaning i.pdfdescribe two properties of iPS and ES cells, including the meaning i.pdf
describe two properties of iPS and ES cells, including the meaning i.pdfbharatchawla141
 
Coffman Company issued 1,000,000 10 year 10 percent bonds January 1,.pdf
Coffman Company issued 1,000,000 10 year 10 percent bonds January 1,.pdfCoffman Company issued 1,000,000 10 year 10 percent bonds January 1,.pdf
Coffman Company issued 1,000,000 10 year 10 percent bonds January 1,.pdfbharatchawla141
 
A JAR file contains an image named images Fall.png. Java class na.pdf
A JAR file contains an image named images Fall.png. Java class na.pdfA JAR file contains an image named images Fall.png. Java class na.pdf
A JAR file contains an image named images Fall.png. Java class na.pdfbharatchawla141
 
A 71-year-old male patient comes to the hospital after having been p.pdf
A 71-year-old male patient comes to the hospital after having been p.pdfA 71-year-old male patient comes to the hospital after having been p.pdf
A 71-year-old male patient comes to the hospital after having been p.pdfbharatchawla141
 
You are carrying out experiments in cell fusion by fusing together ce.pdf
You are carrying out experiments in cell fusion by fusing together ce.pdfYou are carrying out experiments in cell fusion by fusing together ce.pdf
You are carrying out experiments in cell fusion by fusing together ce.pdfbharatchawla141
 
Write an MPI program that implements a shell-sort like parallel algo.pdf
Write an MPI program that implements a shell-sort like parallel algo.pdfWrite an MPI program that implements a shell-sort like parallel algo.pdf
Write an MPI program that implements a shell-sort like parallel algo.pdfbharatchawla141
 
Which of the following are roles of proteins Pick ALL that apply..pdf
Which of the following are roles of proteins Pick ALL that apply..pdfWhich of the following are roles of proteins Pick ALL that apply..pdf
Which of the following are roles of proteins Pick ALL that apply..pdfbharatchawla141
 
When are a persons fellowship, autonomy, and competence face threa.pdf
When are a persons fellowship, autonomy, and competence face threa.pdfWhen are a persons fellowship, autonomy, and competence face threa.pdf
When are a persons fellowship, autonomy, and competence face threa.pdfbharatchawla141
 
What is the function in homworts Where can one find homwortsS.pdf
What is the function  in homworts  Where can one find homwortsS.pdfWhat is the function  in homworts  Where can one find homwortsS.pdf
What is the function in homworts Where can one find homwortsS.pdfbharatchawla141
 
This is the assignmentOBJECTIVESAfter finishing this lab, stude.pdf
This is the assignmentOBJECTIVESAfter finishing this lab, stude.pdfThis is the assignmentOBJECTIVESAfter finishing this lab, stude.pdf
This is the assignmentOBJECTIVESAfter finishing this lab, stude.pdfbharatchawla141
 
Two paragraph opinion about the film editing of the movie LIFE OF .pdf
Two paragraph opinion about the film editing of the movie LIFE OF .pdfTwo paragraph opinion about the film editing of the movie LIFE OF .pdf
Two paragraph opinion about the film editing of the movie LIFE OF .pdfbharatchawla141
 
True or False The aDDM fixes the SV reference problem by assuming t.pdf
True or False The aDDM fixes the SV reference problem by assuming t.pdfTrue or False The aDDM fixes the SV reference problem by assuming t.pdf
True or False The aDDM fixes the SV reference problem by assuming t.pdfbharatchawla141
 
The number of visits to public libraries increased from 1.4 billion i.pdf
The number of visits to public libraries increased from 1.4 billion i.pdfThe number of visits to public libraries increased from 1.4 billion i.pdf
The number of visits to public libraries increased from 1.4 billion i.pdfbharatchawla141
 
The first table contains data of the Student entry. Attributes are Si.pdf
The first table contains data of the Student entry. Attributes are Si.pdfThe first table contains data of the Student entry. Attributes are Si.pdf
The first table contains data of the Student entry. Attributes are Si.pdfbharatchawla141
 
Save for Later 12) Viruses, adware and spyware are referred to collec.pdf
Save for Later 12) Viruses, adware and spyware are referred to collec.pdfSave for Later 12) Viruses, adware and spyware are referred to collec.pdf
Save for Later 12) Viruses, adware and spyware are referred to collec.pdfbharatchawla141
 
Sustainability Sustainability is an important consideration for any.pdf
Sustainability Sustainability is an important consideration for any.pdfSustainability Sustainability is an important consideration for any.pdf
Sustainability Sustainability is an important consideration for any.pdfbharatchawla141
 
Research health data stewardship and in your post show why it is imp.pdf
Research health data stewardship and in your post show why it is imp.pdfResearch health data stewardship and in your post show why it is imp.pdf
Research health data stewardship and in your post show why it is imp.pdfbharatchawla141
 

More from bharatchawla141 (20)

Explain how HPV leads to cervical cancer and oral cancer. Include.pdf
Explain how HPV leads to cervical cancer and oral cancer. Include.pdfExplain how HPV leads to cervical cancer and oral cancer. Include.pdf
Explain how HPV leads to cervical cancer and oral cancer. Include.pdf
 
Consider L = {a^nb^2nc^P p 0}. Prove L is not a context-free langu.pdf
Consider L = {a^nb^2nc^P  p  0}. Prove L is not a context-free langu.pdfConsider L = {a^nb^2nc^P  p  0}. Prove L is not a context-free langu.pdf
Consider L = {a^nb^2nc^P p 0}. Prove L is not a context-free langu.pdf
 
Differentiate between analog and digital signals.SolutionIn ana.pdf
Differentiate between analog and digital signals.SolutionIn ana.pdfDifferentiate between analog and digital signals.SolutionIn ana.pdf
Differentiate between analog and digital signals.SolutionIn ana.pdf
 
describe two properties of iPS and ES cells, including the meaning i.pdf
describe two properties of iPS and ES cells, including the meaning i.pdfdescribe two properties of iPS and ES cells, including the meaning i.pdf
describe two properties of iPS and ES cells, including the meaning i.pdf
 
Coffman Company issued 1,000,000 10 year 10 percent bonds January 1,.pdf
Coffman Company issued 1,000,000 10 year 10 percent bonds January 1,.pdfCoffman Company issued 1,000,000 10 year 10 percent bonds January 1,.pdf
Coffman Company issued 1,000,000 10 year 10 percent bonds January 1,.pdf
 
A JAR file contains an image named images Fall.png. Java class na.pdf
A JAR file contains an image named images Fall.png. Java class na.pdfA JAR file contains an image named images Fall.png. Java class na.pdf
A JAR file contains an image named images Fall.png. Java class na.pdf
 
A 71-year-old male patient comes to the hospital after having been p.pdf
A 71-year-old male patient comes to the hospital after having been p.pdfA 71-year-old male patient comes to the hospital after having been p.pdf
A 71-year-old male patient comes to the hospital after having been p.pdf
 
You are carrying out experiments in cell fusion by fusing together ce.pdf
You are carrying out experiments in cell fusion by fusing together ce.pdfYou are carrying out experiments in cell fusion by fusing together ce.pdf
You are carrying out experiments in cell fusion by fusing together ce.pdf
 
Write an MPI program that implements a shell-sort like parallel algo.pdf
Write an MPI program that implements a shell-sort like parallel algo.pdfWrite an MPI program that implements a shell-sort like parallel algo.pdf
Write an MPI program that implements a shell-sort like parallel algo.pdf
 
Which of the following are roles of proteins Pick ALL that apply..pdf
Which of the following are roles of proteins Pick ALL that apply..pdfWhich of the following are roles of proteins Pick ALL that apply..pdf
Which of the following are roles of proteins Pick ALL that apply..pdf
 
When are a persons fellowship, autonomy, and competence face threa.pdf
When are a persons fellowship, autonomy, and competence face threa.pdfWhen are a persons fellowship, autonomy, and competence face threa.pdf
When are a persons fellowship, autonomy, and competence face threa.pdf
 
What is the function in homworts Where can one find homwortsS.pdf
What is the function  in homworts  Where can one find homwortsS.pdfWhat is the function  in homworts  Where can one find homwortsS.pdf
What is the function in homworts Where can one find homwortsS.pdf
 
This is the assignmentOBJECTIVESAfter finishing this lab, stude.pdf
This is the assignmentOBJECTIVESAfter finishing this lab, stude.pdfThis is the assignmentOBJECTIVESAfter finishing this lab, stude.pdf
This is the assignmentOBJECTIVESAfter finishing this lab, stude.pdf
 
Two paragraph opinion about the film editing of the movie LIFE OF .pdf
Two paragraph opinion about the film editing of the movie LIFE OF .pdfTwo paragraph opinion about the film editing of the movie LIFE OF .pdf
Two paragraph opinion about the film editing of the movie LIFE OF .pdf
 
True or False The aDDM fixes the SV reference problem by assuming t.pdf
True or False The aDDM fixes the SV reference problem by assuming t.pdfTrue or False The aDDM fixes the SV reference problem by assuming t.pdf
True or False The aDDM fixes the SV reference problem by assuming t.pdf
 
The number of visits to public libraries increased from 1.4 billion i.pdf
The number of visits to public libraries increased from 1.4 billion i.pdfThe number of visits to public libraries increased from 1.4 billion i.pdf
The number of visits to public libraries increased from 1.4 billion i.pdf
 
The first table contains data of the Student entry. Attributes are Si.pdf
The first table contains data of the Student entry. Attributes are Si.pdfThe first table contains data of the Student entry. Attributes are Si.pdf
The first table contains data of the Student entry. Attributes are Si.pdf
 
Save for Later 12) Viruses, adware and spyware are referred to collec.pdf
Save for Later 12) Viruses, adware and spyware are referred to collec.pdfSave for Later 12) Viruses, adware and spyware are referred to collec.pdf
Save for Later 12) Viruses, adware and spyware are referred to collec.pdf
 
Sustainability Sustainability is an important consideration for any.pdf
Sustainability Sustainability is an important consideration for any.pdfSustainability Sustainability is an important consideration for any.pdf
Sustainability Sustainability is an important consideration for any.pdf
 
Research health data stewardship and in your post show why it is imp.pdf
Research health data stewardship and in your post show why it is imp.pdfResearch health data stewardship and in your post show why it is imp.pdf
Research health data stewardship and in your post show why it is imp.pdf
 

Recently uploaded

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 

Read carefully. Im not sure if the point class is correct but postin.pdf

  • 1. Read carefully. Im not sure if the point class is correct but posting it too. In this program, you are to write 3 different classes that should work together as aggregate classes (“has-a”relationship) and using inheritance (“is-a” relationship). It will also use your knowledge of .equals methods, constructors, and deep vs. shallow copies. The classes you should implement are: 1.Point – this should be the same Point.java that you have already implemented in MinilabPoint. Later, it will beused as part of an aggregate class called Ray (a Ray “has-a” Point as part of its data – see below for details onRay). 2. Ray – this will implement a Mathematical Ray. It should have the following: Data: That hold an endpoint (as a Point) and a direction (as an int that stores the number of degrees fromthe x-axis). that hold the x-value and the y-value. This data will be eventually be inherited by asubclass (see below) and should not be public. Examples of Rays are shown below: One Ray has an endpoint of the Point (2, 3) and a directionof 45 (since it is a 45º angle with the x-axis).The other Ray has an endpoint of the Point (0, 0) and adirection of 135 (since it is a 135º reference angle with the x-axis). Constructors: A default constructor that will initialize the endpoint to a new Point that is (3, 4) and the direction to 135. A parameterized constructor that will receive the endpoint (as a Point) and the direction (as an int). If the direction is not between 0 and 359 (inclusive), thenthrow new IllegalArgumentException(<”your descriptive String here”>);If the direction is OK, then initialize the data to what is received. Be sure a deep copy is used. A copy constructor that will receive another Ray. It should initialize its data to be the same as the Ray that was received. Be sure a deep copy is used. Methods: A toString() method that returns a String representing the Ray. It should be in the form endpoint-----> direction Example: (3, 4)----->135It is using 5 dashes, a >, and a space. Be exact. A method called translate(int xmove, int ymove) that will return nothing and “translates,” or shifts, the endpoint by the distances passed in. A method called rotate(int angle), which will receive an angle and return nothing. If the anglereceived is negative, it should:throw new IllegalArgumentException(<”your descriptive String here”>); If the angle is OK, then it should change the direction by adding the angle to it. But…if that makes the direction be >= 360, then the method should change it to be from 0-359. For
  • 2. example:If (3, 4)----->135 is told to rotate(800) then its direction will change to 835. But that isactually twice around the circle and ending up at 935. So it should be corrected to finally be: (3, 4)----->215 A method called equals(Object obj), which receives an Object and returns true if it’s endpoint and its direction are both equal to the endpoint and direction of the Object (Ray) that was received. Itshould be implemented like we did in class. A method called getEndpoint, which receives nothing and returns the endpoint (as a Point). Besure it returns a deep copy. A method called setEndpoint(Point p), which receives a Point and returns nothing. It should set itsendpoint to a deep copy of what is received. A method called aboveXAxis(), which returns a boolean that will be true if any part of the Rayextends to above the x-axis (in Quadrant 1 or Quadrant 2). 3. StyleRay – this will be a subclass of Ray and will also store what it looks like as a String (either “dashed”, “dotted”, or “double”). Data: It will also have an endpoint (as a Point) and a direction (as an int). Both of those are justinherited from the parent class. In addition, StyleRay should have a String which holds the style(either “dashed”, “dotted”, or “double”).Constructors: Since constructors are not inherited, you will have to implement these constructors. Insome cases they work similarly to the parent class’s constructors. A default constructor that will initialize the endpoint to a new Point that is (3, 4) and the directionto 135 (same as its parent class). In addition, it will initialize its style to “double”. A parameterized constructor that will receive the endpoint (as a Point) and the direction (as an int)and the style (as a String). If the direction is not between 0 and 359 (inclusive), thenthrow new IllegalArgumentException(<”your descriptive String here”>);Also, if the style that is received is not equal to “double” or “dashed” or “dotted” thenthrow new IllegalArgumentException(<”your descriptive String here”>);If the direction and style are OK, then initialize the data to the Point, int, and String that arereceived. Be sure a deep copy is used. A copy constructor that will receive another StyleRay. It should initialize its data to be the same as the StyleRay that was received. Be sure deep copies are used. Methods: Almost every StyleRay method can be inherited except for the following A toString() method which will receive nothing and return a String representing the StyleRay.Depending on the type, the String representation will look like this: If the style equals “double” it should be endpoint=====> direction Example: (3, 4)=====> 135It is using 5 equal signs, a >, and a space. Be exact. If the style equals “dotted” it should be endpoint…..> direction
  • 3. Example: (3, 4)…..> 135It is using 5 dots, a >, and a space. Be exact. If the style equals “dashed” it should be endpoint- - -> direction Example: (3, 4)- - -> 135It is using 3 dashes with a space between each, then a > and aspace. Be exact. If the style is anything but the above, something is wrong. It should not happen, but youcan use a last else in your logic and:throw new IllegalStateException(<”your descriptive String here”>); A method called equals(Object obj), which receives an Object and returns true if it’s endpoint and its direction are both equal to the endpoint and direction of the Object (StyleRay) that was received. NOTE that it does not check to see if the styles are the same. It should be implemented like wedid in class. Point Class: class Point { // integers set to private private int x; private int y; //default constructor public Point () { x=4; y=-2; } //parameterized constructor public Point (int x, int y) { this.x=x; this.y=y; } //Copy Constructor public Point (Point p) { this.x=p.x; this.y=p.y; } //which receives nothing and just returns the x value. (This //is an example of a “getter,” or “accessor” method)
  • 4. int getX() { return this.x; } //receives an int and sets its x value to //what is received. void setX(int newX) { this.x=newX; } // Inquadrant 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 boolean inQuadrant(int theQuadrant) { switch(theQuadrant) { case 1 : if(this.x>0 && this.y>0) { return true; } break; case 2 : if(this.x<0 && this.y>0) { return true; } break; case 3 : if(this.x<0 && this.y<0) { return true; } break; case 4 : if(this.x>0 && this.y<0)
  • 5. { return true; } break; default : //If theQuadrant is not in the range 1-4. throw new IllegalArgumentException("Quadrant should be 1,2,3 or 4.. " + "You have entered quadrant as "+theQuadrant); } return false; } void translate(int xmove,int ymove) { this.x=this.x+xmove; this.y=this.y+ymove; } // String representing the //current instance @Override public String toString() { return "(" + this.x + ", " + this.y + ")"; } //returns true @Override public boolean equals(Object obj) { if(obj instanceof Point){ Point p = (Point)obj; if(x == p.x && y == p.y) return true; } return false; } } Solution
  • 6. I used the same Point class provided. PROGRAM CODE: Ray.java package math; public class Ray { private Point endPoint; public int direction; protected int x; protected int y; Ray() { endPoint = new Point(3,4); direction = 135; } Ray(Point endPoint, int direction) { this.endPoint = new Point(endPoint); if(direction >=0 && direction<=359) { this.direction = new Integer(direction); } else throw new IllegalArgumentException("Direction is out of range"); } Ray(Ray other) { this.endPoint = new Point(other.endPoint); this.direction = new Integer(other.direction); } @Override public String toString() { // TODO Auto-generated method stub return endPoint + "-----> " + direction;
  • 7. } void translate(int xmove, int ymove) { endPoint.translate(xmove, ymove); } void rotate(int angle) { if(angle<0) throw new IllegalArgumentException("Angle is negative"); else { direction += angle; while(direction >= 360) { direction -= 360; } } } @Override public boolean equals(Object obj) { if(obj instanceof Ray) { Ray ray = (Ray) obj; if(endPoint.equals(ray.endPoint) && ray.direction == direction) { return true; } } return false; } public Point getEndpoint() {
  • 8. return endPoint; } public void setEndpoint(Point p) { endPoint = new Point(p); } public boolean aboveXAxis() { if(endPoint.inQuadrant(1) && endPoint.inQuadrant(2)) return true; else return false; } } StyleRay.java package math; public class StyleRay extends Ray{ String style; public StyleRay() { super(); this.style ="double"; } StyleRay(Point endPoint, int direction, String style) { super(endPoint, direction); if(style.equals("double") || style.equals("dashed")||style.equals("dotted")) this.style = new String(style); } StyleRay(StyleRay other) { this(other.getEndpoint(), other.direction, other.style); }
  • 9. @Override public String toString() { if(style.equals("double")) return getEndpoint() + "=====> " + direction; else if(style.equals("double")) return getEndpoint() + ".....> " + direction; else if(style.equals("double")) return getEndpoint() + "- - -> " + direction; else throw new IllegalArgumentException("Invalid style"); } @Override //Super class - Ray does the same job which is required here public boolean equals(Object obj) { if(obj instanceof StyleRay) { StyleRay styleray = (StyleRay)obj; Ray ray = new Ray(styleray.getEndpoint(), styleray.direction); return super.equals(ray); } return false; } } Tester.java package math; public class Tester { /** * @param args */ public static void main(String[] args) { Ray ray1 = new Ray(); System.out.println(ray1); Ray ray2 = new Ray(new Point(5,5), 110); System.out.println(ray2);
  • 10. ray2.rotate(400); System.out.println(ray2); StyleRay styleray = new StyleRay(new Point(2,3), 345, "double"); System.out.println(styleray); } } OUTPUT: (3, 4)-----> 135 (5, 5)-----> 110 (5, 5)-----> 150 (2, 3)=====> 345