--add in simple short one with inputs and % at start
There are five short assignments in this lab on math, inputs, and random numbers. They are all due on Thursday, August 17 at 11:59 pm. 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 and https://www.youtube.com/watch?v=BRVBoXk-Ojk
Assignment 1: 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 on interest. 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 convert 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 2: Create a program called QuadraticFormula.java that will ask the user for the coefficients of a quadratic formula (the values of a,b, and c in ax2 + bx + c = 0), then calculate and print the two roots. 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 quadratic 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 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 YOU WILL GET 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 3: We will now get some practice with casting. 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
Assignment 4: The California Mega Millions lottery picks its winners by choosing 5 random numbers (integers) from 1 to 56 (including 56), followed by a golden ball that is a random integer from 0 to 46 (including 46). Design a java program called MegaMillions.java that will randomly choose and print one set of six mega millions lottery numbers. For the sake of this program, we will assume that it is alright if some of the numbers repeat (for instance, the number 17 could show up twice - soon we will learn how to prevent this from happening).
After it prints out the numbers, have your program also print out the prize the winner will get. The prize should be a random double between 1 million and 5 million (note: your number may print in scientific notation with an E, this is fine).
TIP: Do not buy lotto tickets. The lotto is a tax on people who are bad at math.
Assignment 5: Make a program called RandomNumbers.java that has the user (with Scanner) enter 2 integers, a and b (you may assume that b, the second number they type in, will be bigger than a). The program will then print out a random double between a and b AND a random integer between a and b (including both endpoints). For example, if the user types in a=4 and b = 7, it should print out a double on the interval [4,7) and for the int, either 4,5,6 or 7. Use your notes!
Test this program several times to make sure it gives you all of the possible integer values and every value it gives is between a and b.
HINT: remember, if you want a random integer between 2 and 5, there are 4 (not 3) possible options.
Submit RandomNumbers.java and MegaMillions.java to your folder in google drive!
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)