•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 392,207 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,818 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
A program similar to CircleClass.java which defines a rectangle object. ClientProgram.java is the driver program for the Rectangle.java file.
// Rectangle.java: package rectangle; public class Rectangle { private double width = 1; private double height = 1; private static String color = "white"; public Rectangle() { } public Rectangle(double w, double h, String c) { width = w; height = h; color = c; } public double getWidth() { return width; } public void setWidth(double w) { width = w; } public double getHeight() { return height; } public void setHeight(double h) { height = h; } public static String getColor() { return color; } public static void setColor(String c) { color = c; } public double findArea() { return height * width; } } // ClientProgram.java package rectangle; public class ClientProgram { public static void main(String args[]) { Rectangle mySquare = new Rectangle(5, 5, "green"); System.out.print("\n Height = " + mySquare.getHeight() ); System.out.print("\n Width = " + mySquare.getWidth() ); System.out.print("\n Color = " + mySquare.getColor() ); mySquare.setHeight(10); mySquare.setWidth(15); System.out.print("\n\n Height = " + mySquare.getHeight() ); System.out.print("\n Width = " + mySquare.getWidth() ); System.out.print("\n Area = " + mySquare.findArea() ); } }
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)