CS46A Spring 19

5A

Write a program called TetrahedronPrinter that will compute the surface area and the height of a regular tetrahedron given the length of its side. A regular tetrahedron has 4 faces and all the edges are the same length. The formulas and a picture are here. (Scroll down to find the formulas)

Ask the user to input the edge length using Scanner class. (Use the prompt, "Enter the edge length: ") Test that the input is non-negative. If it is negative, print the message "Edge can not be negative". Otherwise, calculate and print both surface area and height formatted to 2 decimal places. Use printf. Do not round with some other method.

For the draft, ask the user for the edge length and print it formatted to two decimal places with printf. In the draft, don't test if the value is non-negative. You will do that in the final.

5A draft:
5A final:

5B

We do not want users of our classes to be able to set invalid values for instance variables. Now that you know how to use if statements, you are going to add error checking to a a few classes from earlier homeworks.

You should not print error messages from constructors or methods of object. In the real world, you might throw an exception when the parameter is invalid, but we have not covered exceptions yet. We will just be sure the data in our objects are valid. Follow the directions below to add error checking to each class.

Use proper if structure. Do not do unnecessary tests . Do not have empty if or else blocks

You can get working versions of any of these from the solutions posted on laughton.com/obrien/sjsu.

HeliumBalloon (hw 4a)

WaterFlask (hw3b)

Climber (hw 3a)

For the draft, make the changes to HeliumBalloon

5B draft:
5B final:

5C

Write a class called MyNumber that represents a positive number. MyNumber has a constructor that takes an integer.

Provide the constructor:

Provide methods

For the draft, provide, the instance variable, the constructor and the getNumber method.

5C draft:
5C final: