SlideShare a Scribd company logo
1 of 9
Download to read offline
1- Create a class called Point that has two instance variables, defined as private, as follows: An x
coordinate and a y coordinate of type integer.
a) Write two constructors for the Point class as follows: A default constructor that sets the class
instance variables to zero and a constructor that receives two integer values and sets the instance
variables to them.
b) Write the set and get methods for the Point class to set and return the values of its instance
variables.
c) Write a toString() method for the Point class that prints the class name (Point) and the value of
its instance variables.
2- Create three classes called Circle, Rectangle and Square with the following properties:
- The Circle class has two instance variables – a position of type Point (the class that you just
created above) and a radius of type double. The instance variables position and radius specify the
position of the center and radius of the circle, respectively.
- The Rectangle class has three instance variables – a position of type Point (the class that you
just created above), a length and a width of type double. The instance variables position, length
and width specify the position of the top left corner, length and width of the rectangle,
respectively.
- The Square class has two instance variables – a position of type Point (the class that you just
created above) and a lengthof type double. The instance variables position andlength specify the
position of the top left corner and length of the square, respectively.
For each of the Circle, Rectangle andSquare classes do the following:
a) Define the instance variables as private.
b) Write two constructors for each class as follows: A default constructor that sets the instance
variables to zero and a constructor that receives values for the instance variables and sets them.
c) Write the set and get methods for each class to set and return the values of their instance
variables. For example, one of the get methods would return a Point.
d) Write a toString() method for each class that prints the class name (Circle, Rectangle or
Square) and the value of its instance variables.
e) Write two methods called getPerimeter() and getArea() for each class, which calculate and
return the perimeter and area of the class, respectively. For example, the getArea() method of the
Square class returns the area of the Square object.
3- Test the above classes by writing a class called GeometricTest.java that does the following:
- Creates instances of the Circle, Rectangle and Square classes as follows:
- Circle: positioned at x = 7, y = 3 and the radius = 4.5.
- Rectangle: positioned at x = 3, y = -1 and the length = 4.0 and width = 6.0.
- Square: positioned at x = 5, y = 8 and the length = 2.0.
- Prints each of the above objects.
- Changes the length of the Square object to 5.0.
- Prints the perimeter and area of each of each of the above objects.
- Compares the x coordinates of the Square and Rectangle classes and prints a message
specifying which one of them has a larger x coordinate.
Solution
import java.util.*;
import java.lang.*;
import java.io.*;
class Point
{
private int x;
private int y;
public Point()
{
this.x = 0;
this.y = 0;
}
public Point(int x,int y)
{
this.x = x;
this.y = y;
}
public int getX()
{
return this.x;
}
public int getY()
{
return this.y;
}
public void setX(int x)
{
this.x = x;
}
public void setY(int y)
{
this.y = y;
}
public String toString()
{
return "Point("+getX() +","+getY()+")";
}
};
class Rectangle extends Point
{
private Point p;
private double length;
private double width;
public Rectangle()
{
p.setX(0);
p.setY(0);
length = 0;
width =0;
}
public Rectangle(Point p,double length,double width)
{
this.p = p;
this.length = length;
this.width = width;
}
public double getWidth()
{
return width;
}
public double getLength()
{
return length;
}
public Point getPoint()
{
return this.p;
}
public double getArea() //compute the area of the rectangle.
{
double area;
area = getWidth() * getLength();
return area;
}
public double getPerimeter() //compute the perimeter of the rectangle
{
double perimeter;
perimeter = 2*(getWidth()+getLength());
return perimeter;
}
public String toString()
{
return "Rectangle : Top left Point :"+ getPoint() +" width :"+getWidth() + " height
:"+getLength();
}
}
class Circle extends Point
{
private Point p;
private double radius;
public Circle()
{
p.setX(0);
p.setY(0);
radius =0;
}
public Circle(Point p,double radius)
{
this.p = p;
this.radius = radius;
}
public double getRadius()
{
return radius;
}
public Point getPoint()
{
return this.p;
}
public double getArea() //compute the area of the circle.
{
double area;
area = 3.14 * getRadius() * getRadius();
return area;
}
public double getPerimeter() //compute the perimeter of the circle
{
double perimeter;
perimeter = 2* 3.14 *getRadius();
return perimeter;
}
public String toString()
{
return "Circle : center Point:"+ getPoint() +" radius "+getRadius();
}
}
class Square extends Point
{
private Point p;
private double length;
public Square()
{
p.setX(0);
p.setY(0);
length = 0;
}
public Square(Point p,double length)
{
this.p = p;
this.length = length;
}
public double getLength()
{
return length;
}
public Point getPoint()
{
return this.p;
}
public void setLength(double length)
{
this.length = length;
}
public double getArea() //compute the area of the square.
{
double area;
area = getLength() * getLength();
return area;
}
public double getPerimeter() //compute the perimeter of the square
{
double perimeter;
perimeter = 4*(getLength());
return perimeter;
}
public String toString()
{
return "Square : Top left Point :"+ getPoint() +" length :"+getLength() ;
}
}
class GeometricTest
{
public static void main (String[] args)
{
Point pc = new Point(7,3);
Circle c = new Circle(pc,4.5);
System.out.println(c.toString());
System.out.println("Area of circle = "+c.getArea());
System.out.println("Perimeter of circle = "+c.getPerimeter());
Point pr = new Point(3,-1);
Rectangle r = new Rectangle(pr,4.0,6.0);
System.out.println(r.toString());
System.out.println("Area of rectangle = "+r.getArea());
System.out.println("Perimeter of rectangle = "+r.getPerimeter());
Point ps = new Point(5,8);
Square s = new Square(ps,2.0);
s.setLength(5.0);
System.out.println(s.toString());
System.out.println("Area of square = "+s.getArea());
System.out.println("Perimeter of square = "+s.getPerimeter());
Point p1 = r.getPoint();
Point p2 = s.getPoint();
if(p1.getX() >p2.getX())
System.out.println("x-coordinate of rectangle is greater than x-coordinate of square");
else
System.out.println("x-coordinate of square is greater than x-coordinate of rectangle");
}
}
output:

