1) Write a program using the switch statement name GradeReport that reads a grad
ID: 3685933 • Letter: 1
Question
1) Write a program using the switch statement name GradeReport that reads a grade from the user and prints the comments accordingly. Hint Prompt the user to enter their grade user must be prompt to enter a numeric grade (0 to 100) if the input isn't an integer between 0 and 100, prompt the user to re-enter Use a do loop for the re-enter of grade then if condition is not met or grade is not between 0 and 100 then prompt the user on the screen as follows ("Error: You must enter an integer between 0 and 100");” Also incorporate a while loop to keep track of tries. create a variable name “tries” that will keep track of tries no more than 3 therefore if the input isn't an integer between 0 and 100, prompt the user to reenter Below I have provided a demo of the switch statement category = grade / 10 switch (category) case 10: Perfect score job well case 9: well above average. Excellent case 8: above average Nice job case 7: average case 6: below average you should see the professor...to clarify the material presented in class...
2) Write the code to display the content below The program Name is Half_XmasTree. This program MUST use (ONLY) for loops to display the output below from 1 to 10...1st row prints 1 star 2nd row prints 2… 3rd print 3 stars and so forth... This program is controlled by the user to input the amount of row. A good test condition is the value of ten rows. The user will demand the size of the tree. A good test condition is the value of ten rows. Remember the purpose of print() and println()
**********
*********
********
*******
******
*****
****
***
**
*
3) Write the code to display the content below The program Name is Full_XmasTree. This program MUST use (ONLY) for loops to display the output below For example the 1st row prints 1 star 2nd row prints 2, the 3rd row print 3 stars and so forth... This program is controlled by the user to input for the amount of row. A good test condition is the value of ten rows. (hint***)This program should account for white spaces print(“* ”). Remember the purpose of print() and println()
*
**
***
****
*****
******
*******
********
*********
Explanation / Answer
Question 1:
GradeReport.java
public class GradeReport {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
java.util.Scanner in = new java.util.Scanner(System.in);
int grade = 0;
int tries = 0;
int TOTAL_CHANCES = 3;
int category = 0;
do{
System.out.println("Please enter the grade between 0 and 100");
grade = in.nextInt();
if(grade >= 0 && grade <= 100){
category = grade / 10;
switch(category){
case 10: System.out.println("Perfect score job well"); break;
case 9: System.out.println("well above average. Excellent"); break;
case 8: System.out.println("above average Nice job"); break;
case 7: System.out.println("average"); break;
case 6:
case 5:
case 4:
case 3:
case 2:
case 1:
case 0: System.out.println("below average you should see the professor...to clarify the material presented in class..."); break;
default: System.out.println("Invalid case"); break;
}
break;
}
else{
System.out.println("Error: You must enter an integer between 0 and 100");
tries++;
}
} while(tries < TOTAL_CHANCES);
}
}
Output:
Please enter the grade between 0 and 100
1
below average you should see the professor...to clarify the material presented in class...
Please enter the grade between 0 and 100
82
above average Nice job
Please enter the grade between 0 and 100
101
Error: You must enter an integer between 0 and 100
Please enter the grade between 0 and 100
102
Error: You must enter an integer between 0 and 100
Please enter the grade between 0 and 100
-1
Error: You must enter an integer between 0 and 100
Please enter the grade between 0 and 100
66
below average you should see the professor...to clarify the material presented in class...
Question 2
Half_XmasTree.java
public class Half_XmasTree {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
java.util.Scanner in = new java.util.Scanner(System.in);
System.out.println("Please enter the size of tree ..");
int size = in.nextInt();
String str = "";
for(int i=size; i > 0; i--){
str = "";
for(int j = 0; j<i; j++){
str = str + "* ";
}
System.out.print(str);
System.out.println();
}
}
}
Output:
Please enter the size of tree ..
10
* * * * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
Please enter the size of tree ..
5
* * * * *
* * * *
* * *
* *
*
Question 3:
Full_XmasTree.java
public class Full_XmasTree {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
java.util.Scanner in = new java.util.Scanner(System.in);
System.out.println("Please enter the size of tree ..");
int size = in.nextInt();
String str = "";
for(int i=1; i <= size; i++){
str = "";
for(int j = 0; j<i; j++){
str = str + "* ";
}
System.out.print(str);
System.out.println();
}
}
}
Output:
Please enter the size of tree ..
10
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
Please enter the size of tree ..
5
*
* *
* * *
* * * *
* * * * *
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.