# Lab 3: Introduction to `long`, `double`, and `Math.pow`

Due Tuesday, September 13 at 11:59 PM

## Goals for This Lab

By the time you have completed this work, you should be able to:

• Be able to identify the type of expressions involving `int`, `String`, `long`, and `double`
• Read in user input as big numbers (`long`) or floating-point numbers (`double`)
• Write computations which intermix `int`, `long`, and `double`
• Use `Math.pow()` for exponentiation
Provided files:

# Step-by-Step Instructions

## Step 1: Answer Questions Regarding Types

Download the `lab3questions.txt` file, and edit it with a text editor of your choice. Answer the questions in the file. Be sure to use the appropriate formatting. Save your work in your own local copy of `lab3questions.txt`. Be sure to preserve the filename and file type!

## Step 2: Edit `LongPerimeterCalculation.java`

Download the `LongPerimeterCalculation.java` file, and open it in jGrasp (or a text editor of your choice). The program you write should behave exactly the same as `PerimeterCalculation.java` from last week. The only difference is that instead of using `int` variables to store the width, height, and area, you should use `long` variables. Similarly, you should use `nextLong()` as opposed to `nextInt()`. An example run of the program is shown below, with user input in bold:

```Enter width: 2000000000
Enter height: 2000000000
Perimeter: 8000000000
```

For full credit, the output of your program must match EXACTLY to the output shown above. Note that if you use `int` variables instead, your calculations will be incorrect, resulting in a different area shown above. As a hint, you may want to simply copy your code from your `PerimeterCalculation.java` solution, and then modify it to use `long` variables and `nextLong()`. Your code will overall look somewhat similar to `LongAddTwo.java`

## Step 3: Edit `DegreeConversion.java`

Download the `DegreeConversion.java` file, and open it in jGrasp (or a text editor of your choice). The program you need to write will take a temperature in Celsius and convert it to Fahrenheit. Notably, the temperature received can be a floating-point value, and the result will be a floating-point value, so you will need to use `double` variables and `nextDouble()`.

You can convert a temperature in Celsius to a temperature in Fahrenheit using the following formula, where `C` represents the input temperature in Celsius, and `F` represents the output temperature in Fahrenheit:

```F = C * 1.8 + 32
```

An example run of the program is shown below, with user input in bold:

```Enter temperature in Celsius: 41.75
Fahrenheit: 107.15
```

For full credit, the output of your program must match EXACTLY to the output shown above. Note that if you use `int` variables instead, your calculations will be incorrect, resulting in a different Fahrenheit temperature shown above.

## Step 4: Edit `CompoundInterest.java`

Download the `CompoundInterest.java` file, and open it in jGrasp (or a text editor of your choice). The program you need to write will compute compound interest including principal. In order to perform this computation, your program will need to gather the following inputs from the user in the following order:

1. Principle (`P`, a `long` value)
2. Annual interest rate (`R`, a `double` value)
3. Number of times interest is compounded per year (`N`, an `int` value)
4. Number of years invested (`T`, an `int` value)

With the above information, the compound interest can be computed using the following formula, where `A` represents the result (the compound interest including principle):

```A = P * (1 + R / N)(N * T)
```

Note that the result (`A`) can be a floating-point value, so it should be represented as a `double` if it has its own variable. Exponentiation can be performed with `Math.pow`; for example, `54` can be written in Java like so:

```Math.pow(5, 4)
```

An example of exponentiation in practice can be seen in `Exponentiation.java`.

An example run of the program you must write is shown below, with user input in bold:

```Enter principle (long): 500
Enter annual interest rate (double): 0.053
Enter number of times interest is compounded per year (int): 12
Enter number of years invested (int): 8
Compound interest including principal: 763.3178417090967
```

For full credit, the output of your program must match EXACTLY to the output shown above. If you do not use the correct variable types, your calculation will likely be incorrect and lead to output which is different from what is shown above.

## Step 5: Turn in Your Solution Using Canvas

Log into Canvas, and go to the COMP 110 class. Click “Assignments” on the left pane, then click “Lab 3”. From here, you can upload your answers and your code. Specifically, you must turn in the following three files:

• `lab3questions.txt`
• `LongPerimeterCalculation.java`
• `DegreeConversion.java`
• `CompoundInterest.java`

In addition, if you collaborated with anyone else, be sure to download `collaborators.txt` and write the names of the people you collaborated with in the file, one per line. Please submit this file along with the other four files.

You can turn in the assignment multiple times, but only the last version you submitted will be graded.