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

I\'m getting errors with this java program. It is showing me errors for NumbersT

ID: 662546 • Letter: I

Question

I'm getting errors with this java program.

It is showing me errors for NumbersTest test = new NumbersTest(); part. Please fix.


import java.util.Scanner;

public class SmallestAndAverage {

   public static void main(String args[]) {

   Scanner sc = new Scanner(System.in);
   double x, y, z;

   System.out.print("Enter number 1 :");
   x = sc.nextDouble();
   System.out.print("Enter number 2 :");
   y = sc.nextDouble();
   System.out.print("Enter number 3 :");
   z = sc.nextDouble();

   NumbersTest test = new NumbersTest();
   double smallest = test.smallest(x, y, z);

   System.out.println("Smallest of " + x + ", " + y + ", " + z + " is: "+ smallest);

   double average = test.average(x, y, z);
  
   System.out.println("Average of " + x + ", " + y + ", " + z + " is: "+ average);
   }

   double smallest(double x, double y, double z) {
   double smallest = x;
   if (smallest > y)
   smallest = y;
   if (smallest > z)
   smallest = z;

   return smallest;
   }

   double average(double x, double y, double z) {
   double average;
average = (x + y + z) / 3;
   return average;
   }
}

Explanation / Answer

import java.util.Scanner;

public class SmallestAndAverage {

   public static void main(String args[]) {

       Scanner sc = new Scanner(System.in);
       double x, y, z;

       System.out.print("Enter number 1 :");
       x = sc.nextDouble();
       System.out.print("Enter number 2 :");
       y = sc.nextDouble();
       System.out.print("Enter number 3 :");
       z = sc.nextDouble();

       SmallestAndAverage test = new SmallestAndAverage();
       double smallest = test.smallest(x, y, z);

       System.out.println("Smallest of " + x + ", " + y + ", " + z + " is: "+ smallest);

       double average = test.average(x, y, z);
    
       System.out.println("Average of " + x + ", " + y + ", " + z + " is: "+ average);
   }

   double smallest(double x, double y, double z) {
       double smallest = x;
       if (smallest > y)
           smallest = y;
       if (smallest > z)
           smallest = z;

       return smallest;
   }

   double average(double x, double y, double z) {
       double average;
      average = (x + y + z) / 3;
       return average;
   }
}

/*You were using wrong classname NumbersTest to test the class. Replaced it with the right class SmallestAndAverage */

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