This lab on math is due on SUNDAY August 24 at NOON (12pm). If you missed the lesson in class, you can watch here: https://www.youtube.com/watch?v=TEuuMhdvu1Y and https://www.youtube.com/watch?v=yuJLd2mU0Dc
Assignment 1: Create a program called Division.java (so public class Division). This program will ask the user to input an int number. It will then print out what the answers are for that number % 2, that number % 10, and that number / 10. Here's an example of what it might look like when you run it:
Type in your number
>124
You typed in 124. Your number %2 is 0 [since 124%2 = 0]
Your number %10 = 4
Your number / 10 = 12
Assignment 2: Create a program called Interest.java. If you store money in some banks or investments, you can make money on interest. This program will calculate how much you will make. It will ask the user for an initial amount of money, an interest rate (like 6% - they will just type in 6 though, not the percent sign), and the amount of time you will keep your money in the bank, and then calculate the amount of money they will have at the end.
-The program should convert a percent entered into a decimal. For instance, if the user gives 5 (representing 5%), your program should change that into .05 for the calculation.
-To calculate interest, the formula is (initial amount)*(1+interest rate)^t , where t is the amount of years. [the ^t means raise to the t power]. Use Math.pow for the exponent.
For instance, if the user types in 1000 dollars at 5 percent interest for 3 years, that is worth:
1000 * (1.05)^3 = 1157.63
Your program would just print out the final answer 1157.63
It is fine that your answer has more than two decimals.
Submit Interest.java to your google drive
Assignment 3: Create a program called QuadraticFormula.java that will ask the user for the coefficients of a quadratic equation (the values of a,b, and c), then calculate and print the two solutions using the quadratic formula. The user will type in three numbers for a,b, and c (for example, 1, 6, 8) and your program will calculate and then print out the two answers to the corresponding equation (in this case, it would print out -2 and -4). You do not need to represent the equation in terms of x, you just have to give the answers. Be careful with parentheses!! It should look like this when you run it:
Type in a:
>2 (user types in 2)
Type in b:
>5
Type in c:
>3
The roots are -1.0 and -1.5.
Feel free to look online if you forget the quadratic formula :).
NOTE: if you type in numbers which do have a solution (meaning the square root would have a negative inside), your program will probably output NaN (not a number) . This is fine and you do not need to worry. YOU MAY ASSUME THAT THE USER WILL TYPE IN VALUES OF a,b,c THAT LEAD TO REAL SOLUTIONS - YOU WILL NOT GET A NEGATIVE INSIDE A SQUARE ROOT. For instance, your program should be able to solve x2-9=0 (and give 3 and -3 as answers) or 2x2 + 5x +3 = 0 (solutions should be -1 and -1.5) but not necessarily x2 + 9 = 0. Submit QuadraticFormula.java to your google drive folder.
Assignment 4: Create a program called DoubleDivide (saved in DoubleDivide.java). In this program, you will ask the user for two ints. It will then divide them both ways, giving you the answer as both an int, and casting to give a double for four total outputs. For example, here is what it will look like when running:
Type in two numbers
>3
>4
Doing 3/4 would be 0 or 0.75. //since 3/4 = 0 and 3.0/4 = 0.75
Doing 4/3 would be 1 or 1.33333333 //since 4/3 = 1 and 4.0/3 = 1.3333333
Assignment 5: Create a program named CastAverage.java that asks the user for three ints (using nextInt()) and then print out the average of those three as a double. It should then take that average, multiply it by 10, and cast THAT number as an int then print it.
Here is a sample of what if might look like:
>>user inputs 2,6,8
Your program prints 5.3333333333333 //the average of 2,6,8 is 5.3333333333
//now your program does 5.333333333*10, which is 53.33333333333 then casts that as an int:
Your program then also prints 53.
Once you have tested your code, submit CastAverage.java
Are you done with these assignments and still have time left? Try these options:
-make sure your code is tested, commented correctly and looks nice
-help people around you
-for 2 points of extra credit, create a program called QuadraticFormulaComplex that will assume the user enters a, b and c of a quadratic equation with complex roots. Your program does not need to solve equations with real solutions. It should print out the roots in a+bi format (Hint: use Math.abs)