Lab #3

 
//David Ash
//Lab 3

public class numberstat {

    private int number;
	private int firstnum;
	private int lastnum;

	private int count;
	private double  average;
	private int max;

	private int min;
	private int totalnum;
	private int numamount;


	public int getnum() { 
		return number;
	}

	public int getfirstnum() {
		return firstnum;
	} 


	public int getlastnum() {
		return lastnum;

	}
	public int getcount() {
		return count++;

	}
	public double getaverage() {
		return average;

	}
	public int getmax() {
		return maximum;

	}
	public int getmin() {
		return min;

	}
	public int gettotalnum() {
		return totalnum;

	}
	public int getnumamount() {
		return numamount;

	}
}


import java.util.Scanner;
public class trainstats {

	public static void main(String[] args) {

		int number = 0;

		int numamount = 0;
		int totalnum = 0;

	    int firstnum = number;
	    int lastnum = number %10;
	    int count =1;

	    double  average;
	    int max = 0;
	    int min = 1;


		Scanner input = new Scanner( System.in);

	System.out.println("Enter a series of numbers: ");

	System.out.println("Enter a 0 when you are finished:  ");

	do {
	number=input.nextInt();

	numamount ++;
	totalnum = totalnum + number;

	if (number > max)

	{
		max=number;
		count=0;

	}
	if(number==max)
		count++;


	else if (number < min) {  min=number; 	count=1; } 
        if(number==min){ count ++; } 	
        if (count ==1){ firstnum = number; } 	
        else if (count >0) { lastnum = number;
	}
	}


while (number !=0);

average=(double)totalnum/(numamount-1);
System.out.printf("The average is %.2f\n", average);

System.out.println("the total number you entered: " + numamount);

System.out.println("The sum for the numbers you entered is " + totalnum);
System.out.println("The maximum number is\t: " + max);
System.out.println("The minimum number is: " + min);


System.out.printf("the first digit you entered is " + firstnum);
System.out.printf("\nThe last digit you entered is  " + lastnum); 

	numberstat stats1 = new numberstat();
	numberstat stats2 = new numberstat();
	numberstat stats3 = new numberstat();
	numberstat stats4 = new numberstat();
	numberstat stats5 = new numberstat();
	numberstat stats6 = new numberstat();
	numberstat stats7 = new numberstat();
	numberstat stats8 = new numberstat();

	System.out.printf("%s\n" , stats1.getmax());

	System.out.printf("%s\n" , stats2.getmin());
	System.out.printf("%s\n" , stats3.getaverage());

	System.out.printf("%s\n" , stats4.getlastnum());
	System.out.printf("%s\n" , stats5.getfirstnum());

	System.out.printf("%s\n" , stats6.getnum());
	System.out.printf("%s\n" , stats7.getnumamount());

	System.out.printf("%s\n" , stats8.gettotalnum());

}
}

Hello world!

This is the first post on your Learning Blog. Edit or delete it, then start blogging!

NOTE: Remember to add appropriateĀ CategoryĀ and TagsĀ to your posts. This will help your professors and other visitors find the content they are looking for. The Category “Coursework” and the Tags “OpenLab” and “City Tech” have already been applied to this post. Feel free to make changes!