WEEK 2 Completed C++ program with Comments in the code 20% Lab Report 20% (Templ
ID: 3536840 • Letter: W
Question
WEEK 2
Completed C++ program with Comments in the code 20%
Lab Report 20% (Template is in Doc Sharing)
No Syntax (Complier) error 20%
No Runtime (system) error 20%
No Logical Error (correct results) 20%
---------------------------------------------------------------------------------------------------------------------------------------------------------
WEEK 1
Points distribution:
Completed C++ program with Comments in the code 20%
Lab Report 20% (Template is in Doc Sharing)
No Syntax (Complier) error 20%
No Runtime (system) error 20%
No Logical Error (correct results) 20%
Explanation / Answer
5.5 :
Sorting double numbers:
import java.util.Scanner;
/**
This is a test class for DataSet.
*/
public class DataSetTester
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Please enter three numbers:");
double num1 = in.nextDouble();
double num2 = in.nextDouble();
double num3 = in.nextDouble();
DataSet s = new DataSet(num1, num2, num3);
System.out.println("The inputs in sorted order are: "
+ s.getSmallestNumber() + " "
+ s.getMiddleNumber() + " "
+ s.getLargestNumber());
}
}
public class DataSet
{
private double a;
private double b;
private double c;
public DataSet(double num1, double num2, double num3)
{
a = num1;
b = num2;
c = num3;
}
public double getLargestNumber()
{
{
if(a > b && a > c)
return a;
else if(b > a && b > c)
return b;
else if(c > a && c > b)
return c;
}
return getLargestNumber();
}
public double getSmallestNumber()
{
{
if(a < b && a < c)
return a;
else if(b < a && b < c)
return b;
else if(c < a && c < b)
return c;
}
return getSmallestNumber();
}
public double getMiddleNumber()
{
{
if(a > b && a < c)
return a;
else if(b > a && b < c)
return b;
else if(c > a && c < b)
return c;
}
return getMiddleNumber();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.