Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Section 1: Use basic data types and simple mathematical calculation. slope (22) In the previous lab, we used Java API to write some program e.g.
Section 1: Use basic data types and simple mathematical calculation. slope (22) In the previous lab, we used Java API to write some program e.g. age calculation in days. In this lab, we will create our own class to solve a mathematical problem, TwoPoints. xl, yi midpoint 02-y) x2-x getArea - return the coverage area of two points and can be calculated by area = 1*: - , *ly - al display TwoPoints - display the (x1, y1) and (x2, y2) of the two points (see examples below) displayMidpoint -display the midpoint (x, y) between these two points: 1+x, (y2 + y ) midpoint 2 2 Note: that the x, y of the midpoint can be floating values (double variables), displayGeometric - display the distance, slope and coverage area as shown in the execution simples x2, y2 Class TwoPoints represents 2 points and its related geometric calculation. Each point is defined by a pair of coordinates (x,y). Thus, we will have variables xl, y1, x2 and y2 to keep their values. The program that we will write consists of two classes as shown in the following class diagram. L3.1.1: Write code for the class Two Points as defined above. To test your class TwoPoints, the first draft of the TwoPoint Test.java is given here: TwoPoints Test Two Points -x1: Int -yi: int -X2: int -y2: Int +setPoints(aX1: int, aY1: int, aX2: int, aY2:int): void +getDistance(): double +getslope(): double +getArea(): double +displayMidPoint(): vold +displayTwo Points(): vold +displayGeometrico: void +main(args: String[]):void public class TwoPointsTest { public static void main(String[] args) { int x1 - 8; int yi - 2; int x2 = 4; int y2 = 5; Two Points pt - new TwoPoints(); pt.setPoints(x1, y1, x2, y2); pt.displayTwo Points(); pt.displayMidPoint(); pt.displayGeometric(); 1 In our design, class TwoPoints has abilities to do the followings: calculate distance between them, find slope, midpoint and rectangle area covering by them. When executing it, the expected result from the test should look like: Description: Instance variables: xl, yl, x2 and y2 keep (x,y) values of the two points Pointi (8, 2) Point2 (4, 5) Midpoint is (6.80, 3.58) Geometric values: Distance between them: 5.000 Slope of the line between them: -2.750 Coverage area: 12.000 Method details: setPoints - set the values of the variables for xl, y1, x2 and y2 respectively. getDistance - return the distance between two points in the coordinate plane using the below formula distance = (x2-x)+62 - y.)2 getslope - return the slope for the line between these two points using the given formula: L3.1.2: Modify the TwoPoints Test.java to accept input values for xl, yl, x2, and y2 from the console. (In the below example, the numbers in groen indicate that the user enters those values in the console.) We also provide a test class as follows: The following is the result of the sample execution: Enter value for xi: 3 Enter value for yi: 4 Enter value for x2: 6 Enter value for y2: 30 Pointi (3, 4) Point2 (6, 30) Midpoint is (4.50, 17.00) Geometric values: Distance between them: 26.173 Slope of the line between them: 8.667 Coverage area: 78.800 public class TestOnePoint { public static void main(String args[]) { OnePoint p = new OnePoint(); p.setPoint(3, 4); System.out.println(p.getManhattanDistanceFromOrigin()); } Submission: : You are required to finish and submit all the exercises L3.X. Y in this lab instructions, where X and Y are section und problem numbers, respectively. Exercise 13.1.1 (TwoPoints.java) Submit your code. Exercise 13.1.2 (TwoPointsTest.java) Submit your code. Hint: The following code is a class declaration for OnePoint. You may modify this class declaration in order to write the class declaration for TwoPoints to achieve the exercise L3.1.1 and L3.1.2 Due date: within Feb 09, 2021 by 23:55 Submission channel: Submit on Google Classroom, You are regudred to submit this lab as Eclipse project (compressed as.por.rar). In this project, it must contain the following files: 1. Two Points.java 2. Two Points Test.java public class OnePoint { public int x; public int y; public void setPoint(int ax, int ay) { X - ax; y = ay; } public int getManhattanDistance FromOrigin() { return x + y; } } This class OnePoint simply represents a point in 2D plane. The class contains only 2 variables: X, y: and, 2 methods: setPoint(int ax, int ay), etManhattanDistanceFromOrigin(). The first method, setpoint, is to set the values of variables x, y. The second method. getManhattanDistance FramOrigin, is to compute the Manhattan distance from origin to the point (x, y). The fornula to compute the Manhattan distance from origin is shown as follows: distance warthottan = x+y This formular is only valid for x, y 2 0. Section 1: Use basic data types and simple mathematical calculation. slope (22) In the previous lab, we used Java API to write some program e.g. age calculation in days. In this lab, we will create our own class to solve a mathematical problem, TwoPoints. xl, yi midpoint 02-y) x2-x getArea - return the coverage area of two points and can be calculated by area = 1*: - , *ly - al display TwoPoints - display the (x1, y1) and (x2, y2) of the two points (see examples below) displayMidpoint -display the midpoint (x, y) between these two points: 1+x, (y2 + y ) midpoint 2 2 Note: that the x, y of the midpoint can be floating values (double variables), displayGeometric - display the distance, slope and coverage area as shown in the execution simples x2, y2 Class TwoPoints represents 2 points and its related geometric calculation. Each point is defined by a pair of coordinates (x,y). Thus, we will have variables xl, y1, x2 and y2 to keep their values. The program that we will write consists of two classes as shown in the following class diagram. L3.1.1: Write code for the class Two Points as defined above. To test your class TwoPoints, the first draft of the TwoPoint Test.java is given here: TwoPoints Test Two Points -x1: Int -yi: int -X2: int -y2: Int +setPoints(aX1: int, aY1: int, aX2: int, aY2:int): void +getDistance(): double +getslope(): double +getArea(): double +displayMidPoint(): vold +displayTwo Points(): vold +displayGeometrico: void +main(args: String[]):void public class TwoPointsTest { public static void main(String[] args) { int x1 - 8; int yi - 2; int x2 = 4; int y2 = 5; Two Points pt - new TwoPoints(); pt.setPoints(x1, y1, x2, y2); pt.displayTwo Points(); pt.displayMidPoint(); pt.displayGeometric(); 1 In our design, class TwoPoints has abilities to do the followings: calculate distance between them, find slope, midpoint and rectangle area covering by them. When executing it, the expected result from the test should look like: Description: Instance variables: xl, yl, x2 and y2 keep (x,y) values of the two points Pointi (8, 2) Point2 (4, 5) Midpoint is (6.80, 3.58) Geometric values: Distance between them: 5.000 Slope of the line between them: -2.750 Coverage area: 12.000 Method details: setPoints - set the values of the variables for xl, y1, x2 and y2 respectively. getDistance - return the distance between two points in the coordinate plane using the below formula distance = (x2-x)+62 - y.)2 getslope - return the slope for the line between these two points using the given formula: L3.1.2: Modify the TwoPoints Test.java to accept input values for xl, yl, x2, and y2 from the console. (In the below example, the numbers in groen indicate that the user enters those values in the console.) We also provide a test class as follows: The following is the result of the sample execution: Enter value for xi: 3 Enter value for yi: 4 Enter value for x2: 6 Enter value for y2: 30 Pointi (3, 4) Point2 (6, 30) Midpoint is (4.50, 17.00) Geometric values: Distance between them: 26.173 Slope of the line between them: 8.667 Coverage area: 78.800 public class TestOnePoint { public static void main(String args[]) { OnePoint p = new OnePoint(); p.setPoint(3, 4); System.out.println(p.getManhattanDistanceFromOrigin()); } Submission: : You are required to finish and submit all the exercises L3.X. Y in this lab instructions, where X and Y are section und problem numbers, respectively. Exercise 13.1.1 (TwoPoints.java) Submit your code. Exercise 13.1.2 (TwoPointsTest.java) Submit your code. Hint: The following code is a class declaration for OnePoint. You may modify this class declaration in order to write the class declaration for TwoPoints to achieve the exercise L3.1.1 and L3.1.2 Due date: within Feb 09, 2021 by 23:55 Submission channel: Submit on Google Classroom, You are regudred to submit this lab as Eclipse project (compressed as.por.rar). In this project, it must contain the following files: 1. Two Points.java 2. Two Points Test.java public class OnePoint { public int x; public int y; public void setPoint(int ax, int ay) { X - ax; y = ay; } public int getManhattanDistance FromOrigin() { return x + y; } } This class OnePoint simply represents a point in 2D plane. The class contains only 2 variables: X, y: and, 2 methods: setPoint(int ax, int ay), etManhattanDistanceFromOrigin(). The first method, setpoint, is to set the values of variables x, y. The second method. getManhattanDistance FramOrigin, is to compute the Manhattan distance from origin to the point (x, y). The fornula to compute the Manhattan distance from origin is shown as follows: distance warthottan = x+y This formular is only valid for x, y 2 0
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