I need help with 11.15 Area convex polygon in introduction to
Java programming and data structures. I havent had any luck
creaating it effectivly.
Here is a program of Area Convex polygen Hope it wil help you
public class MyPoint {
public double x;
public double y;
public MyPoint(double x, double y) {
this.x = x;
this.y = y;
}
public MyPoint() {
this(0,0);
}
public double x() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double y() {
return y;
}
public void setY(double y) {
this.y = y;
}
public double distance(double x, double y) {
return Math.sqrt((this.x - x) * (this.x - x) + (this.y - y) * (this.y - y));
}
public double distance(MyPoint point) {
return distance(point.x, point.y);
}
public MyPoint getCenterPoint(MyPoint p) {
return new MyPoint((p.x + this.x) / 2, (p.y + this.y) / 2);
}
public static MyPoint getCenterPoint(double x1, double y1, double x2, double y2) {
return new MyPoint((x1 + x2) / 2, (y1 + y2) / 2);
}
/** Return true if this point is on the left side of the
* directed line from p0 to p1 */
public boolean leftOfTheLine(MyPoint p0, MyPoint p1) {
return leftOfTheLine(p0.x, p0.y, p1.x, p1.y, x, y);
}
/** Return true if this point is on the same
* line from p0 to p1 */
public boolean onTheSameLine(MyPoint p0, MyPoint p1) {
return onTheSameLine(p0.x, p0.y, p1.x, p1.y, x, y);
}
/** Return true if this point is on the right side of the
* directed line from p0 to p1 */
public boolean rightOfTheLine(MyPoint p0, MyPoint p1) {
return rightOfTheLine(p0.x, p0.y, p1.x, p1.y, x, y);
}
/** Return true if this point is on the
* line segment from p0 to p1 */
public boolean onTheLineSegment(MyPoint p0, MyPoint p1) {
return onTheLineSegment(p0.x, p0.y, p1.x, p1.y, x, y);
}
/** Return true if point (x2, y2) is on the left side of the
* directed line from (x0, y0) to (x1, y1) */
public static boolean leftOfTheLine(double x0, double y0, double x1, double y1, double x2, double y2){
return (x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0) > 0;
}
/** Return true if point (x2, y2) is on the same
* line from (x0, y0) to (x1, y1) */
public static boolean onTheSameLine(double x0, double y0, double x1, double y1, double x2, double y2) {
return (x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0) == 0;
}
/** Return true if point (x2, y2) is on the
* line segment from (x0, y0) to (x1, y1) */
public static boolean onTheLineSegment(double x0, double y0, double x1, double y1, double x2, double y2) {
double position = (x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0);
return position <= 0.0000000001 && ((x0 <= x2 && x2 <= x1) || (x0 >= x2 && x2 >= x1));
}
/** Return true if point (x2, y2) is on the right side of the
* directed line from (x0, y0) to (x1, y1) */
public static boolean rightOfTheLine(double x0, double y0, double x1, double y1, double x2, double y2){
return (x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0) < 0;
}
@Override
public String toString() {
return "(" + x + ", " + y + ")";
}
}
import java.util.ArrayList;
import java.util.Scanner;
public class Exercise_15 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of the points: ");
int numOfPoints = input.nextInt();
System.out.print("Enter the coordinates of the points: ");
ArrayList<MyPoint> points = new ArrayList<>();
for (int i = 0; i < numOfPoints; i++) {
points.add(new MyPoint(input.nextDouble(), input.nextDouble()));
}
System.out.println("The total area is " + getConvexPolygonArea(points));
}
// Area of a Convex Polygon
// http://www.mathwords.com/a/area_convex_polygon.htm
public static double getConvexPolygonArea(ArrayList<MyPoint> points) {
// points must be counter clockwise
double sum1 = 0;
double sum2 = 0;
for (int i = 0; i < points.size(); i++) {
int limitIndex = (i + 1) % points.size();
MyPoint p1 = points.get(i);
MyPoint p2 = points.get(limitIndex);
System.out.println("P1 index = " + i);
System.out.println("P2 index =" + limitIndex);
sum1 += (p1.x * p2.y);
sum2 += (p1.y * p2.x);
}
double area = 0.5 * (sum1 - sum2);
return (area > 0) ? area : -area;
}
}
I need help with 11.15 Area convex polygon in introduction to Java programming and data structures....
I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java Programming Project #4 – Classes and Objects (20 Points) You will create 3 new classes for this project, two will be chosen from the list below and one will be an entirely new class you invent.Here is the list: Shirt Shoe Wine Book Song Bicycle VideoGame Plant Car FootBall Boat Computer WebSite Movie Beer Pants TVShow MotorCycle Design First Create three (3) UML diagrams...
******Java Programming Hi guys, I really need you help. I created a code for my java course, but it keep giving me error messages. Majority of my code is fine but some keep display error on my console. I was hoping someone could pin points the problem. .There are three classes with the testCenter class being the main class. In the following is the assignment, and the bottom is my code. Please help! Assignment: Concepts: GUI User Design Graphics Deployment...
Introduction to Data Structures programming assignments can be completed either in C++ (preferred) or in Java. In both cases you cannot use libraries or packages that contain pre-built data structures, other than built-in support for objects, arrays, references, and pointers. Classes in C++ and Java can represent anything in the real world. This assignment is to write a class to represent a Date in a Calendar. Date Class Member Variables The following table identifies and describes the purpose of each...
Introduction In this final programming exercise, you'll get a chance to put together many of the techniques used during this semester while incorporating OOP techniques to develop a simple song playlist class. This playlist class allows a user to add, remove and display songs in a playlist. The Base Class, Derived Class and Test Client Unlike the other PAs you completed in zyLabs, for this PA you will be creating THREE Java files in IntelliJ to submit. You will need...
Computer Science 111 Introduction to Algorithms and Programming: Java Programming Net Beans Project #4 - Classes and Objects (15 Points) You will create 3 new classes for this project, two will be chosen (THE TWO CHOSEN ARE TENNIS SHOE AND TREE) from the list below and one will be an entirely new class you invent. Here is the list: Cellphone Clothes JuiceDrink Book MusicBand Bike GameConsole Tree Automobile Baseball MusicPlayer Laptop TennisShoe Cartoon EnergyDrink TabletComputer RealityShow HalloweenCostume Design First Create...
The following is for java programming. the classes
money date and array list are so I are are pre made to help with
the coding so you can resuse them where applicable
Question 3. (10 marks) Here are three incomplete Java classes that model students, staff, and faculty members at a university class Student [ private String lastName; private String firstName; private Address address; private String degreeProgram; private IDNumber studentNumber; // Constructors and methods omitted. class Staff private String lastName;...
This is java. I need help with my computer science class. Question 11 Assume that you have an array of integers named arr. The following program segment is intended to sum arr [0]through arr[n−1], where n = arr.length: sum = 0; i = 0; n = arr.length; while (i != n) { i++; sum += arr[i]; } In order for this segment to perform as intended, which of the following modifications, if any, should be made? 1.No modification is necessary...
Need help with java programming. Here is what I need to do: Write a Java program that could help test programs that use text files. Your program will copy an input file to standard output, but whenever it sees a “$integer”, will replace that variable by a corresponding value in a 2ndfile, which will be called the “variable value file”. The requirements for the assignment: 1. The input and variable value file are both text files that will be specified in...
Hi I need help creating a program in JAVA. This is material from chapter 9 Objects and Classes from the Intro to JAVA textbook. Mrs. Quackenbush's Rent-A-Wreck car rental ..... Mrs. Q asked you to create a program that can help her track her growing fleet of junkers. Of course she expects you to use your best programming skills, including: 1. Plan and design what attributes/actions an automobile in a rental fleet should have (example. Track number of Trucks, SUVs,...
I was wondering if I could get some help with a Java Program
that I am currently working on for homework. When I run the program
in Eclipse nothing shows up in the console can you help me out and
tell me if I am missing something in my code or what's going
on?
My Code:
public class Payroll {
public static
void main(String[] args) {
}
// TODO Auto-generated method stub
private int[] employeeId = {
5658845, 4520125, 7895122,...