[VIEWED 4328
TIMES]
|
SAVE! for ease of future access.
|
|
|
zeePa
Please log in to subscribe to zeePa's postings.
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(){
} }
|
|
|
|
HowardRoark
Please log in to subscribe to HowardRoark's postings.
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.
|
|
|
zeePa
Please log in to subscribe to zeePa's postings.
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!
|
|
|
HowardRoark
Please log in to subscribe to HowardRoark's postings.
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.
|
|
|
zeePa
Please log in to subscribe to zeePa's postings.
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.
|
|
|
techGuy
Please log in to subscribe to techGuy's postings.
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());
}
}
|
|
|
ice_cop123
Please log in to subscribe to ice_cop123's postings.
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..!!!
|
|
|
zeePa
Please log in to subscribe to zeePa's postings.
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!"
|
|