wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes exam question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "exam question" Watch "exam question" New topic
Author

exam question

johnathan smith
Greenhorn

Joined: Mar 30, 2007
Posts: 21
hi

i have an exam coming up
and when looking at previous years papers i have realiaed that the questions are similar therefore I assume this years will be no exception.

i feel pretty confident about some questions but this one question i am struggling to come up with a solution for.

if anybody can help out that would be superb

The question opens with a class of a rectangle
it has methods to set the dimensions
return the width height and area and print these out

the question is

a) Write a method that takes as a parameter an array of Rectangle objects and prints out the details of every rectangle stored in this array.

b) Write a method that takes as a parameter an array of Rectangle objects and returns an array of the areas of the rectangles stored in this array

thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36563
    
  16
That sounds easy enough. Tell us what you have managed so far.
johnathan smith
Greenhorn

Joined: Mar 30, 2007
Posts: 21
well iv been trying part a

and so far i have come up with



but im guessing the for statement is incorrect
any idea where its wrong?
thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36563
    
  16
You have a couple of errors.
  • You seem to be declaring "rectangles" twice.
  • When you get to the print() call, you are printing rectangles rather than a single Rectangle.
  • You are quite correct to assume that the Rectangle object ought to have a toString() method which will alow you to print it out. Please go back to the Java Tutorial and revise control statements here. You will find for somewhere on the left of the window.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 36563
        
      16
    There is another error in the heading of the for loop. I shall leave you to work out what it is, for the time being.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 36563
        
      16
    Have you worked it out yet?
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 36563
        
      16
    Bump!!


    How far have you got?
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 36563
        
      16
    You ought to have something by now . . .
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 36563
        
      16
    Have you given up?
    Jinny Morris
    Ranch Hand

    Joined: Apr 29, 2007
    Posts: 101
    Mr. Ritchie -

    Cool! I've been looking for "problems" to try to solve in order to get used to this whole class-and-object approach to programming about which I still feel pretty clueless - so if you keep checking this thread I will add my questions if you don't mind ...
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 36563
        
      16
    Please don't add new questions to an existing thread, Jinny Morris. If it is a new question, it deserves a thread to itself.

    And Johnathan Smith, have you given up with this array of rectangles question?
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: exam question
     
    Similar Threads
    need help for upcoming exam
    Need help in iBatis !
    array of rectangles exam question
    Sun Cirtification
    delete an element from an array