import javax.swing.JOptionPane;
public class first {
// Main Method
public static void main(String[]args) {
// Create a rectangle
Rectangle1 myRectangle = new Rectangle1();
// Ask User for color
String colorInput = JOptionPane.showInputDialog(
"Enter color for the rectangle\n or leave blank and press Enter");
// Convert colorInput string to a double
double color1 = Double.parseDouble(colorInput);
// Ask User for height
String heightInput = JOptionPane.showInputDialog(
"Enter a number for the height of a Rectangle: ");
// Convert heightInput to a double
double height1 = Double.parseDouble(heightInput);
// Ask User for width
String widthInput = JOptionPane.showInputDialog(
"Enter a number for the width of a Rectangle: ");
// Display Results
String color = "The color is "
+ color1 + "\nThe area of the rectangle Rectangle1 is "
+ myRectangle.getArea() + "\nand the perimeter is "
+ myRectangle.getPerimeter();
JOptionPane.showMessageDialog(null, color);
}
}
class Rectangle1 {
// Rectangle Class
double height = 20;
double width = 50;
// Construct a rectangle with area of 1
Rectangle1(){
double area = height * width;
}
// Find perimeter of the rectangle
double Perimeter = (height * 2) + (width * 2);
// Return the area of this rectangle
double getArea(){
return height * width;
}
// Return the Perimeter of this rectangle
double getPerimeter(){
return Perimeter;
}
}
Here's the errors I'm getting:
Warning: Cannot convert string "-b&h-lucida-medium-r-normal-sans-*-140-*-*-p-*-iso8859-1" to type FontStruct Exception in thread "main" java.lang.NumberFormatException: For input string: "black" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1207) at java.lang.Double.parseDouble(Double.java:220) at first.main(first.java:14)

New Topic/Question
Reply




MultiQuote




|