Hi guys, I'll cut straight to the chase; I'm in danger of failing my Java class, because I cannot any of this stuff out. It's too late for me to drop, and I can't fail the class. So, could you guys please help me out? Thanks!
*I'm not trying to weasel my way out of doing schoolwork. I just cannot figure this stuff out, and everything I've handed in I got a 0 or a 65. Thanks.
1. [Pass/fail] Read a grade (use type int) from the user and state whether the grade is passing or failing depending on whether or not it is 65 or higher:
Enter your grade: 57
Sorry, you failed!
2. [Password] Prompt the user for a password and then either grant or deny access based on their entry (just print a message, we can't do anything else). Be sure to use an if-else statement. Remember that you need to use
if (word.equals("swordfish"))
rather than
if (word == "swordfish")
to check if the String variable word contains the string "swordfish".
3. [Temperature converter] Ask the user if a temperature is in Fahrenheit or Celsius, then ask for the temperature. Then, based on the first answer, calculate and print the temperature in the other scale:
Enter F or C: f
Enter temperature: 98.6
98.6 F = 37.0 C
Running it again…
Enter F or C: C
Enter temperature: 100
100.0 C = 212.0 F
Use the formulas C=(5(F-32))/9 and F=1.8C+32 to do the conversion. Be sure to store the temperatures using the double data type, since the user can type a temperature with decimals.
Finally, you can use
if (scale.equalsIgnoreCase("C"))
to compare the letter typed to the letter C without regard to uppercase or lowercase.
4. [Division calculator] You're going to write a program to divide two numbers that the user enters. Prompt the user for 2 doubles. If the second number is zero, print a "divide-by-zero" error. Otherwise, calculate and print the result of dividing the first number by the second:
Enter first number: 4.8
Enter second number: 1.6
4.8 / 1.6 = 3.0
And again…
Enter first number: 4.8
Enter second number: 0
Error: Division by zero
5. 5. [Grade converter] Read an int grade from the user and convert it to A, B, C, D, F, or invalid based on the following ranges:
Grade range Grade
90-100 A
80-89 B
70-79 C
65-69 D
50-64 F
Anything else invalid
Enter grade: 82
That grade is a B.
Enter grade: 106
That grade is invalid.