zeePa
Replies to this thread:

More by zeePa
What people are reading
Subscribers
Subscribers
[Total Subscribers 1]

paroo
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 Java lovers, please help me
[VIEWED 4328 TIMES]
SAVE! for ease of future access.
Posted on 11-05-08 8:18 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Create a class named MyRectangle to represent rectangles. The required data fields are width, height, and color. Use double data type for width and height, and a String for color. Suppose that all rectangles are the same color. Use a static variable for color. Provide the accessor methods for the properties and a method findArea() for computing the area of the rectangle.....Write a program to test your class MyRectangle. In the client program, create two MyRectangle objects. Assign a width and height to each of the two objects. Assign the first object the color red, and the second, yellow. Display all properties of both objects including their area.

God is it that tough? WHy is it freaking me out? guys help me. I framed it a lil bit.

 

public class MyRectangle{

private double width = 1;
private double height = 1;
private static String color = "white";

public MyRectangle(){

}

public MyRectangle(double widthParam, double heightParam, String colorParam){

}

public double getWidth(){

}

public void setWidth(double widthParam){

}

public double getHeight(){

}

public void setHeight(double heightParam){

}

public String getColor(){

}

public static void setColor(String colorParam){

}

public double findArea(){

}
}



 
Posted on 11-05-08 8:26 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

By the way, is that an interview home assignment? I know exactly the same question asked by a company a year ago to one of my friend.
 
Posted on 11-05-08 8:58 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

yea you can kinda say it is interview question.But not really,its a prep question though. A preparation for some test!
 
Posted on 11-05-08 9:13 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

I would help you out if you had at least tried it, and shared what you came up with.
 
Posted on 11-05-08 9:32 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

ALL I HAVE COME UP WITH IS FRAMING ALL THE CLASSES/METHODS. THATS IT. AND ITS WITH THE QUESTION.
 
Posted on 11-05-08 11:00 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Yup..it should be pretty easy...LD u too into java? bandook ra khukuri khoi?

Anyway, you can use following client program to test ur MyRectangle class...post your code once you r done..You might have to modify the methods below to match ur MyRectangle class's  accessor method, g'luck

 

 

public class client

{

public static void main(String args[])

{

MyRectangle R1 = new MyRectangle();

MyRectangle R2 = new MyRectangle();

R1.setLength(4);

R1.setHeight(3);

R1.setColor("Red");

R2.setLength(6);

R2.setHeight(2);

R2.setColor("Yellow");

System.out.println("Properties of R1");

System.out.println("Height:" + R1.getHeight()

+ " Length:" +R1.getLength()

+ " Color:" + R1.getColor()

+ " Area:"+R1.getArea());

System.out.println("Properties of R2");

System.out.println("Height:" + R2.getHeight()

+ " Length:" +R2.getLength()

+ " Color:" + R2.getColor()

+ " Area:"+R2.getArea());

}

}


 
Posted on 11-05-08 11:01 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

this is one of the easiest program in Java..if this freaks you out...its time to change your major..!!!
 
Posted on 11-06-08 8:14 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

IceCoP123,

                  If it's that easy for you, then please do it for me or at least give me some hint. A learned man is always there to share what he knows infront of people who don't know what he knows. Its easy for a grown ass man to walk/run/jump, not for a toddler.  Sometimes, a barking dog really don't bite!

Salute to techguy and LD.

For you guys: " True knowledge is to know that you know what you know and you don't know what you don't know!"


 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 30 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
and it begins - on Day 1 Trump will begin operations to deport millions of undocumented immigrants
ढ्याउ गर्दा दसैँको खसी गनाउच
To Sajha admin
Travel Document for TPS (approved)
All the Qatar ailines from Nepal canceled to USA
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters