• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Trouble starting this program

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically i am somewhat at a loss as to how to properly begin and implement this program... i understand the concept behind having three classes (Square, Board, myDriver)...the thing that is keeping me from knwoing how to start this is the creation of "squares". The board class is supposed to create a 2 by 2 array of squares...i cant seem to figure out how to do this since each square needs a side (top,bottom,left,right which is a boolean value). The whole program set up is below:



Write a program (consisting of 3 classes) which allows two
human players to play the game Lines (described in class)
on a 3 by 3 grid (ie with a gameboard consisting of 4 squares).

Your first class will be called Square. This class will have
4 private boolean variables (top/bottom/left/right) with accessors
and mutators. You may add other variables/methods as desired. For
example, you may want to have a method called complete (telling
whether all four sides have been used).

Your second class will be called Board. This class will have
a private variable layout which is a 2x2 array of Squares.
Add methods as necessary. For example, you probably want to
have a method called markLine which takes two ints and
marks the line between those integers (if it exists) and another
method toString which returns a String which represents the
board. You may add other variables/methods as desired. For
example, I used 2 helper methods called markVert and markHoriz.

Your last class will be called Driver. This class will have a
main method (and possibly helper methods) which creates an
instance of Board and takes input from the two players (allowing
each to draw one line). Once all lines have been marked, it should
print out the score.
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frank,

Welcome to JavaRanch!

You don't have to have every line of a program clear in your head before you start to code. You definitely shouldn't try to write a whole program before you compile and run it. Code a little, test a little, code some more.

So first, you write the square class:



Make sure that compiles. Then add those booleans, and accessors and mutators. Just for fun, add a main() routine to Square (you can delete it later):



Now run Square, make sure you see what you expect.

Then create the Board class, which might contain stuff like


Make sure all this compiles. Then give "Board" a main() and test some of its functionality.

And so on. Go ahead, try it!
 
Frank Ponce
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help!11 With that example i just figured it out
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!