15
answers
0
watching
597
views
12 Oct 2018

4. In this question, you will be shown a snippet of code. You will then be shown the output from either the compiler or the Java virtual machine and be asked what the error is and how to fix it. In each case, your answer should include the line number of the problem, a one or two sentence explanation as to why the issue occurs, and a specific fix for the problem. Your fix should mention the exact line or lines of code you'd add/change/delete. Total for this question (5 parts): (15 points) (a) Consider the following class: import java.util.Scanner; public class Hockeystandings //This method should calculate the percentage of games in which the team lost. public static double computePercentageLosses (int numwins, int numLosses) return numLosses/ (numwins + numLosses) * 100; public static void main(String[] args) { Scanner reader - new Scanner (System.in); System.out.println("Enter the number of wins for the Maple Leafs"); int numLeafwins = reader.nextInt (); System.out.println("Enter the number of losses for the Maple Leafs"); int numLeaflosses-reader.nextInt (); System.out.println("Enter the number of wins for the Canadiens"); int numCanadienswins – reader.nextInt (); System.out.println("Enter the number of losses for the Canadiens"); int numCanadienslosses = reader.nextInt (); double mapleLeafs Record - computePercentage Losses (numLeafwins, numLeaf Losses); double canadienskecord - computePercentage Losses (numCanadienswins, nuCanadienslos305): if (canadiens Record > mapleleafsRecord) { System.out.println("Of course the Leafs did worse."); else { System.out.println("Wow, that hasn't happened for a long time!"); The point of the program is to ask the user to enter numbers representing the wins and losses of the Maple Leafs and Canadiens in a season. The code compiles successfully and when you run the program, you enter the values: 2 80 40 42 into the keyboard. You expect that the program will output the message Of course the Leafs did worse since they had fewer wins. However, to your surprise, the output of the program is: Wow, that hasn't happened for a long time! Why is this the case and fix the error?

For unlimited access to Homework Help, a Homework+ subscription is required.

Unlock all answers

Get 1 free homework help answer.
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Collen Von
Collen VonLv2
15 Oct 2018
Already have an account? Log in

Related questions

Related Documents

Weekly leaderboard

Start filling in the gaps now
Log in