Write a program that uses a Scanner object that asks for your name and your exam
ID: 3587423 • Letter: W
Question
Write a program that uses a Scanner object that asks for your name and your examen, assignment and lab marks. The examen counts for 40%, assignments 40% and labs 20%. The program computes your grade percentage. Test the program with three sets of data and include the results in this report. Do not concern yourself with controlling the display of the decimal point.
Sample output:
Please enter your name: ..
Please enter your examen mark: ..
Please enter your assignment mark: ..
Please enter your lab mark: ..
Final grade: ..%
Program:
Output (3 different outputs):
SOLUTIONS AND OUTPUTS NEED TO BE IN JAVA FORMAT. (PLEASE SHARE YOUR SCREENSHOTS AS WELL).
Explanation / Answer
import java.util.Scanner;
class Main{
public static void main(String[] args)
{
// declaring variables
double total;
int examen, assignment, lab;
String name;
Scanner sc = new Scanner(System.in);
// taking user input
System.out.print("Please enter your name: ");
name = sc.next();
System.out.print("Please enter your examen mark: ");
examen = sc.nextInt();
// 40% means we gotta do (40/100)
total = examen*(40/100.0);
System.out.print("Please enter your assignment mark: ");
assignment = sc.nextInt();
// 40% means we gotta do (40/100)
total += assignment*(40/100.0);
System.out.print("Please enter your lab mark: ");
lab = sc.nextInt();
// 20% means we gotta do (20/100)
total += lab*(20/100.0);
// printing output
System.out.print("Final grade: "+total+"%");
}
}
/* Sample Output
Please enter your name: Chegg
Please enter your examen mark: 80
Please enter your assignment mark: 70
Please enter your lab mark: 90
Final grade: 78.0%
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.