Lab 2

Description:

Well for this java lab, I had to understand objects that was use for the program to know which are needed to put in the numbers for it to work. I also had to use the scanner protocol due to the fact that for me to actually enter the numbers while the program is being executed, scanner will help allow me to have programming rights to enter any number I want. It can be either positive or negative numbers, as long a scanner is mention in the code, it will be allowed. But that is for the second part of the lab. I needed to used the constructor to help allow the program to get the declare objects that was within the private so that i can use the set and get methods

/**
 *
 * @AntonScott
 *
 */

package edu.cuny.citytech.CET3640.f13.Lab2;

public class NumberStats {

private double firstnum;
private double lastnum;
private double min;
private double max;
private double sum;
private double avg;

private double countnum;
private double intnum;
private double floatnum;
private double FloorValue;
private double CeilingValue;

public NumberStats()
{
firstnum = 0;
lastnum = 0;
min = 0;
max = 0;
sum = 0;
intnum = 0;
floatnum = 0;
countnum = 0;
}

public void setNumberStats(double newnumber, int count)
{

this.lastnum = newnumber;
sum += newnumber;

if (count == 1) {

min = newnumber;
max = newnumber;
firstnum = newnumber;
}

if (min >= newnumber) {
min = newnumber;
}

if (max <= newnumber) {
max = newnumber;
}

this.avg = sum/count;
this.countnum = count;

this.FloorValue = Math.floor(newnumber);
this.CeilingValue = Math.ceil(newnumber);

if (FloorValue <= newnumber && CeilingValue <= newnumber )
{
intnum++;
}

else
{
floatnum++;
}

}
public double getfirstnum() {
return firstnum;
}

public double getlastnum() {
return lastnum;
}

public double getmin() {
return min;
}

public double getmax() {
return max;
}

public double getavg() {
return avg;
}

public double getcountnum(){
return countnum;
}

public double getintnum(){
return intnum;
}

public double getfloatnum(){
return floatnum;
}
public double getFloorValue(){
return FloorValue;
}

public double getCeilingValue(){
return CeilingValue;
}

public void displayStatistics()
{

System.out.println(“The First number entered is: ” + getfirstnum());
System.out.println(“The Last number entered is: ” + getlastnum());
System.out.println(“The count of numbers entered is: ” + getcountnum());
System.out.println(“The count of integers is: ” + getintnum());
System.out.println(“The count of floating points is: ” + getfloatnum());
System.out.println(“The Minimum number entered is: ” + getmin());
System.out.println(“The Maximum number entered is: ” + getmax());
System.out.println(“The Average number is: ” + getavg());

}
}

package edu.cuny.citytech.CET3640.f13.Lab2;

import java.util.Scanner;
public class NumberStatsTest {

public static int count = 1;
private static Scanner scanner;

public static void main(String[] args) {
// TODO Auto-generated method stub

NumberStats StatsTest = new NumberStats();
scanner = new Scanner(System.in);

do
{

System.out.println(“Please enter a number, to exit the computations enter the number ‘Exit’:”);
StatsTest.setNumberStats(scanner.nextDouble(), count);

if(scanner.hasNext(“Exit”))
{
System.out.println(“Exiting the computations, displaying final statistics: “);
StatsTest.displayStatistics();

break;
}

count++;
}
while(true);

}
}Lab 2 part 1Lab 2 part 2

Leave a Reply

Your email address will not be published. Required fields are marked *