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

Hello so I am trying to do the following outputs for this program but I am not g

ID: 3685090 • Letter: H

Question

Hello so I am trying to do the following outputs for this program but I am not getting it. I am having trouble making it so that when I give a value for the homework section I need the two inputs(nextInt) to be togther with a space in between. I am also having trouble adding if statements. Can someone please fix my code to output the following three outputs? it would mean a lot!

Expected Output:

The following logs of execution indicate the exact format of the output that you should reproduce. Your
program's output should match these samples exactly when the same input is typed. Please note that there are
some blank lines between sections of output and that some lines of output are indented by four spaces. Also
note that input values typed by the user appear on the same line as the corresponding prompt message.

First log of execution (user input underlined)
This program accepts your homework and exam
scores as input, and computes your grade in
the course or indicates what grade you need
to earn on the final exam.

Homework:
   What is its weight (0-100)? 50
   How many homework assignments were there? 3
   Homework 1 score and max score: 14 15
   Homework 2 score and max score: 18 20
   Homework 3 score and max score: 19 25
   Weighted homework score: 42.5

Midterm exam:
   What is its weight (0-100)? 20
   Exam score: 81
   Was there a curve? (1 for yes, 2 for no) 2
   Weighted exam score: 16.2

Final exam:
   Have you taken the final exam yet? (1 for yes, 2 for no) 2
   What is its weight (0-100)? 30
   What percentage would you like to earn in the course? 80
   You need a score of 71.0 on the final exam.

Second log of execution (user input underlined)
This program accepts your homework and exam
scores as input, and computes your grade in
the course or indicates what grade you need
to earn on the final exam.

Homework:
   What is its weight (0-100)? 40
   How many homework assignments were there? 4
   Homework 1 score and max score: 21 30
   Homework 2 score and max score: 11 20
   Homework 3 score and max score: 28 50
   Homework 4 score and max score: 5 10
   Weighted homework score: 23.64

Midterm exam:
   What is its weight (0-100)? 30
   Exam score: 95
   Was there a curve? (1 for yes, 2 for no) 1
   How much was the curve? 10
   Weighted exam score: 30.0

Final exam:
   Have you taken the final exam yet? (1 for yes, 2 for no) 1
   What is its weight (0-100)? 30
   Exam score: 63
   Was there a curve? (1 for yes, 2 for no) 1
   How much was the curve? 5
   Weighted exam score: 20.4
   Your course grade is 74.04

Third log of execution (user input underlined)
This program accepts your homework and exam
scores as input, and computes your grade in
the course or indicates what grade you need
to earn on the final exam.

Homework:
   What is its weight (0-100)? 50
   How many homework assignments were there? 2
   Homework 1 score and max score: 10 50
   Homework 2 score and max score: 12 25
   Weighted homework score: 14.67

Midterm exam:
   What is its weight (0-100)? 25
   Exam score: 56
   Was there a curve? (1 for yes, 2 for no) 2
   Weighted exam score: 14.0

Final exam:
   Have you taken the final exam yet? (1 for yes, 2 for no) 2
   What is its weight (0-100)? 25
   What percentage would you like to earn in the course? 90
   You need a score of 245.33 on the final exam.
   Sorry, it is impossible to achieve this percentage.
   The highest percentage you can get is 53.67.

My Code:

import java.util.Scanner;

