Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am using Java(BlueJ) and I am having problems getting the Area to match what it is suppose to be. Can't tell if my code

I am using Java(BlueJ) and I am having problems getting the Area to match what it is suppose to be. Can't tell if my code is wrong or my math. Also need help showing everything out to three decimal places besides the number of sides. My code is as follows:

import java.lang.Math; import java.text.*;

public class Lab01 { private int n; private double side; private double x; private double y; private static DecimalFormat df = new DecimalFormat("##.###"); Lab01() { n = 3; side = 1; x = 0; y = 0; } Lab01(int N, double Side) { n = N; side = Side; x = 0; y = 0; } Lab01(int N, double Side, double X, double Y) { n = N; side = Side; x = X; y = Y; } public int getN() { return n; } public double getSide() { return side; } public double getX() { return x; } public double getY() { return y; } public void setN(int N) { n = N; } public void setSide(int Side) { side = Side; } public void setX(int X) { x = x; } public void setY(int Y) { y = Y; } public double getPerimeter() { return n * side; } public double getArea() { double numerator = n * Math.pow(side,2); double denominator = 4 * Math.tan(Math.PI/n); return numerator/denominator; }

My test portion of the code is:

import java.lang.Math; import java.text.*; public class Lab01Test { private static DecimalFormat df = new DecimalFormat(".###"); public static void main(String[] args) { Lab01 l1 = new Lab01(4,6,0,0); Lab01 l2 = new Lab01(4,10,5.600,7.800); Lab01 l3 = new Lab01(2,3,0.000,0); System.out.println("Begining program execution....."); System.out.println("Lab 01 CM245 Schmidt"); System.out.println("Printing Polygon-------------"); System.out.println("Polygon: Area = " + df.format(l1.getArea())); System.out.println("Polygon: Perimeter = " + l1.getPerimeter()); System.out.println("Polygon: number of sides: " + l1.getSide()); System.out.println("Polygon: length of sides: " + l1.getN()); System.out.println("Polygon: x coordinate: " + l1.getX()); System.out.println("Polygon: y coordinate: " + l1.getX()); System.out.println("Printing Polygon-------------"); System.out.println("Polygon: Area = " + l2.getArea()); System.out.println("Polygon: Perimeter = " + l2.getPerimeter()); System.out.println("Polygon: number of sides: " + l2.getSide()); System.out.println("Polygon: length of sides: " + l2.getN()); System.out.println("Polygon: x coordinate: " + l2.getX()); System.out.println("Polygon: y coordinate: " + l2.getY()); System.out.println("Printing Polygon-------------"); System.out.println("Area = " + l3.getArea()); System.out.println("Perimeter = " + l3.getPerimeter()); System.out.println("Polygon: number of sides: " + l3.getSide()); System.out.println("Polygon: length of sides: " + l3.getN()); System.out.println("Polygon: x coordinate: " + l3.getX()); System.out.println("Polygon: y coordinate: " + l3.getY());

}

My results are:

Begining program execution..... Lab 01 XCM245 Schmidt Printing Polygon------------- Polygon: Area = 36.0 Polygon: Perimeter = 24.0 Polygon: number of sides: 6.0 Polygon: length of sides: 4 Polygon: x coordinate: 0.0 Polygon: y coordinate: 0.0 Printing Polygon------------- Polygon: Area = 100.00000000000001 Polygon: Perimeter = 40.0 Polygon: number of sides: 10.0 Polygon: length of sides: 4 Polygon: x coordinate: 5.6 Polygon: y coordinate: 7.8 Printing Polygon------------- Area = 2.755455298081545E-16 Perimeter = 6.0 Polygon: number of sides: 3.0 Polygon: length of sides: 2 Polygon: x coordinate: 0.0 Polygon: y coordinate: 0.0

Im lost at what is wrong with my area and how to show three decimal places on all lines except number of sides. Get it to run and compile just not the numbers I need for area. Thanks for the help.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions

Question

=+free to pirate employees from competitors?

Answered: 1 week ago