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 */
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.