CSCI 201 - Assignment 3
CSCI 201 - Assignment 3
Work Alone
It is important that all work you submit for this assignment (and all assignments in this class) be your own. You may talk to other students about the assignment, but you may not exchange code. All code written for this assignment must originate from your brain and your fingertips. You may not copy code from any other source (including the Internet). Please see me if you have questions!
Coding Standards
Be sure to follow the class coding standards (available in D2L) for this assignment! 1. Display a menu that asks the user if he/she wants to add, subtract, multiply, or divide, and get the users choice. You have a few options for doing this. You can list all the options to the user with a number by each option and have the user input the number of the option he/she would like. Alternatively, you could have the user enter the operator (+, -, *, or /) or keyword of the operator (add, subtract, multiply, or divide) he/she wants to perform. Either method is acceptable as long as it is clear to the user what you are asking. If the user enters a valid operator, have the user enter two decimal numbers. Perform the users selected arithmetic operation and output the result. This problem is similar to the first problem of the last assignment, except that instead of performing all arithmetic operations, we are only performing the one the user requests. If the user did not enter a valid operator in the beginning of the program, tell the user that the operator was invalid. In that case, do NOT proceed with asking the user for two numbers.
2. Write a Java program that asks the user to enter a radius of a circle. A decimal number is acceptable for the radius, but it needs to be positive. Once you have obtained a valid radius from the user, output the following 3 lines to the screen: the circle diameter (2 * radius), circle circumference (2 * pi * radius), and circle area (pi * radius * radius). If the user enters 0 or a negative number for the radius, tell the user the radius is invalid. Be sure to use Math.PI to get an accurate value of pi.
3. Write a Java program that asks a user to enter the coefficients a, b, and c. Use the coefficients to solve the quadratic formula for x. The coefficients can be decimal numbers. The only restriction is that a must not be zero. Quadratic Formula:
The discriminant is the name of the term under the root sign in the quadratic formula (b * b 4 * a * c). If the discriminant is negative, there are no real solutions for x. In this case, tell the user there are no real solutions. If the discriminant is 0, there will be one real solution for x. In this case tell the user there is one solution and display the value of x. If the discriminant is positive, there will be two solutions for x. In this case tell the user there are two solutions and display both values of x. Note: This is one of the rare situations where is it OK to name your variables a, b, and c. In most instances these would not be acceptable variables names, but in this case, those letters actually do accurately describe the purpose of the variables.