//Kenny Cruz
//CET 3640
//Lab2 Class
public class NumberStats {
private int counter = 0;
private float sum;
private float average;
private float current = 0;
private float largest;
private float smallest;
private float firstNumber;
private float lastNumber;
private float remainder=0;
private int fpoint = 0;
private int ints = 0;
public void setNewNum(float current){
this.current = current;
remainder= current%2;
if(counter == 0)
{
firstNumber = current;
largest = current;
smallest = current;
}
if ((remainder==0) || (remainder==1)) {
ints++;
}
else
{
fpoint++;
}
if (current > largest) {
largest = current;
}
else if (current < smallest) {
smallest = current;
}
sum = sum + current;
lastNumber = current;
counter++;
}
public float getFirstNumber(){
return this.firstNumber;
}
public float getLastNumber(){
return this.lastNumber;
}
public int getCounter(){
return this.counter;
}
public int getInts(){
return this.ints;
}
public int getfPoint(){
return this.fpoint;
}
public float getLargest(){
return this.largest;
}
public float getSmallest(){
return this.smallest;
}
public float getSum(){
return this.sum;
}
public float getAverage(){
average = sum / counter;
return this.average;
}
}
B) Application code NumberStatsApp.java
import java.util.Scanner;
public class NumberStatsApp {
public static void main(String[] args) {
int opt = 0;
float num = 0;
Scanner input = new Scanner(System.in);
NumberStats classNumberStats = new NumberStats();
do {
System.out.println(“MENU”);
System.out.println(“Select…”);
System.out.println(” (1) Enter A Number”);
System.out.println(” (2) Exit”);
opt = input.nextInt();
if(opt == 1)
{
System.out.println(“Enter a number:”);
num = input.nextFloat();
classNumberStats.setNewNum(num);
}
else if(opt == 2)
opt = ‘n’;
else
System.out.println(“Try again\n”);
} while (opt != ‘n’);
System.out.println(“The first number is: “+ classNumberStats.getFirstNumber());
System.out.println(“The last number is: ” + classNumberStats.getLastNumber());
System.out.println(“Total numbers are: ” + classNumberStats.getCounter());
System.out.println(“Total number of integers is: ” + classNumberStats.getInts());
System.out.println(“Total number of floating points is: ” + classNumberStats.getfPoint());
System.out.println(“The minimum value is: ” + classNumberStats.getSmallest());
System.out.println(“The maximum value is: ” + classNumberStats.getLargest());
System.out.println(“The Sum of the Integers are: ” + classNumberStats.getSum());
System.out.println(“The Average is: ” + classNumberStats.getAverage());
}
}