More Related Content

Similar to 1- Create a class called Point that has two instance variables, defi.pdf

Read carefully. Im not sure if the point class is correct but postin.pdf
Read carefully. Im not sure if the point class is correct but postin.pdfRead carefully. Im not sure if the point class is correct but postin.pdf
Read carefully. Im not sure if the point class is correct but postin.pdfbharatchawla141
 
Csphtp1 09
Csphtp1 09Csphtp1 09
Csphtp1 09HUST
 
Abstract Classes Interface Exceptional Handling Java
Abstract Classes Interface Exceptional Handling JavaAbstract Classes Interface Exceptional Handling Java
Abstract Classes Interface Exceptional Handling JavaSyedShahroseSohail
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfaromanets
 
Csphtp1 10
Csphtp1 10Csphtp1 10
Csphtp1 10HUST
 
Object - Oriented Programming: Inheritance
Object - Oriented Programming: InheritanceObject - Oriented Programming: Inheritance
Object - Oriented Programming: InheritanceAndy Juan Sarango Veliz
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Palak Sanghani
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6sotlsoc
 
麻省理工C++公开教学课程(二)
麻省理工C++公开教学课程(二)麻省理工C++公开教学课程(二)
麻省理工C++公开教学课程(二)ProCharm
 

Similar to 1- Create a class called Point that has two instance variables, defi.pdf (12)

Read carefully. Im not sure if the point class is correct but postin.pdf
Read carefully. Im not sure if the point class is correct but postin.pdfRead carefully. Im not sure if the point class is correct but postin.pdf
Read carefully. Im not sure if the point class is correct but postin.pdf
 
3433 Ch09 Ppt
3433 Ch09 Ppt3433 Ch09 Ppt
3433 Ch09 Ppt
 
Csphtp1 09
Csphtp1 09Csphtp1 09
Csphtp1 09
 
Abstract Classes Interface Exceptional Handling Java
Abstract Classes Interface Exceptional Handling JavaAbstract Classes Interface Exceptional Handling Java
Abstract Classes Interface Exceptional Handling Java
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
 
Csphtp1 10
Csphtp1 10Csphtp1 10
Csphtp1 10
 
3433 Ch10 Ppt
3433 Ch10 Ppt3433 Ch10 Ppt
3433 Ch10 Ppt
 
Ch3
Ch3Ch3
Ch3
 
Object - Oriented Programming: Inheritance
Object - Oriented Programming: InheritanceObject - Oriented Programming: Inheritance
Object - Oriented Programming: Inheritance
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6
 
麻省理工C++公开教学课程(二)
麻省理工C++公开教学课程(二)麻省理工C++公开教学课程(二)
麻省理工C++公开教学课程(二)
 

More from jeeteshmalani1

How can you define the traits below and what are your thoughts on th.pdf
How can you define the traits below and what are your thoughts on th.pdfHow can you define the traits below and what are your thoughts on th.pdf
How can you define the traits below and what are your thoughts on th.pdfjeeteshmalani1
 
frank has klinefelter syndrome (47, XXY)... Frank has Klinefelter sy.pdf
frank has klinefelter syndrome (47, XXY)... Frank has Klinefelter sy.pdffrank has klinefelter syndrome (47, XXY)... Frank has Klinefelter sy.pdf
frank has klinefelter syndrome (47, XXY)... Frank has Klinefelter sy.pdfjeeteshmalani1
 
Does law provide liberty What is law How does law tend to be perve.pdf
Does law provide liberty What is law How does law tend to be perve.pdfDoes law provide liberty What is law How does law tend to be perve.pdf
Does law provide liberty What is law How does law tend to be perve.pdfjeeteshmalani1
 
Consider two n times n matrices C and D that commute under matrix mul.pdf
Consider two n times n matrices C and D that commute under matrix mul.pdfConsider two n times n matrices C and D that commute under matrix mul.pdf
Consider two n times n matrices C and D that commute under matrix mul.pdfjeeteshmalani1
 
Can someone help me setup this in JAVA Im new to java. Thanks.pdf
Can someone help me setup this in JAVA Im new to java. Thanks.pdfCan someone help me setup this in JAVA Im new to java. Thanks.pdf
Can someone help me setup this in JAVA Im new to java. Thanks.pdfjeeteshmalani1
 
atify and describe the cult alue dimensions that help ural profile of.pdf
atify and describe the cult alue dimensions that help ural profile of.pdfatify and describe the cult alue dimensions that help ural profile of.pdf
atify and describe the cult alue dimensions that help ural profile of.pdfjeeteshmalani1
 
21. Assume that mutations in the transformer (tra) and the male- spec.pdf
21. Assume that mutations in the transformer (tra) and the male- spec.pdf21. Assume that mutations in the transformer (tra) and the male- spec.pdf
21. Assume that mutations in the transformer (tra) and the male- spec.pdfjeeteshmalani1
 
Write one Conditional Signal Assignment VHDL code statement in the b.pdf
Write one Conditional Signal Assignment VHDL code statement in the b.pdfWrite one Conditional Signal Assignment VHDL code statement in the b.pdf
Write one Conditional Signal Assignment VHDL code statement in the b.pdfjeeteshmalani1
 
Write a two- to three- page paper responding to the questions at the.pdf
Write a two- to three- page paper responding to the questions at the.pdfWrite a two- to three- page paper responding to the questions at the.pdf
Write a two- to three- page paper responding to the questions at the.pdfjeeteshmalani1
 
1. Match the following. DOE is pursuing the demonstration of one suc.pdf
1. Match the following. DOE is pursuing the demonstration of one suc.pdf1. Match the following. DOE is pursuing the demonstration of one suc.pdf
1. Match the following. DOE is pursuing the demonstration of one suc.pdfjeeteshmalani1
 
Which of the following involve an increase in the entropy of the sys.pdf
Which of the following involve an increase in the entropy of the sys.pdfWhich of the following involve an increase in the entropy of the sys.pdf
Which of the following involve an increase in the entropy of the sys.pdfjeeteshmalani1
 
Which of the following was true about the Great Depression in th.pdf
Which of the following was true about the Great Depression in th.pdfWhich of the following was true about the Great Depression in th.pdf
Which of the following was true about the Great Depression in th.pdfjeeteshmalani1
 
What are the major concerns for corporations in developing and re.pdf
What are the major concerns for corporations in developing and re.pdfWhat are the major concerns for corporations in developing and re.pdf
What are the major concerns for corporations in developing and re.pdfjeeteshmalani1
 
Which factors might account for the specificity of certain viruses f.pdf
Which factors might account for the specificity of certain viruses f.pdfWhich factors might account for the specificity of certain viruses f.pdf
Which factors might account for the specificity of certain viruses f.pdfjeeteshmalani1
 