public class Finals12
{
   public static void main(String[] args)
   {
   printWelcomeMessage();
     
   Scanner s= new Scanner(System.in);
     
   System.out.println(" Homework: ");
   double hw = getWeightedHomeworkScore(s);

   System.out.println(" Midterm exam: ");
   double midterm = getWeightedExamScore(s);
     
   System.out.println(" Final exam: ");
   doFinalExam(s, hw, midterm);
   }
       private static void printWelcomeMessage()
       {
           System.out.println("This program accepts your homework "
               + "and exam scores as input, and computes your grade in"
               +" the course or indicates what grade you need"
               +" to earn on the final exam.");          
       }
       private static void doFinalExam(Scanner s, double hw, double midterm)
       {
           int taken;
           double escore2;
          
           System.out.print("Have you taken the final exam yet? (1 for yes, 2 for no) ");
           taken=s.nextInt();
               System.out.println();
           if(taken==1)
           {
               System.out.println("What is its weight? ");
               int weight=s.nextInt();
               System.out.print("Exam Score: ");
               int escore = s.nextInt();
               System.out.println("Was there a curve? (1 for yes, 2 for no) ");
               int curvevalue=s.nextInt();
               if(curvevalue==1)
               {
                   System.out.println("How much was the curve? ");
                   int curve=s.nextInt();
                   escore2=((escore+curve)*weight)/100;
                   System.out.println("Weighted exam score"+escore2);
               }
               else if (curvevalue==2)
               {
                   escore2=(escore*weight)/100;
                   System.out.println("Weighted exam score" +escore2);
               }
           }
           else if(taken==2)
               {
               escore2=0;
               double coursegrade;
               int hwscore = 0;
               coursegrade=hwscore +escore+escore2;
               System.out.println("course grade is: " + coursegrade);
               }      
       }
       private static double getWeightedExamScore(Scanner s)
       {
           int curvevalue;
           double escore,curve,escore1;
          
           System.out.print("What is its weight (0-100)? " );
           double weight = s.nextInt();
          
               System.out.println();
          
           System.out.print("Exam Score: ");
           escore= s.nextInt();
          
               System.out.println();
          
           System.out.print("Was there a curve? (1 for yes, 2 for no) ");
           curvevalue=s.nextInt();
           System.out.println();
                   if(curvevalue==1)
                   {
                       System.out.print("How much was the curve? ");
                       curve=s.nextInt();
                       escore=((escore+curve)*weight)/100;
                           System.out.println();
                       System.out.println("The weighted exam score: " +escore);
                   }
                   else if(curvevalue==2)
                   {
                       escore=(escore*weight)/100;
                       System.out.println("Weighted exam: " + escore);              
                   }
       return 0;
       }
       private static double getWeightedHomeworkScore(Scanner s)
       {
           double weight, numAssign,score1,maxscore1,sum = 0;
           double hwscore,summax,sumscore;

           System.out.print(" What is its weight (0-100)? ");
           weight= s.nextInt();
          
           System.out.print(" How many homework assignments were there? ");
           numAssign=s.nextInt();
          
               for(int i=1; i<=numAssign;i++)
               {
                   System.out.print(" Homework "+i+" score and maxscore: ");
                   int score11=s.nextInt(),maxscore11=s.nextInt();
                   sum+=(score11/maxscore11)*(weight/100);
               }
               System.out.println(" Weighted homework score is" + sum);
               return 0;
       }          
}

Explanation / Answer

HelloWorld.java

import java.io.*;
import java.util.Scanner;

class Input {
   public int readInt(String message) throws IOException {
      try {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         System.out.print(message);
         int i = Integer.parseInt(br.readLine());
         return i;
      } catch (IOException e) {
         System.out.println("Error: Input Output Error! Abort.");
         System.exit(1);
      }//error handling
      return 1;
   }//readInt

   public int readInt() throws IOException {
      return readInt("Number: ");
   }

    public String readLine(String message) throws IOException {
      try {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         System.out.print(message);
         String i = br.readLine();
         return i;
      } catch (IOException e) {
         System.out.println("Error: Input Output Error! Abort.");
         System.exit(1);
      }//error handling
      return "Error!";
   }//readLine

   public String readLine() throws IOException {
      return readLine("Word: ");
   }

    public double readDouble(String message) throws IOException {
      try {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         System.out.print(message);
         double i = Double.parseDouble(br.readLine());
         return i;
      } catch (IOException e) {
         System.out.println("Error: Input Output Error! Abort.");
         System.exit(1);
      }//error handling
      return -1.;
   }//readDouble

   public double readDouble() throws IOException {
      return readDouble("Number: ");
   }

   public String readWord() {
      return readWord("Word: ");
   }

   public String readWord(String message) {
      System.out.print(message);
      Scanner console = new Scanner(System.in);
      return console.next();
   }
}

public class Grimshaw_Grades {
   public static final String CURVED = " Was there a curve?";
   public static final String TAKEN = " Have you taken the final exam yet?";
   public static final String WEIGHT = " What is its weight (0-100)";
   public static final String CURVE = " How much was the curve";
   public static final String DESIRED_SCORE = " What percentage would you like to earn in the course";

   public static void printIntro() {
      System.out.println("This program accepts your homework and exam");
      System.out.println("scores as input, and computes your grade in");
      System.out.println("the course or indicates what grade you need");
      System.out.println("to earn on the final exam.");
      System.out.println();
   }

   public static double printWeightedScore(String catagory, double totalScore, int maxScore, double weight) {
      double score = totalScore/maxScore;
      score *= weight;
      System.out.printf(" Weighted %s score: %.2f ", catagory, score);
      return score;
   }

   public static double getHomework(Input console) throws IOException{
      double totalScore = 0., weight = 0.;
      int maxScore = 0, assnNum = 0;
      System.out.println("Homework:");
      weight = get(WEIGHT, console);
      assnNum = console.readInt(" How many homework assignments were there? ");
      for (int i = 1; i <= assnNum; i++) {
         Scanner tmp = new Scanner(System.in);
         System.out.print(" Homework "+i+" score and max score: ");
         totalScore += tmp.nextDouble();
         maxScore += tmp.nextInt();
      }
      return printWeightedScore("homework", totalScore, maxScore, weight);
   }

   public static double get(String question, Input console)throws IOException {
      return console.readDouble(question+"? ");
   }

   public static boolean isIt(String question, Input console) throws IOException{
      return console.readInt(question+" (1 for yes, 2 for no) ") == 1 ? true : false;
   }

   public static double getExam(Input console) throws IOException{
      double weight = 0., score = 0., curve = 0.;
      int maxScore = 100;
      weight = get(WEIGHT, console);
      score = console.readDouble(" Exam score: ");
      if (isIt(CURVED, console))
         curve = get(CURVE, console);
      return printWeightedScore("exam", (score+curve>=maxScore ? 100 : score+curve), maxScore, weight);
   }

   public static double getMidterm(Input console) throws IOException {
      System.out.println("Midterm exam:");
      return getExam(console);
   }

   public static double getFinal(double grade, Input console) throws IOException{
      double weight = 0., endGrade = 0., ans;
      int maxScore = 100;
      System.out.println("Final exam:");
      if (isIt(TAKEN, console))
         return getExam(console);
      weight = get(WEIGHT, console);
      endGrade = get(DESIRED_SCORE, console);
      double weightedScore = endGrade-grade;
      ans = weightedScore/weight;
      ans *= 100;
      System.out.printf(" You need a score of %.2f on the final exam. ", ans);
      if (ans > 100.) {
         System.out.println(" Sorry, it is impossible to achieve this percentage.");
         System.out.printf(" The highest percentage you can get is %.2f ", (grade+weight));
      }
      System.exit(0);
      return weight;
   }

   public static double calculateGrade() throws IOException{
      double grade = 0.;
      Input console = new Input();
      grade += getHomework(console);
      grade += getMidterm(console);
      grade += getFinal(grade, console);
      return grade;
   }

   public static void main(String[] args) throws IOException {
      printIntro();
      double grade = calculateGrade();
      System.out.printf(" Your course grade is %.2f ", grade);
   }
}

sample output

This program accepts your homework and exam                                                                                                                 
scores as input, and computes your grade in                                                                                                                 
the course or indicates what grade you need                                                                                                                 
to earn on the final exam.                                                                                                                                  
                                                                                                                                                            
Homework:                                                                                                                                                   
        What is its weight (0-100)? 50                                                                                                                      
        How many homework assignments were there? 3                                                                                                         
        Homework 1 score and max score: 14 15                                                                                                               
        Homework 2 score and max score: 18 20                                                                                                               
        Homework 3 score and max score: 19 25                                                                                                               
        Weighted homework score: 42.50                                                                                                                      
                                                                                                                                                            
Midterm exam:                                                                                                                                               
        What is its weight (0-100)? 20                                                                                                                      
        Exam score: 81                                                                                                                                      
        Was there a curve? (1 for yes, 2 for no) 2                                                                                                          
        Weighted exam score: 16.20                                                                                                                          
                                                                                                                                                            
Final exam:                                                                                                                                                 
        Have you taken the final exam yet? (1 for yes, 2 for no) 2                                                                                          
        What is its weight (0-100)? 30                                                                                                                      
        What percentage would you like to earn in the course? 80                                                                                            
                                                                                                                                                            
        You need a score of 71.00 on the final exam.                                                                                                        

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote