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

(java) Trying to write a program computing overall course grade... So far cant g

ID: 3668592 • Letter: #

Question

(java) Trying to write a program computing overall course grade... So far cant get the total points on a section to display. Heres the code.

import java.util.*;
public class Grades {
public static void main (String[] args) {
introduction();
getWeights();
System.out.println("Using weights of 50 20 30 ");
homework();

}
  
public static void introduction () {
System.out.println("This program accepts your homework scores and");
System.out.println("scores from two exams as input and computes");
System.out.println("your grade in the course.");
}
public static void getWeights () {
Scanner console = new Scanner(System.in);

System.out.print("Homework and Exam 1 weights? ");
int homeworkWeight = console.nextInt();
int exam1Weight = console.nextInt();
  

}
public static void homework () {
System.out.println("Homework:");
Scanner console = new Scanner(System.in);
System.out.print("Number of assignments? ");
int numAssignments = console.nextInt();
  
System.out.print("Assignment 1 score and max? ");
int assignment1score = console.nextInt();
int assignment1max = console.nextInt();
  
System.out.print("Assignment 2 score and max? ");
int assignment2score = console.nextInt();
int assignment2max = console.nextInt();
  
System.out.print("Assignment 3 score and max? ");
int assignment3score = console.nextInt();
int assignment3max = console.nextInt();
  
System.out.print("Sections attended? ");
int sections = console.nextInt();
  
System.out.print("Total points =");
int totalpointshw=(assignment1score+assignment2score+assignment3score);
  
  
}

}

The part im having trouble with is at the very end, to display/calculate the total of the points inputted by the user for the assignments. (Also need to do it with the max points)

Explanation / Answer

Required solution:

package com.blazent.webapp.test;


import java.util.*;

public class Grades
{
   public static void main( String[] args )
   {
       introduction();
       getWeights();
       System.out.println( "Using weights of 50 20 30 " );
       homework();

   }

   public static void introduction()
   {
       System.out.println( "This program accepts your homework scores and" );
       System.out.println( "scores from two exams as input and computes" );
       System.out.println( "your grade in the course." );
   }

   public static void getWeights()
   {
       Scanner console = new Scanner( System.in );
       System.out.print( "Homework and Exam 1 weights? " );
       int homeworkWeight = console.nextInt();
       int exam1Weight = console.nextInt();

   }

   public static void homework()
   {
       System.out.println( "Homework:" );
       Scanner console = new Scanner( System.in );
       System.out.print( "Number of assignments? " );
       int numAssignments = console.nextInt();
       int assignmentScore, assignmentMax, totalScoreObtained = 0, sectionAttended, numSections = 0, totalScore = 0;
       for( int i = 1; i <= numAssignments; i++ )
       {
           System.out.print( "Assignment" + i + " score and max? " );
           assignmentScore = console.nextInt();
           totalScoreObtained += assignmentScore;
           assignmentMax = console.nextInt();
           totalScore += assignmentMax;
           System.out.print( "Sections attended? " );
           sectionAttended = console.nextInt();
           numSections += sectionAttended;
       }
       System.out.println( "Total Score Obtained:" + totalScoreObtained );
       System.out.println( "MAX Score:" + totalScore );
       System.out.println( "Total Sections Attended:" + numSections );
       console.close();

   }
}

Sample output:

Homework:
Number of assignments? 3
Assignment1 score and max? 15
20
Sections attended? 3
Assignment2 score and max? 20
25
Sections attended? 3
Assignment3 score and max? 22
25
Sections attended? 5
Total Score Obtained:57
MAX Score:70
Total Sections Attended:11