What basic auditing policy logs attempts to authenticate a user thro.pdf
What basic auditing policy logs attempts to authenticate a user thro.pdfWhat basic auditing policy logs attempts to authenticate a user thro.pdf
What basic auditing policy logs attempts to authenticate a user thro.pdfjeeteshmalani1
 
What is a warrant in Toulmins model of a syllogismA) A legal do.pdf
What is a warrant in Toulmins model of a syllogismA) A legal do.pdfWhat is a warrant in Toulmins model of a syllogismA) A legal do.pdf
What is a warrant in Toulmins model of a syllogismA) A legal do.pdfjeeteshmalani1
 
What are the main methods anthropologists use Give an example of ho.pdf
What are the main methods anthropologists use Give an example of ho.pdfWhat are the main methods anthropologists use Give an example of ho.pdf
What are the main methods anthropologists use Give an example of ho.pdfjeeteshmalani1
 
Arrange the following parts and processes of eukaryotic gene expressi.pdf
Arrange the following parts and processes of eukaryotic gene expressi.pdfArrange the following parts and processes of eukaryotic gene expressi.pdf
Arrange the following parts and processes of eukaryotic gene expressi.pdfjeeteshmalani1
 
The polarization of the CMB detected in the WMAP data is evidence fo.pdf
The polarization of the CMB detected in the WMAP data is evidence fo.pdfThe polarization of the CMB detected in the WMAP data is evidence fo.pdf
The polarization of the CMB detected in the WMAP data is evidence fo.pdfjeeteshmalani1
 
Technical Performance Measures are quantitative measures that must be.pdf
Technical Performance Measures are quantitative measures that must be.pdfTechnical Performance Measures are quantitative measures that must be.pdf
Technical Performance Measures are quantitative measures that must be.pdfjeeteshmalani1
 

More from jeeteshmalani1 (20)

How can you define the traits below and what are your thoughts on th.pdf
How can you define the traits below and what are your thoughts on th.pdfHow can you define the traits below and what are your thoughts on th.pdf
How can you define the traits below and what are your thoughts on th.pdf
 
frank has klinefelter syndrome (47, XXY)... Frank has Klinefelter sy.pdf
frank has klinefelter syndrome (47, XXY)... Frank has Klinefelter sy.pdffrank has klinefelter syndrome (47, XXY)... Frank has Klinefelter sy.pdf
frank has klinefelter syndrome (47, XXY)... Frank has Klinefelter sy.pdf
 
Does law provide liberty What is law How does law tend to be perve.pdf
Does law provide liberty What is law How does law tend to be perve.pdfDoes law provide liberty What is law How does law tend to be perve.pdf
Does law provide liberty What is law How does law tend to be perve.pdf
 
Consider two n times n matrices C and D that commute under matrix mul.pdf
Consider two n times n matrices C and D that commute under matrix mul.pdfConsider two n times n matrices C and D that commute under matrix mul.pdf
Consider two n times n matrices C and D that commute under matrix mul.pdf
 
Can someone help me setup this in JAVA Im new to java. Thanks.pdf
Can someone help me setup this in JAVA Im new to java. Thanks.pdfCan someone help me setup this in JAVA Im new to java. Thanks.pdf
Can someone help me setup this in JAVA Im new to java. Thanks.pdf
 
atify and describe the cult alue dimensions that help ural profile of.pdf
atify and describe the cult alue dimensions that help ural profile of.pdfatify and describe the cult alue dimensions that help ural profile of.pdf
atify and describe the cult alue dimensions that help ural profile of.pdf
 
21. Assume that mutations in the transformer (tra) and the male- spec.pdf
21. Assume that mutations in the transformer (tra) and the male- spec.pdf21. Assume that mutations in the transformer (tra) and the male- spec.pdf
21. Assume that mutations in the transformer (tra) and the male- spec.pdf
 
Write one Conditional Signal Assignment VHDL code statement in the b.pdf
Write one Conditional Signal Assignment VHDL code statement in the b.pdfWrite one Conditional Signal Assignment VHDL code statement in the b.pdf
Write one Conditional Signal Assignment VHDL code statement in the b.pdf
 
Write a two- to three- page paper responding to the questions at the.pdf
Write a two- to three- page paper responding to the questions at the.pdfWrite a two- to three- page paper responding to the questions at the.pdf
Write a two- to three- page paper responding to the questions at the.pdf
 
