Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- /**
- This program is an application class,
- It is used to test/drive the Rectangle logic class
- */
- public class RectangleDemo
- {
- public static void main(String[] args)
- {
- // Create a Rectangle object, passing 5.0 and
- // 15.0 as arguments to the constructor.
- double width = 1, length;
- Rectangle lot, house, gardenShed, box;
- lot = new Rectangle(100, 200);
- house = new Rectangle(40.0, 50.0);
- gardenShed = new Rectangle(4.0, 8.0);
- System.out.println("Lot\narea:\t "+lot.calcArea() +
- "\tperimiter: " + lot.calcPerimeter()+"\n\nBuildings:");
- System.out.println("Garden Shed\n area:\t "+gardenShed.calcArea() +
- "\t\tperimiter: " + gardenShed.calcPerimeter());
- System.out.println("House\n area:\t "+house.calcArea() +
- "\t\tperimiter: " + house.calcPerimeter());
- System.out.println ("\nArea left to build on "+
- (lot.calcArea() - house.calcArea() - gardenShed.calcArea()));
- /* temp
- while (width > 0) {
- if ((width = acceptDub ("Rectangle width:")) > 0) {
- if ((length = acceptDub ("Rectangle length:")) > 0) {
- box = new Rectangle(length, width);
- // Display the length.
- System.out.println("The box's length is " +
- box.getLength());
- // Display the width.
- System.out.println("The box's width is " +
- box.getWidth());
- // Display the area.
- System.out.println("The box's area is " +
- box.calcArea());
- // Display the area.
- System.out.println("The box's perimiter is " +
- box.calcPerimeter());
- }
- }
- }
- */
- System.out.println("Bye! ");
- }//main()
- public static double acceptDub(String msg) {
- String numIn = JOptionPane.showInputDialog(msg);
- double numOut = 0;
- try {
- numOut = Double.parseDouble(numIn);
- } catch (NullPointerException|NumberFormatException e) {
- System.out.println("Invalid number, can't convert");
- }
- return numOut;
- } //acceptDub(0
- } // RectangleDemo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement