Lab 2

Lab Description

I developed a program that ask the user to enter a group of numbers that calculate the average and total sum. Also, the program will recognize the max and min numbers. I created two classes that will work together to execute the program.

Source Code

package Lab_2;
import java.lang.Math;
public class Numberstatistics {
	String hello;
	double nums;
	double firstnum;
	double lastnum;
	double max;
	double min;
	double sum;
	double countnumber = 0;
	int count = 0;
	int HIGHcount = 0;
	int LOWcount = 0;
	int intcountnumber = 0;

	public Numberstatistics (String intro){
		hello=intro;
	}
	public String gethello(){
		return hello;
	}
	public void display(){
		System.out.printf("%s\n", gethello());
	}

	public void setNumberStatsNumbers(double nums)
	{
		this.nums = nums;

		HIGHcount = (int) Math.ceil(nums);
		LOWcount = (int) Math.floor(nums);

		firstnum = nums;
		sum += nums;
		count++;

		if (nums < HIGHcount && nums > LOWcount)
		{
			countnumber++;
		} 
		else
		{
			intcountnumber++;
		}

		if (nums > max)
		{
			max= nums;
		} 

		if (nums < min)
		{
			min = nums;
		} 

		if ( count == 1 )
		{
			firstnum = nums;
			max = nums;
			min = nums;
		}
	}

	public double getfirstnum()
	{
		return this.firstnum;
	}

	public double getcountnumber()
	{
		return this.countnumber;
	}

	public int getintcountnumber()
	{
		return this.intcountnumber;
	}

	public double getlastnum()
	{
		return this.lastnum;
	}

	public double getmax()
	{
		return this.max;
	}

	public double getmin()
	{
		return this.min;
	}

	public double getsum()
	{
		return this.sum;
	}

	public double getcount()
	{
		return this.count;
	}

	void count(double z)
	{
		z = getcount();
		System.out.printf("the amount of numbers stored: %f\n", z);
	}
	void count(double y, double x)
	{
		y = getintcountnumber();
		System.out.printf("the amount of numbers stored: %f\n", y);
		x = getcountnumber();
		System.out.printf("the amount of numbers stored: %f\n",x);
	}

	public void NumbersList ()
	{
		System.out.printf("first interger: %f\n",getfirstnum());
		System.out.printf("last interger: %f\n",getlastnum());
		System.out.printf("min interger: %f\n", getmin());
		System.out.printf("max interger: %f\n", getmax());
		System.out.printf("total numbers : %f\n", getsum());
		System.out.printf("avg : %f\n", getsum()/getcount());
	}
}
package Lab_2;
import java.util.Scanner;
import Lab_2.Numberstatistics;
public class NumberstatsMain {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Numberstatistics nmbrstats = new Numberstatistics("Adam's Forbes Second Program");
		float NUM;
		Scanner adam = new Scanner( System.in );

		nmbrstats.display();
		System.out.print("Enter '1' to run the program or '0' to exit: \n");
		NUM = adam.nextInt();

		if(NUM == 1){

		boolean end = true;

		while(end)
		{
		{System.out.println("Enter a group of numbers:\n");

		String num1 = adam.next();
		char num3 = num1.charAt(0);

		if(num3 == 'n' || num3 == 'N' ){
		    end = false;
		}
		else{
		float numbers = Float.parseFloat(num1);
		nmbrstats.setNumberStatsNumbers(numbers);
		nmbrstats.NumbersList();
		nmbrstats.count(numbers);
		nmbrstats.count(numbers, numbers);
		}
		}}}
		else 
		{
		System.out.println("End");

		}
		}

	}

Screenshot

LR

Leave a Reply

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