JavaRush /Java Blog /Random EN /Error in Learn Java Tutorial by Katie Sierra and Burt Bat...
lookinbody
Level 11
Москва

Error in Learn Java Tutorial by Katie Sierra and Burt Bates

Published in the Random EN group
Good day everyone. In between work and CodeGym, I bought and started reading Learning Java by Kathy Sierra and Bert Bates. Today I did another homework in the textbook. I couldn't solve the problem " class Triangle " p. 95. In IntelliJ IDEA, the answer came out wrong. Killed two hours, went through all the possible options, nothing happened. Spat, climbed into the answers. And there is my very first decision. As a result, if you drive this code into IntelliJ IDEA, then the answer will not be the one written in the tutorial. Tutorial errorThe correct solution from the answers looks like this:
public class Triangle
{
    double area;
    int height;
    int lenght;
    public static void main(String[] args)
    {
        int x = 0;
        Triangle [] ta = new Triangle[4];
        while (x < 4)
        {
            ta[x] = new Triangle();
            ta[x].height = (x + 1) * 2;
            ta[x].lenght = x + 4;
            ta[x].setArea();
            System.out.print("треугольник " +x+ ", зона");
            System.out.println(" = " + ta[x].area);
            x = x + 1;
        }
        int y = x;
        x = 27;
        Triangle t5 = ta[2];
        ta[2].area = 343;
        System.out.print("y = " + y);
        System.out.println(", зона t5 = " + t5.area);
    }
    void setArea()
    {
        area = (height + lenght) / 2;
    }
}
The answer according to the authors of the textbook should be:
треугольник 0, зона = 4.0
треугольник 1, зона = 10.0
треугольник 2, зона = 18.0
треугольник 3, зона = 28.0
y = 4, зона t5 = 343.0
In reality, the answer looks like this:
треугольник 0, зона = 3.0
треугольник 1, зона = 4.0
треугольник 2, зона = 6.0
треугольник 3, зона = 7.0
y = 4, зона t5 = 343.0
I only had two answers:
  1. Technical error and typo.

  2. The book was written in Java 5.0, I solve the problem in Java 8.0

Please tell me how right I am in my guesses.
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION