*p4.8 (first)

From GGCWiki
Jump to: navigation, search

Nick's Completed Program


  • I edited it so that the side of the square could be user-changed.
  • I really like this program I'm not that good at modifying math formulas but would c=sqrt a^2+b^2 work? The code looks excellent though -Chris
package assignments;

import java.util.Scanner;

public class Square {

double side;

	public Square(double length)
	public void getArea()
		double area;
		area = side * side;
		System.out.println("The area of the square is: "+area);
	public void getPerimeter()
		double perimeter;
		perimeter = 4*side;
		System.out.println("The perimeter of the square is: "+perimeter);
	public void getDiagonal()
		double diagonal;
		diagonal = Math.sqrt(2*(side * side));
		System.out.println("The length of the diagonal is: "+diagonal);
	public static void main(String args[])
		Scanner in = new Scanner(System.in);
		int input;
		System.out.println("Input the length of a side the square : ");
		Square square =new Square(input);

Personal tools