Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise 1 : Write a Java program that determines a student’s grade. The program

ID: 3881261 • 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

Exercise 1:

Solution:
import java.util.*;
public class Exercise1
{
public static void main(String[] args)
{
showGrade();
}

static void showGrade(){

float quiz_score, mid_score,final_score,avg;
Scanner sc=new Scanner(System.in);
System.out.print("Quiz score:");
quiz_score=sc.nextFloat();
System.out.print("Mid-term score:");
mid_score=sc.nextFloat();
System.out.print("Final score:");
final_score=sc.nextFloat();
avg=(quiz_score+mid_score+final_score)/3;

if(avg>=90) System.out.println("Your grade A.");
else if((avg>=70) && (avg<90)) System.out.println("Your grade B.");
else if((avg>=50) && (avg<70)) System.out.println("Your grade C.");
else if(avg<50) System.out.println("Your grade F.");
else System.out.println("Invalid");


}

}

Exercise 2:

Solution:

import java.util.*;
public class Exercise2
{
public static void main(String[] args)
{
calculateSale();
}

static void calculateSale(){

float unitprice=0f;
int quantity=0;
float revenue=0f;
float discount_rate=0f, discount_amount=0f;

Scanner sc=new Scanner(System.in);
System.out.print("Enter unit price:");
unitprice=sc.nextFloat();
System.out.print("Enter quantity:");
quantity=sc.nextInt();

if(quantity<100)
revenue=unitprice*quantity;
else if(quantity>=100 && quantity<=120)
{
discount_rate=(float)10/100;
revenue=unitprice*quantity;
discount_amount=revenue*discount_rate;
revenue-=discount_amount;
}

else if(quantity>120)
{
discount_rate=(float)15/100;
revenue=unitprice*quantity;
discount_amount=revenue*discount_rate;
revenue-=discount_amount;
}

System.out.println("The revenue from sale:"+revenue+"$");
System.out.println("After discount:"+discount_amount+"$("+discount_rate*100+"%)");


}

}

Exercise 3:

Solution:


import java.io.*;


public class Exercise3
{
public static void main(String[] args)
{
   detectKey();
}

static void detectKey(){

char key=' ';
System.out.print("Press a number key:");
try{
key = (char)System.in.read();
}catch(IOException e){};
switch (key)
{
case '0': System.out.println("You pressed 0."); break;
case '1': System.out.println("You pressed 1."); break;
case '2': System.out.println("You pressed 2."); break;
case '3': System.out.println("You pressed 3."); break;
case '4': System.out.println("You pressed 4."); break;
case '5': System.out.println("You pressed 5."); break;
case '6': System.out.println("You pressed 6."); break;
case '7': System.out.println("You pressed 7."); break;
case '8': System.out.println("You pressed 8."); break;
case '9': System.out.println("You pressed 9."); break;
default: System.out.println("Not allowed!"); break;

      }

}

}

Exercise 4:

Solution:

public class Exercise4 {
public static void main(String[] args) {    
int my_array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int sum = 0;

for (int i : my_array)
    sum += i;
System.out.println("The sum is " + sum);
}
}

Sorry for that remaing quetion are unsolved because of chegg policy is solved only first Four quetion .