Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: client program rectangle

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    My Mood
    Worried
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy client program rectangle

    I have been trying to do these program for so long I think I almost got it all but there are some things I am not sure about,
    so I am trying to print the number of rectangles created, but I do not understand how to do it, because I have defined already the number of rectangles created (10). Also I need to find and print the information of a rectangle with the largest area, I do not know how to do it . I am really new at these, I would really apreciate some help



    these is my main class

    public class Rectangle{
     	 private double width, height;
     
    	 private static String color ="white";
     
    	 private Date date;
     
    	 private  static int rectangleCreated = 0; /// why is static?
     
    	 Rectangle(){ // no arg constructor that  creates a default rectangle
     
    		width =1;
    		height =1;
     
    	 rectangleCreated++;
     
    	 date: new Date();
     
    	 }
     
     
    	 Rectangle( double w, double h, String c ){ // CONSTRUCTOR
     
    	 	width = w;
     
    		height = h;
     
    		color = c;
     
    		date = new Date();
     
    		rectangleCreated++;
     
     
    		}
     
    	public static int rectangleCreated(){ 	// a method that returns number of rectangle created 
     
     
    	 return rectangleCreated;
     
    	 } 
     
     
     
    	public double getHeight(){
     
    		return height;
     
    		}
    	public void setHeight ( double h) {
     
    		height = h;
     
    		}
    	public void setWidth ( double w) {
     
    		width = w;
    		}
     
    	public static String getColor(){
     
    		return color;
    		}
     
    	public static void setColor(String c){
    		color = c;
     
    		}
    	public Date getDate(){
     
    		return date;
     
    		}
    	public void setDate ( Date d){
     
    		date = d;
     
    				}
     
     
    	public double getArea(){ // returns area
     
    			return width*height;
     
    		}
    	public double getPerimeter(){ // returns perimeter
     
    		return (2*width* height);
     
    		}
    	public String toString(){
     
    		String S;
    		S = "Rectangle width of" + width;
     
    		S =  S + "and height of" +height;
     
    		S = S + " was created on " + date.toString();
     
    		return S;
     
    			}
    				}


    and these the client program I am working on
    import java.util.*; 
     
     
    public class TestRectangle{
     
    	public static void main (String[]args)
    	{
     
     String[] colors = {"White","Blue","Yellow","Red","Green"};
     
     int k;
     
     
     
     
     
     Rectangle[] arr = new Rectangle[10];
      for(int i = 0; i < 10; i++) {
      	 Rectangle r = new Rectangle();
    	 r.setWidth((Math.random()*40)+10); 
    	 r.setHeight((Math.random()*40)+10);
    	 arr[i] = r;
    	 k = (int)(Math.random()*4)+1; 
    	 System.out.println(colors[k]);
     
     
     
    	   }
     
    			} 
    			 }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,981
    Thanks
    52
    Thanked 2,270 Times in 2,242 Posts

    Default Re: client program rectangle

    What happens when the program is compiled and executed? If it generates output, copy the output, paste it here and add some comments saying what the problem is.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. my encrypting simple client to server program unable to get the key from client
    By Paytheprice in forum What's Wrong With My Code?
    Replies: 11
    Last Post: February 3rd, 2013, 06:15 AM
  2. Replies: 2
    Last Post: October 16th, 2012, 10:13 PM
  3. Rectangle/Ellipse program help
    By ja3n in forum AWT / Java Swing
    Replies: 1
    Last Post: March 1st, 2012, 04:51 AM
  4. Help with JAVA Server-Client Program
    By GodLeoBouki in forum Java Theory & Questions
    Replies: 3
    Last Post: April 12th, 2011, 04:35 PM
  5. Client-Server program
    By Reztem in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 12th, 2010, 05:36 PM