Java 7. Ask the user for a float value that will represent a grade and determine
ID: 3877920 • Letter: J
Question
Java
7. Ask the user for a float value that will represent a grade and determine if the grade is in the "A" range. Print to the console "The grade is above an X" (where X is the minimum value for an "A" grade) if the grade is an "A" (You can decide for yourself what percentage is an "A" grade.) 8. Add to the previous "if" statement so that it becomes an "if/else" or multi-way if/else structure that will now also test to see if the grade is a "B" Output to the console if the grade is in that range. (While you don't necessarily have to use the logical "and" operator to solve this problem, note that in Java the "and" operator i:s represented by "&"or "&&") You can decide for yourself what percentage is a "B" grade. 9. Ask the user for a temperature, stored in a double. Is the temperature higher than 78 degrees or less than (or equal to) 78 degrees? Describe the current temperature as "higher than 78 degrees" or "less than or equal to 78 degrees". 10. For the temperature, write an "if/else" statement that asks if the temperature is (positive & odd) OR (zero & even)? (Notice the use of parenthesis here to define operator precedence. Look up order of operations (PEMDAS), "logical AND" and "logical OR" if this is unfamiliar in your text). If it is, output "yes; positive and odd or zero and even" and if it's not, say "no; not positive and odd or zero and even" on the console.Explanation / Answer
7. //program accepts the float value and prints the grade
import java.util.Scanner;
public class Jprogram {
public static void main(String args[]){
float inp;
// prompt the float value from the user
Scanner input1 = new Scanner(System.in);
System.out.print(" Enter the value :");
inp = input1.nextFloat();
//check the value greater than 70 or not
if(inp>70)
System.out.print(" The grade is above 70. its A grade");
else
System.out.print(" The grade is below 70.");
}
}
output:
Enter the value:80
The grade is above 70. its A grade
8.
import java.util.Scanner;
public class Jprogram {
public static void main(String args[]){
float inp;
// prompt the float value from the user
Scanner input1 = new Scanner(System.in);
System.out.print(" Enter the value:");
inp = input1.nextFloat();
//check the value greater than 79 grade A else >49 grade B
if(inp>79)
System.out.print(" The grade is A .");
else if(inp>49)
System.out.print(" The grade is B.");
else
System.out.print(" The grade is C.");
}
}
output:
Enter the value:60
The grade is B.
9.
package package1;
import java.util.Scanner;
public class Jprogram {
public static void main(String args[]){
double temperature;
// prompt the double as temperature from the user
Scanner input1 = new Scanner(System.in);
System.out.print(" Enter the temperature :");
temperature = input1.nextDouble();
//check the temperature value and prints the message
if(temperature>78)
System.out.print(" The Temperature greater than 78 degrees.");
else if(temperature == 78)
System.out.print(" The temperature is equal to 78 degrees.");
else
System.out.print(" The Temperature is less than 78 degrees.");
}
}
output:
Enter the temperature :90
The Temperature greater than 78 degrees.
Enter the temperature :40
The Temperature is less than 78 degrees.
10. positive & odd OR zero & even can be represented using logical AND, OR as :
if(((temperature>0)&&(temperature%2 ==1))||((temperature==0)&&(temperature%2 ==0)))
mod function % to find the number is odd or even.
coding:
package package1;
import java.util.Scanner;
public class Jprogram {
public static void main(String args[]){
double temperature;
// prompt the double as temperature from the user
Scanner input1 = new Scanner(System.in);
System.out.print(" Enter the temperature :");
temperature = input1.nextDouble();
//check the temperature is positive and odd or zero and even
if(((temperature>0)&&(temperature%2 ==1))||((temperature==0)&&(temperature%2 ==0)))
System.out.print(" yes, positive and odd or zero and even.");
else
System.out.print(" no; not positive and odd or zero and even. ");
}
}
output:
Enter the temperature :85
yes, positive and odd or zero and even.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.