-10

I apologise in advance if it becomes too long to read.The question I have to solve is :

"During his completely miserable life, pirate Abraham Blaufelt has been in search of the lost treasure of Atlantis. On a very fortunate day in the year of the Lord 1642 he enters an abandoned cathedral of a long gone sect in the ancient forests of Poland. Inside he finds a mysterious ancient parchment. The parchment reads:
Traveler, if you want to reach thine goal, trace the path through seas by making the broken, whole.

5,4 4,5 8,7
Add behind 6,3 3,2 9,6 4,3
Add in front 7,6
Add behind 9,8
Add in front 5,5 7,8 6,5 6,4

Abraham Blaufelt immediately knew what he was dealing with. A puzzel of which the result is a safe route to the treasure. This route was essential, the sea was crawling with monsters in those days. Since this most fortunate day, almost four hundred years ago, the european tectonic plate has shifted signifi- cantly. As a result all coordinates have to be shifted by (1, 0).

Write a program that solves this puzzle. This has to be done in the following way: Start with the coordinates on the first row, add the coordinates of the second row at the back, then add the coordinates of the third row in front etc. Make a new Coordinate and CoordinateRow class for this assignment. The latter class has methods to add a CoordinateRow in front or at the back and methods to add a single Coordinate at the front or at the back. The coordinates of the puzzle are

5,4 4,5 8,7=6,3 3,2 9,6 4,3=7,6=9,8=5,5 7,8 6,5 6,4

Every CoordinateRow is seperated from another by an '='. Every coordinate in a row is seperated by a space. The x and y values of a coordinate are seperated by a comma. After all data has been read, the program will print the treasure route on the standard output. The correct route as out put would be:

6,5
8,8
7,5
7,4
8,6
6,4
5,5
9,7
7,3
4,2
10,6
5,3
10,8 

End of question."

I mean I do know that they want me to create classes but what I don't understand is how do i make methods that will add behind or in front of arrays.
I would highly appreciate your help.I am a beginner and never programmed some thing like this thats why asking for some help.
Thanks in advance.

UmNyobe
  • 22,539
  • 9
  • 61
  • 90
BlackSwan
  • 73
  • 1
  • 7
  • 7
    I will recommend to go see your TAs as often as you can, and prepare a part of the assignment with someone of your level. – UmNyobe Nov 27 '13 at 08:43

2 Answers2

1

It seems you are stuck because you are not familiar with the modelisation effort of going from the assignment statement to a solution design. This is a difficult task for everybody, not just beginners. But in your assignment you already got some guidelines.

First you have to understand what do you get as input and what should you output. In this case it is coordinates...

The first part of the assignment is some kind of story from which you have to extract the algorithmic problem.

As a result all coordinates have to be shifted by (1, 0).

This is the transformation you have to do to your inputs to get the desired output.

Then you need to understand the format of your input and outputs, and how you are going to represent them in java. The guidelines already requires one so you should ask yourself:

  • What is a Coordinate?
  • What is a CoordinateRow? What is in the class material or java api I can use to implement it?
  • How do I go from the string "5,4" to a Coordinate?
  • How do I go from the string "5,4 4,5 8,7" to a CoordinateRow?
  • Ok how do I go from a Coordinate to a string such as "5,4"?
  • Ok how do I go from a CoordinateRow to the program output?
  • What are the methods of Coordinate and CoordinateRow explicitly specified?
  • What are the other methods I will definitely need? Hint : remember the transformation above

At this point you already have a class structure with methods defined and just need to fill them.

UmNyobe
  • 22,539
  • 9
  • 61
  • 90
0

Because this is an assignment I don't think you will get much of an answer here.

Because you are new I'll give you a few links that may help;

How can I dynamically add items to a Java array?

Java - Add Element to an Array

http://www.tutorialspoint.com/java/java_methods.htm

In future you should do a google and attempt it first and ask the question with the code you have written. I also advise to use the java documentation, its pretty good and can be found here .

http://docs.oracle.com/javase/7/docs/api/

Hopefully those link have helped you:)

Community
  • 1
  • 1
Melbz
  • 512
  • 4
  • 14