1. Match the following. DOE is pursuing the demonstration of one suc.pdf
1. Match the following. DOE is pursuing the demonstration of one suc.pdf1. Match the following. DOE is pursuing the demonstration of one suc.pdf
1. Match the following. DOE is pursuing the demonstration of one suc.pdf
 
Which of the following involve an increase in the entropy of the sys.pdf
Which of the following involve an increase in the entropy of the sys.pdfWhich of the following involve an increase in the entropy of the sys.pdf
Which of the following involve an increase in the entropy of the sys.pdf
 
Which of the following was true about the Great Depression in th.pdf
Which of the following was true about the Great Depression in th.pdfWhich of the following was true about the Great Depression in th.pdf
Which of the following was true about the Great Depression in th.pdf
 
What are the major concerns for corporations in developing and re.pdf
What are the major concerns for corporations in developing and re.pdfWhat are the major concerns for corporations in developing and re.pdf
What are the major concerns for corporations in developing and re.pdf
 
Which factors might account for the specificity of certain viruses f.pdf
Which factors might account for the specificity of certain viruses f.pdfWhich factors might account for the specificity of certain viruses f.pdf
Which factors might account for the specificity of certain viruses f.pdf
 
What basic auditing policy logs attempts to authenticate a user thro.pdf
What basic auditing policy logs attempts to authenticate a user thro.pdfWhat basic auditing policy logs attempts to authenticate a user thro.pdf
What basic auditing policy logs attempts to authenticate a user thro.pdf
 
What is a warrant in Toulmins model of a syllogismA) A legal do.pdf
What is a warrant in Toulmins model of a syllogismA) A legal do.pdfWhat is a warrant in Toulmins model of a syllogismA) A legal do.pdf
What is a warrant in Toulmins model of a syllogismA) A legal do.pdf
 
What are the main methods anthropologists use Give an example of ho.pdf
What are the main methods anthropologists use Give an example of ho.pdfWhat are the main methods anthropologists use Give an example of ho.pdf
What are the main methods anthropologists use Give an example of ho.pdf
 
Arrange the following parts and processes of eukaryotic gene expressi.pdf
Arrange the following parts and processes of eukaryotic gene expressi.pdfArrange the following parts and processes of eukaryotic gene expressi.pdf
Arrange the following parts and processes of eukaryotic gene expressi.pdf
 
The polarization of the CMB detected in the WMAP data is evidence fo.pdf
The polarization of the CMB detected in the WMAP data is evidence fo.pdfThe polarization of the CMB detected in the WMAP data is evidence fo.pdf
The polarization of the CMB detected in the WMAP data is evidence fo.pdf
 
Technical Performance Measures are quantitative measures that must be.pdf
Technical Performance Measures are quantitative measures that must be.pdfTechnical Performance Measures are quantitative measures that must be.pdf
Technical Performance Measures are quantitative measures that must be.pdf
 

Recently uploaded

History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
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
 
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
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
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
 
“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
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
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
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
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
 
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
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 

Recently uploaded (20)

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
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
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 🔝✔️✔️
 
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
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
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
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
“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...
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
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
 
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
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 

1- Create a class called Point that has two instance variables, defi.pdf

  • 1. 1- Create a class called Point that has two instance variables, defined as private, as follows: An x coordinate and a y coordinate of type integer. a) Write two constructors for the Point class as follows: A default constructor that sets the class instance variables to zero and a constructor that receives two integer values and sets the instance variables to them. b) Write the set and get methods for the Point class to set and return the values of its instance variables. c) Write a toString() method for the Point class that prints the class name (Point) and the value of its instance variables. 2- Create three classes called Circle, Rectangle and Square with the following properties: - The Circle class has two instance variables – a position of type Point (the class that you just created above) and a radius of type double. The instance variables position and radius specify the position of the center and radius of the circle, respectively. - The Rectangle class has three instance variables – a position of type Point (the class that you just created above), a length and a width of type double. The instance variables position, length and width specify the position of the top left corner, length and width of the rectangle, respectively. - The Square class has two instance variables – a position of type Point (the class that you just created above) and a lengthof type double. The instance variables position andlength specify the position of the top left corner and length of the square, respectively. For each of the Circle, Rectangle andSquare classes do the following: a) Define the instance variables as private. b) Write two constructors for each class as follows: A default constructor that sets the instance variables to zero and a constructor that receives values for the instance variables and sets them.
  • 2. c) Write the set and get methods for each class to set and return the values of their instance variables. For example, one of the get methods would return a Point. d) Write a toString() method for each class that prints the class name (Circle, Rectangle or Square) and the value of its instance variables. e) Write two methods called getPerimeter() and getArea() for each class, which calculate and return the perimeter and area of the class, respectively. For example, the getArea() method of the Square class returns the area of the Square object. 3- Test the above classes by writing a class called GeometricTest.java that does the following: - Creates instances of the Circle, Rectangle and Square classes as follows: - Circle: positioned at x = 7, y = 3 and the radius = 4.5. - Rectangle: positioned at x = 3, y = -1 and the length = 4.0 and width = 6.0. - Square: positioned at x = 5, y = 8 and the length = 2.0. - Prints each of the above objects. - Changes the length of the Square object to 5.0. - Prints the perimeter and area of each of each of the above objects. - Compares the x coordinates of the Square and Rectangle classes and prints a message specifying which one of them has a larger x coordinate. Solution import java.util.*; import java.lang.*; import java.io.*; class Point
  • 3. { private int x; private int y; public Point() { this.x = 0; this.y = 0; } public Point(int x,int y) { this.x = x; this.y = y; } public int getX() { return this.x; } public int getY() { return this.y; } public void setX(int x) { this.x = x; } public void setY(int y) { this.y = y; } public String toString() { return "Point("+getX() +","+getY()+")"; }
  • 4. }; class Rectangle extends Point { private Point p; private double length; private double width; public Rectangle() { p.setX(0); p.setY(0); length = 0; width =0; } public Rectangle(Point p,double length,double width) { this.p = p; this.length = length; this.width = width; } public double getWidth() { return width; } public double getLength() { return length; } public Point getPoint() { return this.p; } public double getArea() //compute the area of the rectangle. {
  • 5. double area; area = getWidth() * getLength(); return area; } public double getPerimeter() //compute the perimeter of the rectangle { double perimeter; perimeter = 2*(getWidth()+getLength()); return perimeter; } public String toString() { return "Rectangle : Top left Point :"+ getPoint() +" width :"+getWidth() + " height :"+getLength(); } } class Circle extends Point { private Point p; private double radius; public Circle() { p.setX(0); p.setY(0); radius =0; } public Circle(Point p,double radius) { this.p = p; this.radius = radius; } public double getRadius() { return radius;
  • 6. } public Point getPoint() { return this.p; } public double getArea() //compute the area of the circle. { double area; area = 3.14 * getRadius() * getRadius(); return area; } public double getPerimeter() //compute the perimeter of the circle { double perimeter; perimeter = 2* 3.14 *getRadius(); return perimeter; } public String toString() { return "Circle : center Point:"+ getPoint() +" radius "+getRadius(); } } class Square extends Point { private Point p; private double length; public Square() { p.setX(0); p.setY(0); length = 0;
  • 7. } public Square(Point p,double length) { this.p = p; this.length = length; } public double getLength() { return length; } public Point getPoint() { return this.p; } public void setLength(double length) { this.length = length; } public double getArea() //compute the area of the square. { double area; area = getLength() * getLength(); return area; } public double getPerimeter() //compute the perimeter of the square { double perimeter; perimeter = 4*(getLength()); return perimeter; } public String toString() { return "Square : Top left Point :"+ getPoint() +" length :"+getLength() ;
  • 8. } } class GeometricTest { public static void main (String[] args) { Point pc = new Point(7,3); Circle c = new Circle(pc,4.5); System.out.println(c.toString()); System.out.println("Area of circle = "+c.getArea()); System.out.println("Perimeter of circle = "+c.getPerimeter()); Point pr = new Point(3,-1); Rectangle r = new Rectangle(pr,4.0,6.0); System.out.println(r.toString()); System.out.println("Area of rectangle = "+r.getArea()); System.out.println("Perimeter of rectangle = "+r.getPerimeter()); Point ps = new Point(5,8); Square s = new Square(ps,2.0); s.setLength(5.0); System.out.println(s.toString()); System.out.println("Area of square = "+s.getArea()); System.out.println("Perimeter of square = "+s.getPerimeter()); Point p1 = r.getPoint(); Point p2 = s.getPoint(); if(p1.getX() >p2.getX()) System.out.println("x-coordinate of rectangle is greater than x-coordinate of square"); else System.out.println("x-coordinate of square is greater than x-coordinate of rectangle");