Exercise 1 : Write a Java program that determines a student’s grade. The program
ID: 3881263 • Letter: E
Question
Exercise 1:
Write a Java program that determines a student’s grade.
The program will read three types of scores(quiz, mid-term, and final scores) and determine the grade based on the following rules:
-if the average score >=90% =>grade=A
-if the average score >= 70% and <90% => grade=B
-if the average score>=50% and <70% =>grade=C
-if the average score<50% =>grade=F
See the example output below:
Quiz score: 80
Mid-term score: 68
Final score: 90
Your grade is B.
Exercise 2:
Write a Java program to calculate the revenue from a sale based on the unit price and quantity of a product input by the user.
The discount rate is 10% for the quantity purchased between 100 and 120 units, and 15% for the quantity purchased greater than 120 units. If the quantity purchased is less than 100 units, the discount rate is 0%.
See the example output as shown below:
Enter unit price: 25
Enter quantity: 110
The revenue from sale: 2475.0$
After discount: 275.0$(10.0%)
Exercise 3:
Write a Java program to detect key presses.
If the user pressed number keys( from 0 to 9), the program will tell the number that is pressed, otherwise, program will show "Not allowed”.(Using Switch Case)
Exercise 4:
Write a Java program to sum values of an array. (User must give the length of the array)
Exercise 5:
By using the bubble sort algorithm, write a Java program to sort an integer array of 10 elements in ascending.
Exercise 6:
By using the sequential search algorithm, write a Java program to search for an element of an integer array of 10 elements.
Exercise 7:
Write a Java program to answer about the statistical information such as arithmetic mean, median, mode, and standard deviation of an integer data set. The data points are input by the user from keyboard.(Mean, Median, Mode and Standard Deviation)
Exercise 8:
Write a Java program to insert an element (specific position) into an array
Exercise 9:
Write a Java program to find the maximum and minimum value of an array.
Exercise 10:
Write a Java program to reverse an array of integer values.
Exercise 11:
Write a Java program to find the duplicate values of an array of integer values
Explanation / Answer
Hi... As per chegg rules i have answered first 4 exercises only. Please check below answes and post the remaining questions as 4 each. Please check below answers.
Exercise 1:
Medium.java
import java.util.Scanner;
public class Medium {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Quiz score:");
double qscore=sc.nextDouble();
System.out.println("Mid-term score:");
double mscore=sc.nextDouble();
System.out.println("Final score:");
double fscore=sc.nextDouble();
double avgscore = (qscore+mscore+fscore)/3;
if(avgscore>=90){
System.out.println("Your grade is A.");
}else if(avgscore>=70 && avgscore<90){
System.out.println("Your grade is B.");
}else if(avgscore>=50 && avgscore<70){
System.out.println("Your grade is C.");
}else if(avgscore<50){
System.out.println("Your grade is F.");
}
}
}
Output:
Quiz score:
80
Mid-term score:
68
Final score:
90
Your grade is B.
Exercise 2:
Revenue.java
import java.util.Scanner;
public class Revenue {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.print("Enter unit price:");
double unitprice = sc.nextDouble();
System.out.print("Enter quantity:");
double quantity = sc.nextDouble();
int discount = 0;
if(quantity>120){
discount = 15;
}else if(quantity>=110 && quantity<=120){
discount = 10;
}
if(discount==0){
double total = unitprice*quantity;
System.out.println("The revenue from sale: "+total+"$");
System.out.println("After discount: 0$(0%)");
}else{
double total = unitprice*quantity;
double disc = (total*discount)/100;
System.out.println("The revenue from sale: "+(total-disc)+"$");
System.out.println("After discount: "+disc+"$("+discount+"%)");
}
}
}
Output:
Enter unit price:25
Enter quantity:110
The revenue from sale: 2475.0$
After discount: 275.0$(10%)
Exercise 3:
Detect.java
import java.util.Scanner;
public class Detect {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
boolean flag = true;
while(flag){
System.out.println("Press key:");
String n = sc.next();
switch(n){
case "1": System.out.println("you presses 1");
break;
case "2": System.out.println("you presses 2");
break;
case "3": System.out.println("you presses 3");
break;
case "4": System.out.println("you presses 4");
break;
case "5": System.out.println("you presses 5");
break;
case "6": System.out.println("you presses 6");
break;
case "7": System.out.println("you presses 7");
break;
case "8": System.out.println("you presses 8");
break;
case "9": System.out.println("you presses 9");
break;
case "0": System.out.println("you presses 0");
break;
default: System.out.println("Not allowed");
break;
}
}
}
}
Output:
Press key:
1
you presses 1
Press key:
w
Not allowed
Press key:
#
Not allowed
Press key:
4
you presses 4
Press key:
Exercise 4:
SumArray.java
import java.util.Scanner;
public class SumArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter length of array:");
int max = sc.nextInt();
int array[] = new int[max];
int total=0;
System.out.println("Enter array elements:");
for(int i=0;i<max;i++){
array[i]=sc.nextInt();
total+=array[i];
}
System.out.println("Sum of array values are: "+total);
}
}
Output:
Enter length of array:
3
Enter array elements:
10
32
12
Sum of array values are: 54
Please check the above codes and let me know any issues. Thank you. all the best.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.