I am working on a new project known as "construction building". I am pretty weak in java coding thus i am sincerely asking all of you to hold my hand and guide me step by step with the implementation. I know it is ridiculous to ask you guys for help without putting in effort myself thus i have spent some thought on the implementation process and these is what i have came up with.
A construction company would like to calculate the height difference between the planks set.
(Height different between 1 and 2 is (1)) && (Height different between 1 and 4 is (2)) && (Height different between 1 and 5 is (3))
Untitled.jpg
so to start off with it, i thought i would set a criteria. The focus point will be the top most plank.
since the insert order might be random, <start, end , height>
<4,5,1> <2,6,4>
<5,7,3> <1,3,3>
<2,4,2> into <5,7,3>
<2,6,4> <2,4,2>
<1,3,3> <4,5,1>
then i will grab the plank with the highest height value and set it as my "focus"
using the focus <start, end , height>, i will start to do a compare value as per what you have showed me previously to eliminate those planks that is not anywhere below the "focus" plank.
plank.start > focus end
plank.end < focus.start
plank.height > focus.height
after eliminating those planks that are not anywhere below the "focus" plank, we take the height of the "focus" plank and subtract the height of the "other" planks below.
however there is a part which i have yet thought of the implementation process and that is how do i get the
plank 1)<2,6,4> - plank5)<4,5,1> = <4,5,3> (where <4,5,x> is the place where the height difference is calculated , and x is the height difference)
I am thinking of implementing my code in such format which i have adopted from on of the forum member. I know it is not much and it is more of a sudo code than a working code.
public static Map<Position, List<Position>> getHeightDifference(List<Position> planks) { final float start; final float end; final float height; public Position(float start){ this.start = start; } public Position(float end){ this.end = end; } public Position(float height){ this.height = height; } public float getStart(){ return this.start; } public float getEnd(){ return this.end; } public float getHeight(){ return this.height; } @Override public int compareTo(Position focus) { if(this.start > focus.getEnd()) { return -1; } else if (this.end<focus.getstart) { return -1; } else if (this.height > focus.height) { return -1; } else { return 0; } }