In: Computer Science
Write a Java program to compute your final grade for the course.
Assume the following (you can hard-code these values in your program).
Assignments are worth 30%
Labs are worth 40%
Mid-term is worth 15%
Final is worth 15%
Ask for the grades in each category.
Store them in a double variable.
Print out the final percentage grade.
For example,
Final Grade Calculation
Enter percentage grades in the following order.
Assignments, Labs, Mid-term test, Final Exam: 95 88 86 92
The final grade is 90
2. Create a Project and a Class called “AgeCheck”
Write a Java program to ask the user for their name and age. Use a string variable for the name and an int variable for the age. Output a message using the name and whether the user is old enough to purchase alcohol (21 years old).
For example,
Age Checker
Enter your name: Steve
Enter your age: 19
Hello, Steve, you are only 19 and not old enough to purchase
alcohol.
Age Checker
Enter your name: Jane
Enter your age: 25
Hello, Jane, you are 25 and old enough to purchase alcohol.
Program 1:
import java.util.Scanner; //scanner class importing
public class FinalGrade
{
public static void main(String args[]) //main function
{
double assignments,labs,mid,final_exam; //variables for storing grades which are double data type
Scanner input=new Scanner(System.in);
//creating scanner class input object
System.out.println("Enter Percentage Grade of
Assignments");
assignments=input.nextDouble();
//asking user to enter
assignment grades
System.out.println("Enter Percentage Grade of
Labs");
labs=input.nextDouble();
//askin user to enter labs grades
System.out.println("Enter Percentage Grade of Mid-term
Test");
mid=input.nextDouble();
//asking user to enter mid term test
grades
System.out.println("Enter Percentage Grade of Final
Exam");
final_exam=input.nextDouble();
//asking user to enter final_Exam grades
double
final_grade=(0.3*assignments)+(0.4*labs)+(0.15*mid)+(0.15*final_exam);
//finally computing final grade by multiplying each
grade with their worth % here 30% can be written as 30/100 i.e
0.3
System.out.println("The Final Grade is " +
(int)(final_grade)); //at the end printing the final grade by
casting it to int
}
}
Program 2:
import java.util.Scanner; //scanner class importing
public class AgeChecker
{
public static void main(String args[]) //main function
{
Scanner input=new Scanner(System.in); //scanner class input object creation
System.out.println("Age Checker");
String name; //name variable which is string data type
int age; //age variable which is int data type
System.out.print("Enter Your Name : ");
name=input.nextLine(); //asking user to enter the name
System.out.print("Enter Your Name : ");
age=input.nextInt(); //asking user to enter the age
if (age>=21) //if age greater than or equal to 21 print below message
System.out.println("Hello, "+name+", you are "+ age +" and old enough to purchase alcohol.\n");
else //else print not old enough to purchase alcohol
System.out.println("Hello, "+name+", you are
only "+ age +" and not old enough to purchase alcohol.\n");
}
}
Program 1 Code and Output Screenshots:
Program 2 Code and Output Screenshots :
Note : if you have any queries please post a comment thanks a lot..always available to help you...