Does this Java program need to be two separate Files -
hi taking java class , first assignment involving object oriented programming. getting issues simplecalc portion , wondering if work should 2 separate files or if missing component allows statcalc part , simplecalc part speak 1 another. please keep in mind new java might need spelled out bit more have seen on stack on flow in past @ times, however, appreciate thank in advance. here code:
package tutorial; /* * object of class statcalc can used compute several simple statistics * set of numbers. numbers entered dataset using * enter(double) method. methods provided return following * statistics set of numbers have been entered: number * of items, sum of items, average, standard deviation, * maximum, , minimum. */ public class statcalc { private int count; // number of numbers have been entered. private double sum; // sum of items have been entered. private double squaresum; // sum of squares of items. private double max = double.negative_infinity; private double min = double.positive_infinity; /** * add number dataset. statistics computed * numbers have been added dataset using method. */ public void enter(double num) { count++; sum += num; squaresum += num*num; if (count == 1){ max = num; min = num; } else { if (num > max) max = num; if (num < min) min = num; } } /** * return number of items have been entered dataset. */ public int getcount() { return count; } /** * return sum of numbers have been entered. */ public double getsum() { return sum; } /** * return average of items have been entered. * return value double.nan if no numbers have been entered. */ public double getmean() { return sum / count; } /** * return standard deviation of items have been entered. * return value double.nan if no numbers have been entered. */ public double getstandarddeviation() { double mean = getmean(); return math.sqrt( squaresum/count - mean*mean ); } public double getmin(){ return min; } public double getmax(){ return max; } }// end class statcalc public class simplecalc { public static void main(string[]args){ scanner in = new scanner(system.in); simplecalc calc; calc = new simplecalc(); double item; system.out.println("enter numbers here. enter 0 stop."); system.out.println(); do{ system.out.print("? "); item = in.nextdouble(); if (item != 0) calc.enter(item); }while (item != 0); system.out.println("\nstatistics calc:\n"); system.out.println(count: "+calc.getcount"()); system.out.println(sum: "+calc.getsum"()); system.out.println("minimum: "+calc.getmin()); system.out.println("maximum: "+calc.getmax()); system.out.println("average: "+calc.getmean()); system.out.println("standard deviation: "+calc.getstandarddeviation()); }// end main }//end simplecalc
in java public class must in file same name class. since have public class named statcalc filename must statcalc.java. second class public therefore must in own file.
Comments
Post a Comment