Te bolded statement in my code produces the output of 00


The bolded statement in my code produces the output of 0.0 / 0 if the totalScore / totalMax produce a double. I've been trying different solution for an hour, but nothing seems to work! Any help is appreciated, thank you.

  public static double homework(Scanner console) {

   System.out.println("Please enter information about your homework:");

   System.out.println("Weight? 0-100?");

   int weight = console.nextInt();

   System.out.println("Number of assignments?");

   int assign = console.nextInt();

   int score = 0;

   int max = 0;

   for (int i = 1; i <= assign; i++) {

     System.out.println("Assignment " + i + " score and max?");

     score = score + console.nextInt();

     max = max + console.nextInt();

   }

   System.out.println("How many section did you attend?");

   int attendance = console.nextInt();

   int sectionPointsEarned = attendance * 5;

   if (sectionPointsEarned > sectionPoints) {

     sectionPointsEarned = sectionPoints;

   }

   System.out.println("Section points = " + sectionPointsEarned + "/ " + sectionPoints);

   int totalScore = score + sectionPointsEarned;

   int totalMax = max + sectionPoints;

   if (totalScore > totalMax) {

     totalScore = totalMax;

   }

   System.out.println("Total points = " + totalScore + "/ " + totalMax);

   double weightedScore = ((weight * 1.0) * (totalScore / totalMax));

   weightedScore = Math.round(weightedScore * 10.0) / 10.0;

   System.out.println("Weighted score = " + weightedScore + " / " + weight);

   System.out.println();

   return weightedScore;

  }

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: Te bolded statement in my code produces the output of 00
Reference No:- TGS02644111

Now Priced at $20 (50% Discount)

Recommended (99%)

Rated (4.3/5)