Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
How to get accepted in Fileice (200% Working) 22/2012
Premium Account
FILE HOSTS PREMIUM ACCOUNT
ALL FILE HOST PREMIUM ACCOUNTS
Zynga Slingo Trainer v5.12
iTunes Gift Card Generator V3.1 2012
Diablo 3 GOLD Coins FREE
Working PS3 Jailbreak 3.65 And 3.66
ExtaBit Premium Accounts and Cookies
Steam Wallet Hack - Money Adder & Hack v3
Popular
XBOX POINTS GENERATOR - MICROSOFT POINTS GENERATOR v1.2012
11 may 2012 premium uploading accounts 100% working
Free Microsoft Points
Free Microsoft Points - Microsoft Points Generator - Xbox Live Codes 2012
Car Town Free Blue Points Hack
Free CarTown Blue Points Generator and CarTown Templates
Better way to get content via jQuery $.get()
Free Microsoft Points
Simple Days Purger
Sharecash Downloader Bypass Surveys New 05/2012
Pastable version of
my shapes program
<pre class='prettyprint' language='java'>import java.util.Scanner; class Shape { // Declaration of the instance variables for the class double height, base, area, radius, perimeter; String shape; // Constructor that will initialize only the 'shape' variable public Shape(String shape) { this.shape = shape; } // The method used to calculate the area of the shape double area(){ Scanner s = new Scanner(System.in); // new scanner object // Calculates area if shape is a circle if (this.shape.equalsIgnoreCase("circle")){ System.out.print("What is the radius of the circle? "); radius = s.nextDouble(); area = Math.PI * (radius * radius); } // Calculates area if shape is a rectangle else if (this.shape.equalsIgnoreCase("rectangle")) { System.out.print("What is the base of the shape? "); base = s.nextDouble(); System.out.print("What is the height of the shape? "); height = s.nextDouble(); area = base * height; } // Calculates area if shape is a square else if (this.shape.equalsIgnoreCase("square")) { System.out.print("What is the side length? "); base = s.nextDouble(); area = base * base; } // Calculates area if shape is a triangle else if (this.shape.equalsIgnoreCase("triangle")) { System.out.print("What is the base of the triangle? "); base = s.nextDouble(); System.out.print("What is the height of the triangle? "); height = s.nextDouble(); area = base * height * .5; } // After all the calculations are made, the method returns the area return area; } // Method that calculates the perimeter of the shape double perimeter() { Scanner s = new Scanner(System.in); // new scanner object // calculates perimeter if the shape is a circle if (this.shape.equalsIgnoreCase("circle")) perimeter = Math.PI * (radius * 2); // calculates perimeter if the shape is a rectangle else if (this.shape.equalsIgnoreCase("rectangle")) perimeter = (2 * base) + (2 * height); // calculates perimeter if the shape is a square else if (this.shape.equalsIgnoreCase("square")) perimeter = base * 4; // calculates smallest possible perimeter if shape is a triangle else if (this.shape.equalsIgnoreCase("triangle")){ perimeter=(2*(Math.sqrt((height*height)+((base/2)*(base/2))))+base); } // After all the calculations are made, the method returns the perimeter return perimeter; } } public class Main { // The main method begins here public static void main(String[] args) { Scanner x = new Scanner(System.in); // new scanner object // This variable is local to the main method String units; System.out.println("\t*******Area and Perimeter Calculator!*******"); // Get input from the user System.out.print("What shape? "); // Create new object using the input Shape shape1 = new Shape(x.next()); // If the shape is a triangle, there are an infinite amount of possible areas // so it will only display the perimeter if (shape1.shape.equalsIgnoreCase("triangle")) { System.out.print("What units of measurment? "); units = x.next(); System.out.println("The area is: " + shape1.area() + ' ' + units + " squared.\nThe smallest possible perimeter is: " + shape1.perimeter() + ' ' + units); } // If it is any of the other shapes, it displays both the area and perimeter. else { System.out.print("What units of measurment? "); units = x.next(); System.out.println("The area is: " + shape1.area() + ' ' + units + " squared.\nThe perimeter is: " + shape1.perimeter() + ' ' + units); } } }</pre> <a href="http://www.refactormycode.com/codes/764-my-shapes-program" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>