Question

// 2. Practice debugging this program. It has approximately 22 compiler errors, 1 logic error and...

// 2. Practice debugging this program. It has approximately 22 compiler

errors, 1 logic error and

//1 usability error. Identify them all.

import java.util.scanner;

//This program finds the average of three input values.

public class Arithmeticx

{

public static void main( String [] args )

// declare variables

double number1, number2, number3;

// input data

scanner in = newscanner( );

System.out.print( "Number 1? " );

System.out.print( "Number 2? " );

System.out.print( "Number 3? " );

number 1 = in.nextDouble;

number 2 = in.nextDouble;

number 3 = in.nextDouble;

// calculate average

average = num1 + num2 + num3 / 3;

// print results

system.out.print( Number1 + ", " + Number2 + " & " + Number3 );

system.out.println( " averages to " + average );

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: Hey dear student finds the solution of your query if you have any doubt feel free to ask. Thanks!!

//Identify errors

import java.util.scanner;//compiler error no package this name should be Scanner

//This program finds the average of three input values.

public class Arithmeticx
{
public static void main( String [] args )//error
//curly braces missing
// declare variables

double number1, number2, number3;

// input data

scanner in = newscanner( );//compiler error There is no package this name scanner should be Scanner,argument mssing(System.in)

System.out.print( "Number 1? " );//compier error extra space before double comma starting and extra after double comma

System.out.print( "Number 2? " );//compiler error extra space before double comma starting and extra after double comma

System.out.print( "Number 3? " );//compiler error extra space before double comma starting and extra after double comma

number 1 = in.nextDouble;//2compiler error variable name error ,() missing nextDouble() is method

number 2 = in.nextDouble;//2compiler error variable name error ,() missing nextDouble() is method

number 3 = in.nextDouble;//2compiler error variable name error ,() missing nextDouble() is method

// calculate average

average = num1 + num2 + num3 / 3;//logical error there is no declared vraiables in this cope

// print results

system.out.print( Number1 + ", " + Number2 + " & " + Number3 );//5 compiler errors should be System,extra space before variable,case sensitive variable name should be Number1
//2nd variable name ,3rd vraiable name,extra space after 3rd variable name

system.out.println( " averages to " + average );//2 compiler errors syntax error(System),extra space before average and after average
//2compiler error2
//braces is missing

Modified code:

import java.util.Scanner;

//This program finds the average of three input values.

class Main

{

public static void main( String [] args )
{
// declare variables

double number1, number2, number3,average;

// input data

Scanner in = new Scanner(System.in);

System.out.print("Number 1? ");

System.out.print("Number 2? ");

System.out.print("Number 3? ");

number1 = in.nextDouble();

number2 = in.nextDouble();

number3 = in.nextDouble();

// calculate average

average = number1 + number2 + number3;

// print results

System.out.print(number1 + ", " + number2 + " & " + number3);

System.out.println("averages to " + average);
}
}
//2 compiler errors

Add a comment
Know the answer?
Add Answer to:
// 2. Practice debugging this program. It has approximately 22 compiler errors, 1 logic error and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • DEBUGGING. JAVA. Identify the errors in the following. There are no logical errors in this one...

    DEBUGGING. JAVA. Identify the errors in the following. There are no logical errors in this one just syntax issues. //start import java.util.Scanner; public class NumbersDemo {    public static void main (String args[])    {       Scanner kb = new Scanner(System.in);       int num1, num2;             System.out.print("Enter an integer >> ");       num1 = kb.nextInt();       System.out.print("Enter another integer >> ");       num2 = kb.nextDouble();       displayTwiceTheNumber(num1);       displayNumberPlusFive(num1);       displayNumberSquared(num1)       displayTwiceTheNumber(num2);       displayNumberPlusFive(num2);       displayNumberSquared(num2);    }   ...

  • The files provided in the code editor to the right contain syntax and/or logic errors. In...

    The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. // DebugFive2.java // Decides if two numbers are evenly divisible import java.util.Scanner; public class DebugFive2 { public static void main(String args[]) { int num; int num2; Scanner input = new Scanner(System.in); System.out.print("Enter a number "); num = input.nextInteger() System.out.print("Enter another number ");...

  • Java debugging in eclipse package edu.ilstu; import java.util.Scanner; /** * The following class has four independent...

    Java debugging in eclipse package edu.ilstu; import java.util.Scanner; /** * The following class has four independent debugging * problems. Solve one at a time, uncommenting the next * one only after the previous problem is working correctly. */ public class FindTheErrors { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); /* * Problem 1 Debugging * * This problem is to read in your first name, * last name, and current year and display them in *...

  • Correct the five syntax, run-time or logic errors that are found in the CountAndAverageNumbers.java file. Link...

    Correct the five syntax, run-time or logic errors that are found in the CountAndAverageNumbers.java file. Link to the file: CountAndAverageNumbers.javaPreview the document. Make sure you include comments in your code where errors were corrected. If you do not flag each error with a comment, points will be deducted. Upload the corrected .java file here. The output of the corrected file looks like the following: Debug4Output.PNG This program reads an unspecified number of integers, determines how many positive and negative values...

  • - Part 1 – 4 Debugging Exercises – there are things wrong – either logic or...

    - Part 1 – 4 Debugging Exercises – there are things wrong – either logic or syntax errors.  Correct the pseudocode and one Java program. Add the corrected code in BOLD and change the corrected color to RED.   Debugging 4:  Add the missing code in bold and red. import java.util.Scanner; public class Airline {             public static void main(String args[])             {                         Scanner s = new Scanner(System.in);                         String passengerName = ""                              String ageString = ""                           int passengerAge = 0                         System.out.println("Enter passenger's name: ");                         passengerName  =...

  • Debug the following java code so that it will have given out put at the bottom....

    Debug the following java code so that it will have given out put at the bottom. Make sure to fix all syntax and logical errors. import java.util.Scanner; public class Graphs { // draws 5 histograms public void drawHistograms() Scanner input = new Scanner( System.in ); int number1 = 0; // first number int number2 = 0; // second number int number3 = 0; // third number int number4 = 0; // fourth number int number5 = 0; // fifth number...

  • Need help debugging. first class seems fine. second class is shooting an error on s =...

    Need help debugging. first class seems fine. second class is shooting an error on s = super.getString(prompt);   third class is giving me an error in the while loop where int num = console.getInt("Enter an integer:"); //-------------------------------------------------------------------------- import java.util.Scanner; public class Console {     private Scanner sc;     boolean isValid;     int i;     double d;        public Console()     {         sc = new Scanner(System.in);     }     public String getString(String prompt)     {         System.out.print(prompt);         return sc.nextLine();...

  • I need help debugging this Java program. I am getting this error message: Exception in thread...

    I need help debugging this Java program. I am getting this error message: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at population.Population.main(Population.java:85) I am not able to run this program. ------------------------------------------------------------------- import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; /* Linked list node*/ class node { long data; long year; String country; node next; node(String c,long y,long d) { country=c; year=y; data = d; next = null; } } public class Population { private static node head; public static void push(String...

  • IN JAVA: Write a program that displays a menu as shown in the sample run. You...

    IN JAVA: Write a program that displays a menu as shown in the sample run. You can enter 1, 2, 3, or 4 for choosing an addition, subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter 5 to exit the system. Each test generates two random single-digit numbers to form a question for addition, subtraction, multiplication, or division. For a subtraction such as number1 – number2, number1 is...

  • The part in bold is giving me an error. Ther error is that I cant convert...

    The part in bold is giving me an error. Ther error is that I cant convert an int to a boolean. The program asks the user to input two integer values and determines whether the first is divisible (without a remainder) by the second import java.util.Scanner; public class CheckDivisible { int isDivisible(int dividend, int divisor) { if(dividend % divisor == 0) return 1; else return 0; } public static void main(String[] args) { int dividend = 0; int divisor =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT