Lecture¶

This will be updated with Monday’s lecture slides.

Lecture Activity 3 - Instructions¶

In lecture activity 3, we will practice writing some more Java programs

General instructions for creating Java files¶

For each of the following Tasks, create a separate Java file called task1.java, task2.java, task3.java etc…

Remember, to create a new file, first navigate to this directory locally using cd path/to/this/repo and then type: code task1.java. This will open a new file called task1.java in Visual Studio Code. You can also work in Geany, or Eclipse, it’s your choice.

public class task1 {

	public static void main(String[] args) {
	  // Enter your code
	}
  
}

Don’t forget to change the name of the public class method for each file!

Task 1: Review printing¶

Write Java code that prints your name 6 times.

Task 2: Exponent Table¶

Write Java code that displays the following table:

x 	x^5 	x^10
1 	1 	1
2 	32	1024
3 	243	59049

Task 3: Calculate and Print Area¶

Write Java code that calculates and displays the area and perimeter of a circle that has a radius of 5.5 using the following formulae:

perimeter = 2 * \(\pi\) * \(r\) area = \(\pi\) * \(r\) * \(r\) *.

Sample output:

Area: 95.0440975
Perimeter: 34.55749

Task 4: Complex Calculation¶

Write Java code that computes the answer to this expression:

\[\frac{3 \cdot 4.5 + 5 \cdot 7.1}{7.2 \cdot 5.5}\]

Task 5: Accepting Input¶

Write Java code that accepts two user inputs: a distance in m and the time it takes for the person to run that distance in seconds. Print out the average speed of the runner.

Sample output:

You ran 10 m/s !

Task 6: Update your README file¶

If you named your files as suggested above, you do not have to do anything in this section. If you named your files differently, please update the links below to make sure they work.

Task 1 Java file

Task 2 Java file

Task 3 Java file

Task 4 Java file

Task 5 Java file