CSci 1211 Problem set 2. Due Friday, Jan. 30th at 5pm

Resources: Java Math class. Also, use the examples from the January 23rd class (see resources web page).

Note that in this problem set you have to write your programs "from scratch", i.e. you are not given any files to start from. Feel free to copy/paste code from the examples given in class, but make sure to keep the class name and the file name consistent. Please write your program in good programming style: choose meaningful names of variables and don't forget comments!

Problem 1 (10 points): Computing a power of a number.

Write a program that will prompt the user for an integer number (say, n) and for a double (say, x) and then output the result of raising x to the power n. An example of the program run should look like this:

Please enter an integer: 4
Please enter a number: 2.78
The 4th power of 2.78 is 59.728166559999984
Use Math.pow for the computation. Don't worry if your program prints out things like "The 2th power...", it's fine at this point. Later we will learn how to print different messages depending on values of variables.

Problem 2 (15 points): Computing total energy of an object.

Exercise 8 p. 65. Write a Java program that reads the mass, the height, and the velocity of an object and computes its total energy. Use g = 9.81 meters per square second. Declare it as a constant in your program (use the keyword final).

Test your program on several different values of inputs. Double-check your computations on a calculator.

Problem 2 (15 points): Computing the period of a pendulum.

Exercise 11 p. 65. Use appropriate Math functions for the computation. Use Math.PI for the value of Pi. As in the previous problem, test your program carefully and double-check the computations.
This page is a part of the course CSci 1211 at UMM.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.