Hi folks,

Guess what....I am kind of new to OO programming programming.
However, I have this task to complete in next week and if someone is willing to help, would be much appreciated.

Task: Given input file A, translate the content to produce output file B

File A: Consists of multiple lines of data, whereby each line is of form
X;1.9,2;3,4.3; 5,6

Output file B, should consists of one line per shape and should be formatted as follows.
Shape[TRIANGLE], Points[[[3.0,3.0], [5.0, 8.0], [8.0,4.0]]], Area[9.0]

This should be supporting 4 shape types: Circle, Square, Triangle, Rectangle.

This should demonstrate OO design principle and use Factory design patten and Unit tests.

Note: File A has these cartisean coordinates and is a xxx.dat file;

t: 3,3; 5,8; 7,4
s:-1,-6; -1,-3; 2, -3; -2, -6
c: -4, -3; -2,-1
r:-1,1;4,1; -5; -1,-5

Make an effort at some part of the problem (say just reading the file would be a start)
http://www.daniweb.com/forums/announcement9-2.html

Don't forget this when posting code
http://www.daniweb.com/forums/announcement9-3.html

Hello Salem,

Forgot to say that so far I have modeled the Shape OO principal and manage to calculate my Area. Also I can read the file too. Where I need real help is in the translation of input and know which input line is associated with which shape. By the way this is not an academic coursework. Iys only for my gaining and would like to see others peoples approaches to this problem. Any help is greatly appreciated....

Baftjar

Post an example input file and the corresponding example output file. The examples you posted don't correspond and therefore don't make any sense to me. You also said that each line in File A translates into something in file B... give a sample of one line from File A, and what the program would produce in File B based on that.

Post an example input file and the corresponding example output file. The examples you posted don't correspond and therefore don't make any sense to me. You also said that each line in File A translates into something in file B... give a sample of one line from File A, and what the program would produce in File B based on that.

Hello BestJewSinceJC,

Thanks for showing some interest to help me on domain problem.

The example I tried to show is mainly to illusterate the point of how data from File A can be read line by line, and then each line read should determine what kind of shape these coordinates give us, and calculate the area of that shape.

I hope now it has become clearer for you. Your help is more than welcome at this point.

Baftjar.

Ps: Nice Username by the way!

I understand what the example was meant to illustrate, but I didn't understand the example. If you want my help, you'll have to provide a one line example input and the corresponding output that would be produced based on it. Then I can help you from there

:)

I understand what the example was meant to illustrate, but I didn't understand the example. If you want my help, you'll have to provide a one line example input and the corresponding output that would be produced based on it. Then I can help you from there

:)

Hello again,

Ok, I will try my best to be precise on this:

-INPUT
File A.dat - contains these coordinates which can be a triangle
t: 3,3; 5,8; 7,4

- It should read it and determine if is Triangle, Square, Circle or Rectangle

- OUTPUT

Shape[TRIANGLE], Points[[[3.0,3.0], [5.0, 8.0], [8.0,4.0]]], Area[9.0]
- Should determine that the shape is Triangle, Point coordinate pairs and Area should be calculated. This should be the case for all other lines in file A.

Is it this time clearer for you my friend?

Let me know if you have any observations, since I tend to miss the point at time in explanation to others . I hope you understand that my level is not great in this technology.

Many thanks,

Baftjar

I understand your problem now. As Salem said, keep in mind that we don't do work for people, but we'll be glad to help you solve the problem on your own by giving you ideas, suggestions, tips, and guidance. Anyway:

You will need a few classes to accomplish your task. I recommend a main class (to run your application and call the other classes), a "Point" class that represents an (x,y) coordinate, a Shape class, and a Circle, Square, Triangle, and Rectangle class. Circle, Square, Triangle, and Rectangle should extend Shape since they are all Shapes. Square should extend Rectangle since it is a special case of a Rectangle. (That might be a little overkill, and you may not even need a Square class, but you can decide that on your own). Anyway, your main class should look something like this:

-Open the input file for reading
while(the input file has more lines){
-read in the next available line
-figure out which type of Shape you just read in. This might be complicated; remember those Shape classes I suggested? Each class - Circle, Rectangle, etc - should have a method that checks whether or not a specific set of points represents that type of shape.
-output the appropriate shape. Again, each shape class you use should have a print method that prints the appropriate info.
}


Also, you should keep in mind that there might be classes that help you do these things already. Lets say that you find a class called Rectangle after searching on google that already has some of the methods you need. Then you should extend that class, using those methods, and add your own methods (such as your print method) that will be specific to your project. Good luck & feel free to mention if something is unclear.

> Also I can read the file too.
So post something then.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.