• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

exam question

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sounds easy enough. Tell us what you have managed so far.
 
johnathan smith
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
    Marshal
    Posts: 79178
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Marshal
    Posts: 79178
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Have you worked it out yet?
     
    Campbell Ritchie
    Marshal
    Posts: 79178
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Bump!!


    How far have you got?
     
    Campbell Ritchie
    Marshal
    Posts: 79178
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You ought to have something by now . . .
     
    Campbell Ritchie
    Marshal
    Posts: 79178
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Have you given up?
     
    Ranch Hand
    Posts: 103
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Marshal
    Posts: 79178
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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?
     
    It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic