Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

math456 Group Title

I need help, plz! Design and implement in Java, a class Rectangular tht supports two methods: 1). Area(double x, double y) tht returns the area of a rectangular of width x and length y. 2). perimeter(double x, double y) tht returns the perimeter length of a rectangle of width x & length y.

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. eSpeX Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    And what part did you get stuck on?

    • 2 years ago
  2. math456 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    public class Areas { public static void main( String [] args) { area (int, double x) like what should i write to return the area of a rectangular of the width & length?

    • 2 years ago
  3. eSpeX Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Well, your area method takes an int and a double, so you probably want to return a double.

    • 2 years ago
  4. eSpeX Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    As for what you should put inside the method, consider the steps you must take to calculate the area. You will need to take in two variables, width and height, then multiply them together to get the area.

    • 2 years ago
  5. eSpeX Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    You have been given the definitions for both of your methods, just put the calculation inside that is needed to get the area and perimeter into each of their respective functions.

    • 2 years ago
  6. math456 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    oh so meaning: area ( width x, length y) area = w x h

    • 2 years ago
  7. eSpeX Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Yes, but unless you are going to print it out within the method or assign it to a variable you can access, you will want to "return area = wxh;" or some similar operation.

    • 2 years ago
  8. math456 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    like this? public class Rectangular { public static void main(String [] args) { area (int length x; int width y); return area = x*y; } System.out.print( "area" ); }

    • 2 years ago
  9. math456 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @shadowfiend @ganeshie8 ?

    • 2 years ago
  10. eSpeX Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    You're on the right track, try something like this: import java.util.*; public class Rectangle{ public static void main(String[] args){ double area, x, y; Scanner in = new Scanner(System.in); System.out.println("Please enter your width"); x = in.nextDouble(); System.out.println("Please enter your length"); y = in.nextDouble(); get_area(double x, double y){ area = x*y; System.out.println("The area of the rectangle is: " + area + "\n"); } } }

    • 2 years ago
  11. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    YOu should honestly look at the Java API for 2 reasons. 1 it uses doubles and it's a rectangle which is what you're looking for. http://docs.oracle.com/javase/6/docs/api/java/awt/Rectangle.html Rectangle getBounds() Gets the bounding Rectangle of this Rectangle. To make your own class like this you could do a few things. First is to set it up like you normally would. class rect { double w,h; rect() { //if you need constructor calls, most likely you would want this constructor below } rect(double length, double width) { this.w = width; this.h = height; //this will set the height and width of the new rectangle object you create //to create a new rectangle object you would do rect r = new rect(); or rect r = new rect(10,10); this makes both height and width 10. } next you will want methods TO SET and GET known as getters and settings... public setWidth(double w) { this.w = w; } public getWidth() { return w; //returning will return the global variable at the top which is our width. } same will be done with height.

    • 2 years ago
  12. eSpeX Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Given the examples provided earlier, you may be offering a solution above his experience.

    • 2 years ago
  13. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Next you could make a class that extends the rectangle class i.e., class rect extends Rectangle2D.Double { //code } this overrides Rectangle and you can use it's methods, or make your own.

    • 2 years ago
  14. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    public void setWidth(double w) { this.w = w; } public double getWidth() { return w; //returning will return the global variable at the top which is our width. } IS what should be stated above.

    • 2 years ago
  15. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I don't think it's too hard, this is basic stuff. I explained in my comments what does what. I would assume that if he were too new, he wouldn't understand what the Scanner is either :P.

    • 2 years ago
  16. eSpeX Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Fair enough, I did consider that as I typed it. :)

    • 2 years ago
  17. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Imo it's better to see correct and complete code than to fumble around a lot.... OF course learning it yourself makes you understand it better, a good combo of both if perfect imo.

    • 2 years ago
  18. math456 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @hartnn @.Sam. ??

    • 2 years ago
  19. math456 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @eSpeX i don't hv to use Scanner problem in this program!

    • 2 years ago
  20. math456 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @ganeshie8 ?

    • 2 years ago
  21. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    .....?

    • 2 years ago
  22. math456 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    i tried this, but it shows me error!! public class Rectangular { public static area(double x, double y) { return x*y; } public static perimeter (double x, double y) { return (2*x + 2*y); } }

    • 2 years ago
  23. math456 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @KonradZuse @eSpeX

    • 2 years ago
  24. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    yes because you are not doing anything.

    • 2 years ago
  25. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Basically when you create an object it's like making the frame.

    • 2 years ago
  26. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    in the oracle trail it talks about a bicycle.

    • 2 years ago
  27. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    it has methods like speed up, speed down, brake, etc. This is what we are doing. If you look above at what I said you can make it work.

    • 2 years ago
  28. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    In your own class right now you want to make a main method and that main method will create what you need.

    • 2 years ago
  29. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    class rect { double w,h; rect() { //if you need constructor calls, most likely you would want this constructor below } rect(double length, double width) { this.w = width; this.h = height; Constructor calls are important.

    • 2 years ago
  30. math456 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    public class Rectangular { public static void main (String [] args) { double width,length; x= width; y= length; rectangular (); return x*y; public static perimeter (double x, double y) { return rectangular (2*x + 2*y); } } } Still shows error!

    • 2 years ago
  31. math456 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    can't u tell like what are my mistakes and wht do I need to write instead?

    • 2 years ago
  32. math456 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @KonradZuse ?

    • 2 years ago
  33. math456 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    so this is the new one and it compiles well but I only need the print statement to return the area of a rectangular of width x and length y.! @eSpeX @KonradZuse public class Rectangular { public static void main (String [] args) { } public double area (double x, double y) { return (x*y); } public double perimeter (double x, double y) { return (2*x + 2*y); } }

    • 2 years ago
  34. eSpeX Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    @math456 You do not have anything calling those methods, therefore you have nothing to catch the returned values. If you are going to make it without interaction from a user, why not just use System.out.println instead of a return statement?

    • 2 years ago
  35. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I already showed you what you need. public static void main (String [] args) { Rectangular r = new Rectangular(); } if you make a constructor as shown above then you will be able to make an object.

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.