Question

In: Computer Science

Methods – Compute Grade Please write a complete Java program, given the following information about (a...

Methods – Compute Grade

Please write a complete Java program, given the following information about (a few lines of code in) main: projectAverage = getAverage(”Project”); // returns average of 2 grades testAverage = getAverage(”Test”); // returns average of 2 grades displayGrade(projectAverage, testAverage); // test are 70% & projects 30%

Solutions

Expert Solution

Solution for the above question are as follows -

Code :

import java.util.Scanner;
public class Main
{
// calculate average and return
public static int getAverage(int a[]) {
int sum = 0;
for(int i = 0; i < a.length; i++)
{
sum += a[i];
}
return (sum / a.length);
}
// print the grades Average
public static void displayGrade(int p , int t) {
System.out.println("Project Grades Average : " + p + "%");
System.out.println("Test Grades Average : " + t + "%");
}
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
// get input from user
int projects[] = new int[2];
int tests[] = new int[2];
// get the project data
System.out.println("Enter 2 grades of projects:");
for(int i = 0; i < 2; i++)
{
projects[i] = s.nextInt();
}
// get the test data
System.out.println("Enter 2 grades of tests:");
for(int i = 0; i < 2; i++)
{
tests[i] = s.nextInt();
}
// calculate projects average
int projectAverage = getAverage(projects);
// calculate tests average
int testAverage = getAverage(tests);
// display grades of projects and tests
displayGrade(projectAverage, testAverage);
}
}

Code Screen Shot :

Output :


Related Solutions

Please write a java program that has the following methods in it: (preferably in order)   a...
Please write a java program that has the following methods in it: (preferably in order)   a method to read in the name of a University and pass it back a method to read in the number of students enrolled and pass it back a method to calculate the tuition as 20000 times the number of students and pass it back a method print the name of the University, the number of students enrolled, and the total tuition Design Notes: The...
write a Java program Write a program to assign a letter grade according to the following...
write a Java program Write a program to assign a letter grade according to the following scheme: A: total score >= 90 B: 80 <= total score < 90 C: 70 <= total score < 80 D: 60 <= total score < 70 F: total score < 60 Output - the student's total score (float, 2 decimals) and letter grade Testing - test your program with the following input data: test1 = 95; test2 = 80; final = 90; assignments...
• 1. Write a java program using methods to find the information about a account holder...
• 1. Write a java program using methods to find the information about a account holder at bank. d) Perform the functionalities(Deposit, Withdraw and print) until the user selects to stop.
• 1. Write a java program using methods to find the information about a account holder...
• 1. Write a java program using methods to find the information about a account holder at bank. b) Show different functionalities of a bank account (Deposit, Withdrawal, Print)
• 1. Write a java program using methods to find the information about a account holder...
• 1. Write a java program using methods to find the information about a account holder at bank. c) For every transaction make sure make use of his account balance.
Write a complete program in java that will do the following:
Write a complete program in java that will do the following:Sports:             Baseball, Basketball, Football, Hockey, Volleyball, WaterpoloPlayers:           9, 5, 11, 6, 6, 7Store the data in appropriate arraysProvide an output of sports and player numbers. See below:Baseball          9 players.Basketball       5 players.Football           11 players.Hockey            6 players.Volleyball        6 players.Waterpolo       7 players.Use Scanner to provide the number of friends you have for a team sport.Provide an output of suggested sports for your group of friends. If your...
DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1....
DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1. Write an abstract Java class called Shape which has only one abstract method named getArea(); 2. Write a Java class called Rectangle which extends Shape and has two data membersnamed width and height.The Rectangle should have all get/set methods, the toString method, and implement the abstract method getArea()it gets from class Shape. 3. Write the driver code tat tests the classes and methods you...
URGENT!!! DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps:...
URGENT!!! DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1. Write an abstract Java class called Shape which has only one abstract method named getArea(); 2. Write a Java class called Rectangle which extends Shape and has two data membersnamed width and height.The Rectangle should have all get/set methods, the toString method, and implement the abstract method getArea()it gets from class Shape. 3. Write the driver code tat tests the classes and methods...
Please show screenshot outputs and fully functional code for the Java program. Write the following methods...
Please show screenshot outputs and fully functional code for the Java program. Write the following methods to   1) read the content of an array of 5 doubles public static double[] readingArray() 2) find and print:the smallest element in an array of 5 double public static void smallest(double [] array) 3) find and print:the largest element in an array of 5 doubles pubic static void largest (double [] array) In the main method - invoke readingArray and enter the following numbers...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT