Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,396 members, 7,808,423 topics. Date: Thursday, 25 April 2024 at 11:44 AM

Need A Java Programmer To Put Be Through On A JAVA ASSIGNMENT - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Need A Java Programmer To Put Be Through On A JAVA ASSIGNMENT (4333 Views)

Help Java Programmers: Need Help With A Java Assignment / Java Proramers:java Assignment: Can Someone Help Provide A Solution To This / Functional Programming For Java Programmer Scala Or Clojure? (2) (3) (4)

(1) (Reply) (Go Down)

Need A Java Programmer To Put Be Through On A JAVA ASSIGNMENT by buster(m): 8:26am On Dec 11, 2014
Good day

Am running a particular java code and am having issues compiling as i get an erro such as could not find Class and main class. I have created the class and the main class using java Netbeans but i still cant compile it. Am so sure my code is correct but its compiling it thats giving me the issue

Below is the Assignment and code for the solution. Please can someone guide me on how to compile in other not to get the error message

The following class StatCalc defines a series of methods for computing statistics for a group of numbers.

/*

* An object of class StatCalc can be used to compute several simple statistics

* for a set of numbers. Numbers are entered into the dataset using

* the enter(double) method. Methods are provided to return the following

* statistics for the set of numbers that have been entered: The number

* of items, the sum of the items, the average, and the standard deviation

*/

public class StatCalc {



private int count; // Number of numbers that have been entered.

private double sum; // The sum of all the items that have been entered.

private double squareSum; // The sum of the squares of all the items.



/**

* Add a number to the dataset. The statistics will be computed for all

* the numbers that have been added to the dataset using this method.

*/

public void enter(double num) {

count++;

sum += num;

squareSum += num*num;

}



/**

* Return the number of items that have been entered into the dataset.

*/

public int getCount() {

return count;

}



/**

* Return the sum of all the numbers that have been entered.

*/

public double getSum() {

return sum;

}



/**

* Return the average of all the items that have been entered.

* The return value is Double.NaN if no numbers have been entered.

*/

public double getMean() {

return sum / count;

}



/**

* Return the standard deviation of all the items that have been entered.

* The return value is Double.NaN if no numbers have been entered.

*/

public double getStandardDeviation() {

double mean = getMean();

return Math.sqrt( squareSum/count - mean*mean );

}

} // end class StatCalc



Using the StatCalc class, write a program that calculates and then displays as output to the console, the following statistics against the set of numbers given below.

Statistics that must be calculated:

Count – Quantity of numbers in the data set.
Mean – The mean or average of the numbers in the data set.
Standard Deviation – The measure of variance (or dispersion) from the mean.
The set of numbers that you must use is as follows:

5 7 12 23 3 2 8 14 10 5 9 13

You must create a program with a main method that defines the StatCalc class and instantiates an instance of StatCalc called myStatCalc. Your program should instantiate the instance of the StatCalc using a statement similar to the following:

StatCalc myStatCalc;

myStatCalc = new StatCalc();

MY SOLUTION

Class File
/*
An object of class StatCalc can be used to compute several simple statistics
for a set of numbers. Numbers are entered into the dataset using
the enter(double) method. Methods are provided to return the following
statistics for the set of numbers that have been entered: The number
of items, the sum of the items, the average, the standard deviation,
the maximum, and the minimum.
*/

public class StatCalc {

private int count; // Number of numbers that have been entered.
private double sum; // The sum of all the items that have been entered.
private double squareSum; // The sum of the squares of all the items.
private double max = Double.NEGATIVE_INFINITY; // Largest item seen.
private double min = Double.POSITIVE_INFINITY; // Smallest item seen.

public void enter(double num) {
// Add the number to the dataset.
count++;
sum += num;
squareSum += num*num;
if (num > max)
max = num;
if (num < min)
min = num;
}

public int getCount() {
// Return number of items that have been entered.
return count;
}

public double getSum() {
// Return the sum of all the items that have been entered.
return sum;
}

public double getMean() {
// Return average of all the items that have been entered.
// Value is Double.NaN if count == 0.
return sum / count;
}

public double getStandardDeviation() {
// Return standard deviation of all the items that have been entered.
// Value will be Double.NaN if count == 0.
double mean = getMean();
return Math.sqrt( squareSum/count - mean*mean );
}

public double getMin() {
// Return the smallest item that has been entered.
// Value will be infinity if no items have been entered.
return min;
}

public double getMax() {
// Return the largest item that has been entered.
// Value will be -infinity if no items have been entered.
return max;
}

} // end class StatCalc

Main Class

/*
Computes and display several statistics for a set of non-zero
numbers entered by the user. (Input ends when user enters 0.)
This program uses StatCalc.java.0
*/

public class SimpleStats {

public static void main(String[] args) {

StatCalc calc; // Computes stats for numbers entered by user.
calc = new StatCalc();

double item; // One number entered by the user.

TextIO.putln("Enter your numbers. Enter 0 to end."wink;
TextIO.putln();

do {
TextIO.put("? "wink;
item = TextIO.getlnDouble();
if (item != 0)
calc.enter(item);
} while ( item != 0 );

TextIO.putln("\nStatistics about your calc:\n"wink;
TextIO.putln(" Count: " + calc.getCount());
TextIO.putln(" Sum: " + calc.getSum());
TextIO.putln(" Minimum: " + calc.getMin());
TextIO.putln(" Maximum: " + calc.getMax());
TextIO.putln(" Average: " + calc.getMean());
TextIO.putln(" Standard Deviation: " + calc.getStandardDeviation());

} // end main()

} // end SimpleStats
Re: Need A Java Programmer To Put Be Through On A JAVA ASSIGNMENT by Knownpal(m): 2:44pm On Dec 12, 2014
Hello, its like you are calling a class you did not import. (TextIO).
Re: Need A Java Programmer To Put Be Through On A JAVA ASSIGNMENT by davroca16(m): 6:13am On Dec 13, 2014
Simple download the TextIO.java source file am attaching to this comment, and place it in the same package where your main class is. **for net bean, using you ide, copy and paste the source code in the folder where other source code are located or in the same package where other source file are located**

I just ran the code, and it worked.

Re: Need A Java Programmer To Put Be Through On A JAVA ASSIGNMENT by davroca16(m): 6:44am On Dec 13, 2014
Here is where I found the source code.

The TextIO.java class, is not a standard java class which you can just find in java SE API most times, when you get problems like this, urv got to surf the net, to see if your missing files can be found there.

Btw, that's a cool program you've got there.
Re: Need A Java Programmer To Put Be Through On A JAVA ASSIGNMENT by davroca16(m): 3:46pm On Dec 13, 2014
buster:
Good day

Am running a particular java code and am having issues compiling as i get an erro such as could not find Class and main class. I have created the class and the main class using java Netbeans but i still cant compile it. Am so sure my code is correct but its compiling it thats giving me the issue

Below is the Assignment and code for the solution. Please can someone guide me on how to compile in other not to get the error message

The following class StatCalc defines a series of methods for computing statistics for a group of numbers.

/*

* An object of class StatCalc can be used to compute several simple statistics

* for a set of numbers. Numbers are entered into the dataset using

* the enter(double) method. Methods are provided to return the following

* statistics for the set of numbers that have been entered: The number

* of items, the sum of the items, the average, and the standard deviation

*/

public class StatCalc {



private int count; // Number of numbers that have been entered.

private double sum; // The sum of all the items that have been entered.

private double squareSum; // The sum of the squares of all the items.



/**

* Add a number to the dataset. The statistics will be computed for all

* the numbers that have been added to the dataset using this method.

*/

public void enter(double num) {

count++;

sum += num;

squareSum += num*num;

}



/**

* Return the number of items that have been entered into the dataset.

*/

public int getCount() {

return count;

}



/**

* Return the sum of all the numbers that have been entered.

*/

public double getSum() {

return sum;

}



/**

* Return the average of all the items that have been entered.

* The return value is Double.NaN if no numbers have been entered.

*/

public double getMean() {

return sum / count;

}



/**

* Return the standard deviation of all the items that have been entered.

* The return value is Double.NaN if no numbers have been entered.

*/

public double getStandardDeviation() {

double mean = getMean();

return Math.sqrt( squareSum/count - mean*mean );

}

} // end class StatCalc



Using the StatCalc class, write a program that calculates and then displays as output to the console, the following statistics against the set of numbers given below.

Statistics that must be calculated:

Count – Quantity of numbers in the data set.
Mean – The mean or average of the numbers in the data set.
Standard Deviation – The measure of variance (or dispersion) from the mean.
The set of numbers that you must use is as follows:

5 7 12 23 3 2 8 14 10 5 9 13

You must create a program with a main method that defines the StatCalc class and instantiates an instance of StatCalc called myStatCalc. Your program should instantiate the instance of the StatCalc using a statement similar to the following:

StatCalc myStatCalc;

myStatCalc = new StatCalc();

MY SOLUTION

Class File
/*
An object of class StatCalc can be used to compute several simple statistics
for a set of numbers. Numbers are entered into the dataset using
the enter(double) method. Methods are provided to return the following
statistics for the set of numbers that have been entered: The number
of items, the sum of the items, the average, the standard deviation,
the maximum, and the minimum.
*/

public class StatCalc {

private int count; // Number of numbers that have been entered.
private double sum; // The sum of all the items that have been entered.
private double squareSum; // The sum of the squares of all the items.
private double max = Double.NEGATIVE_INFINITY; // Largest item seen.
private double min = Double.POSITIVE_INFINITY; // Smallest item seen.

public void enter(double num) {
// Add the number to the dataset.
count++;
sum += num;
squareSum += num*num;
if (num > max)
max = num;
if (num < min)
min = num;
}

public int getCount() {
// Return number of items that have been entered.
return count;
}

public double getSum() {
// Return the sum of all the items that have been entered.
return sum;
}

public double getMean() {
// Return average of all the items that have been entered.
// Value is Double.NaN if count == 0.
return sum / count;
}

public double getStandardDeviation() {
// Return standard deviation of all the items that have been entered.
// Value will be Double.NaN if count == 0.
double mean = getMean();
return Math.sqrt( squareSum/count - mean*mean );
}

public double getMin() {
// Return the smallest item that has been entered.
// Value will be infinity if no items have been entered.
return min;
}

public double getMax() {
// Return the largest item that has been entered.
// Value will be -infinity if no items have been entered.
return max;
}

} // end class StatCalc

Main Class

/*
Computes and display several statistics for a set of non-zero
numbers entered by the user. (Input ends when user enters 0.)
This program uses StatCalc.java.0
*/

public class SimpleStats {

public static void main(String[] args) {

StatCalc calc; // Computes stats for numbers entered by user.
calc = new StatCalc();

double item; // One number entered by the user.

TextIO.putln("Enter your numbers. Enter 0 to end."wink;
TextIO.putln();

do {
TextIO.put("? "wink;
item = TextIO.getlnDouble();
if (item != 0)
calc.enter(item);
} while ( item != 0 );

TextIO.putln("\nStatistics about your calc:\n"wink;
TextIO.putln(" Count: " + calc.getCount());
TextIO.putln(" Sum: " + calc.getSum());
TextIO.putln(" Minimum: " + calc.getMin());
TextIO.putln(" Maximum: " + calc.getMax());
TextIO.putln(" Average: " + calc.getMean());
TextIO.putln(" Standard Deviation: " + calc.getStandardDeviation());

} // end main()

} // end SimpleStats

I hope it helped smiley
Re: Need A Java Programmer To Put Be Through On A JAVA ASSIGNMENT by ahmmyreal(m): 11:44pm On Dec 15, 2014
public class StatCalc {
private int count;
private double sum;
private double squareSum;
private double min = Double.POSITIVE_INFINITY;
private double max = Double.NEGATIVE_INFINITY;

public void enter(double num){
count++;
sum += num;
squareSum += num * num;
if (num < min)
min = num;
if (num > max)
max = num;
}

public int getCount(){
return count;
}

public double getSum(){
return sum;
}

public double getMean(){
return sum / count;
}

public double getMin(){
return min;
}

public double getMax(){
return max;
}

public double getStandardDeviation(){
return Math.sqrt(squareSum/count - getMean() * getMean());
}
}
Re: Need A Java Programmer To Put Be Through On A JAVA ASSIGNMENT by ahmmyreal(m): 11:45pm On Dec 15, 2014
import java.util.Scanner;

public class SimpleStats{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
StatCalc calc = new StatCalc();

double num;
do{
System.out.print("Enter your number and press enter or 0 to end: " );
num = input.nextDouble();
if (num != 0)
calc.enter(num);
} while(num != 0);

System.out.printf("\nStatistics about your calc\n" );
System.out.printf("Count: %d\n", 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.printf("Standard Deviation: %.2f\n", calc.getStandardDeviation());
}
}
Re: Need A Java Programmer To Put Be Through On A JAVA ASSIGNMENT by lawbestt: 10:35am On May 16, 2018
i need this too wink
Re: Need A Java Programmer To Put Be Through On A JAVA ASSIGNMENT by Dalexicographer(m): 11:48am On May 16, 2018
lawbestt:
i need this too wink
Yo wanna learn java programming??
Re: Need A Java Programmer To Put Be Through On A JAVA ASSIGNMENT by universe123: 9:11pm On May 16, 2018
Dalexicographer:
Yo wanna learn java programming??
are u good with java?
Re: Need A Java Programmer To Put Be Through On A JAVA ASSIGNMENT by Dalexicographer(m): 7:44am On May 17, 2018
universe123:
are u good with java?
Im an enthusiast... Yet to be a pro though wink

(1) (Reply)

I Will Officially Quit Visiting This Section / For Young And Basic Web Development HOP IN / How Can Java Take Care Of My (future) Needs?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 63
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.