Data are read from the keyboard according to the format deta
Data are read from the keyboard according to the format details below. Each line corresponds to
readings from an instrument (coded 1 to 4) Input data has lines organized as follows:
The program reads this data until an end of file is indicated (signal by a control D from keyboard) All readings except when the reliability code is ”EE” are processed. A SELECT CASE statement is used to organize the FORTRAN 90 program to process the various instruments (coded 1 to 4 in the data file). Three sums of the products v1*vi1 are found:(a) the sum for instrument code 1, (b) the sum for instrument code (2), and (c) the total sum for instruments coded 3 or 4. These sums are printed using sum1, sum2 and sum3 respectively in the code.
Write a FORTRAN 90 program which reads this data from the keyboard (use the Unix redirect ”<” with the data file) and carries out the computations detailed above.
Additionally print neatly formatted (identical to the example below) output of the data read in.
An example run with the program for this problem follows:
A partial FORTRAN 90 program to accomplish the goals of this problem follows:
-5 1
141 -15 3 94 192 -15 4
Starting with the above partial code, complete the solution to this problem. DO NOT USE ANY VARIABLES BEYOND THOSE DECLARED. ADD TO, BUT DO NOT ALTER THE PARTIAL CODE PROVIDED EXCEPT TO FILL IN YOUR INDIVIDUAL NAME IN THE PARTS BE- TWEEN THE ANGLE BRACKETS. Provide test results for the data file:
EC-1.59 -11 4 CC1.54 3 2 EE-1.60 -15 4 ED-2.83 9 4 EE-1.78 6 3 BB-2.73 -7 1 DC0.92 1 3 EE1.60 1 4 CE-2.56 -15 2 DB 0.84 18 3
Solution
public class TurtleExample {
// cut and paste into TurtleMove.java
public static void sierpinski(int n, int length, TurtleGraphics theTurtle){
if (n == 0) return;
for (int i = 0; i < 3; i++){
sierpinski(n-1,length/2, theTurtle);
theTurtle.forward(length);
theTurtle.right(120);
}
}
// cut and paste into TurtleMove.java
public static void tree(int r, TurtleGraphics theTurtle){
if (r<5){
theTurtle.forward(r);
theTurtle.backward( r);
} else {
theTurtle.forward( r/3);
theTurtle.left(30);
tree(r*2/3, theTurtle);
theTurtle.right(30);
theTurtle.backward( r/3);
theTurtle.forward(r/2);
theTurtle.right(25);
tree(r/2,theTurtle);
theTurtle.left(25);
theTurtle.backward(r/2);
theTurtle.forward( r*5/6);
theTurtle.right(25);
tree(r/2, theTurtle);
theTurtle.left(25);
theTurtle.backward(r*5/6);
}
}
// cut and paste into TurtleMove.java
public static void brocolli(int r, TurtleGraphics theTurtle){
// Leaf node just draw a stem
if (r<5){
theTurtle.forward(r);
theTurtle.backward( r);
} else {
// Make stem
theTurtle.forward( r/3);
// Make left branch
theTurtle.left(30);
brocolli(r*2/3, theTurtle);
// Make right branch
theTurtle.right(60);
brocolli(r*2/3, theTurtle);
// Return to center orientation
theTurtle.left(30);
// Return to base of stem
theTurtle.backward( r/3);
}
}
// cut and paste into TurtleMove.java
public static void koch(float r, float size, TurtleGraphics theTurtle) {
if (r <= 1) {
theTurtle.forward((int) (r*size));
theTurtle.left(60);
theTurtle.forward((int) (r*size));
theTurtle.right(120);
theTurtle.forward((int) (r*size));
theTurtle.left(60);
theTurtle.forward((int) (r*size));
} else {
koch(r-1, size/3, theTurtle);
theTurtle.left(60);
koch(r-1, size/3, theTurtle);
theTurtle.right(120);
koch(r-1, size/3, theTurtle);
theTurtle.left(60);
koch(r-1, size/3, theTurtle);
}
}
public static void main(String[] args) {
// Setup EZ graphics system.
TurtleGraphics aTurtle = new TurtleGraphics(1000,512);
TurtleGraphics bTurtle = new TurtleGraphics(1000,512);
aTurtle.penup();
aTurtle.moveTo(50, 500);
aTurtle.pendown();
koch(3, 300, aTurtle);
/*
aTurtle.setPenSize(2);
aTurtle.penup();
aTurtle.moveTo(500, 500);
aTurtle.left(90);
aTurtle.pendown();
brocolli(400,aTurtle);
*/



