Many Errors Calculating Mean / Variance And Standard Deviation
Apr 28, 2014
It may be (it is highly likely) possible that I have royally stuffed this up. I am attempting to write a program that asks a user for a file name, gets the number of entries and if there is more than one entry calculate the mean, variance and standard deviation. This is my code so far:
/* Calculate contains methods that determines the number of data entries in a file, and calculates the mean, variance and standard deviation of this set
*
************************************************************************/
import java.util.Scanner;
import java.io.*;
public class Calculate {
public static void main(String[] args) throws IOException {
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
[Code] ....
The errors I am getting are:
Calculate.java:67: error: ';' expected
mean += mean/String filename;
^
Calculate.java:67: error: not a statement
mean += mean/String filename;
for standard deviation my output is not rounded to the 10's place, how can I make it round to the 10's place. Here is my code.
import java.util.*; public class chapter7 { public static final int Max_Number_Scores = 100; public static int fillArray(double[] scores) { System.out.print("You entered "); for (int i = 0; i < scores.length; i++) { System.out.print(scores[i] + " ");
Basically I'm trying to compute the standard deviation for a set of numbers and I'm using previously know data to compute this. The data I'm working with is here (note all of this is fake as its for an assignment):
Next this is the code that I know is producing the error:
/** * Pass in original data from files, and pass in computed grades as arraylist. this returns all of the standard deviations to be printed */ public static ArrayList calcStandDev(String data1[], ArrayList<Double> grades, ArrayList<Integer> averages) { double standDev = 0; int j = 0; //gets rid of first element in string array, makes processing MUCH easier String[] data = Arrays.copyOfRange(data1, 1, data1.length);
[Code] ....
Look for the line with all the ***'s, it is producing the "java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer".
The reason I dont undersand why its producing this error is because temp.get(i) should be a integer - averages.get(i) (is type double), I do believe automatic up casting is present here making them both a double then I multiply it by itself producing a double? I dont understand where the casing is occurring. And just incase you want the formula I'm using for standard deviation here it is:
I am trying to create a method that calculates the standard deviation of array. What I want to be able to do is something like this
package standardDevaitionAndMean; public class StandardDeviationTest { public static void main (String[] args) { int [] array = {12,12,12,12,12,12,12}; standardDev = array.StandardDevation(); System.out.print(standardDev); } }
With something like this
package standardDevaitionAndMean; public class StandardDeviation {double mean1; double standDev; public double Mean(double ... array) { for(int i=0; i<array.length;i++)
[Code]...
So basically I want to be able to make an array in a class and be able to calculate its standard deviation with my method in my other class. I know the code I wrote is terrible but I just wanted to show what I am trying to do. I am kind of shaky on how arrays operate
The purpose of this program is to import via keyboard Numbers.txt and calculate the mean and standard deviation to Results.txt.I am able to get the mean calculate but when I open the Results.txt the standard deviation is 0. I don't know what is wrong with my code, but I believe it has something to do with the scanner being close. Here is the error message i receive after inputting Numbers.txt.
java.lang.IllegalStateException: Scanner closed at java.util.Scanner.ensureOpen(Unknown Source) at java.util.Scanner.hasNext(Unknown Source) at StatsDemo.main(StatsDemo.java:48) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)
Java Code:
import java.text.DecimalFormat; //for number formatting import java.util.Scanner; //for keyboard input import java.io.*; //for using files public class StatsDemo { public static void main(String [] args) throws IOException
I have to write sorting algorithm for numbers given on standard input(console) with following requirements:
The application must remember the distinction between double and integer numbers. This must be evident in the sorted output. Double type numbers are written using a period (.) to separate the fraction from the whole part.
The problem is I don't know how to efficiently distinct whether something is an int or double on standard input, to save them into 2 different arrays.
Only idea I've come to so far is to read each number as String and check if it has '.' character, to figure out if it's double and than convert it into right type and add it to correct array.
Also thought that maybe this would be achieveable using Pattern but how to do that?
I was wondering how Java knows where to Import classes from when we don't specify the whole directory path.
For example: import java.util.* Does It automatically search In both your current directory and the directory created during Installation that contains the standard library (wherever It may have been Installed) ?
I am facing NoClassDefFoundError with one of the java standard platform class (java.text.DigitList$1)
java.text.DigitList class is part of rt.jar so it should not create any issue as such.
I am using Java 1.6.0_06
StackTrace: Unhandled exception java.lang.NoClassDefFoundError: java/text/DigitList$1 at java.text.DigitList.shouldRoundUp(DigitList.java:4 11) at java.text.DigitList.round(DigitList.java:363) at java.text.DigitList.set(DigitList.java:351) at java.text.DigitList.set(DigitList.java:272) at java.text.DecimalFormat.format(DecimalFormat.java: 584) at java.text.DecimalFormat.format(DecimalFormat.java: 507) at java.text.NumberFormat.format(NumberFormat.java:26 9)
Code: package button; import javax.swing.*; import java.awt.event.*; public class Actions extends JFrame implements ActionListener { JPanel pnl = new JPanel();
[Code] ....
Errors: Exception in thread "main" java.lang.Error: Unresolved compilation problems: The type Actions must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent) event cannot be resolved event cannot be resolved at button.Actions.<init>(Actions.java:4) at button.Actions.main(Actions.java:9)
I'm using netbeans to develop an application to send and receive data via RS 232 standard. I can send data but I can't read it.what can I do? I have this message in the console: Underlying input stream returned zero bytes. (I must use also threads to have application in real time but I don't understand very well....
Allow the user to specify the number of terms (5 terms are shown) to use in the computation. Each time around the loop only one extra term should be added to the estimate for PI.
Alter your solution from part one so that the user is allowed to specify the precision required between 1 and 8 digits (i.e. the number of digits which are correct; e.g. to 5 digits PI is 3.14159), rather than the number of terms. The condition on the loop should be altered so that it continues until the required precision is obtained. Note that you need only submit this second version of the program (assuming you have it working).
I'm trying to calculate sin(x) without using Math.sin(x). The formula for sin(x) is: x - x^3/3! + x^5/5! ... I can't seem to get the coding for the alternating +/- right. Here's my program:
import java.util.Scanner; import java.lang.Math; class Sin { public static void main(String[] args) { Scanner kb = new Scanner(System.in); int n, c, fact = 1, count = 1; double x, sum = 0, sum_sin = 0, result;
I'm working on some exercises and I'm having some problems with a method. I want to create a method to calculate the Factorial of an int number. I already wrote code that asks the user to input an int number and it calculates the Factorial, and it works fine
i.e.: if I input 5 it outputs
5! = 120
as it should. Here's the code:
import java.util.Scanner; public class Factorial1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int number; int total = 1;
[Code] ....
Now I want to make a method to re-use this code in other programs and I wrote this program:
public class TestClass { public static void main(String[] args) { System.out.print(factorial(5)); } public static int factorial(int x) { int total = 0;
[Code] ....
But when I run this program it outputs 0 instead of 120. What is wrong with this code as it compiles just fine but doesn't work as intended.
I am trying to calculate factorials using BlueJ. All of my factorials calculate correctly, I am just having an issue with something the instructor asked of us. She asked us to force the loop to stop when the user inputs "Calculate the factorial of 0", and not give any print.
So far I have my for loop with the correct conditions, I am just really confused as to how to make an if statement to stop the code when the input is 0.
I am working on the first example in this java game programming book. I am having trouble understanding this basic concept. How does the delta variable work throughout this class? I know the syntax I just don't understand the concept fully.
what I'm missing to calculate the Total Payout that Payroll has given out to two employees. the professor states that we have to use "getTotalPayout" . It would have been easy to do "(employee1.getFinal() + employee2.getFinal())" but he use getTotalPayout.
public class Payroll { private String employeeId; private int hourlyrate, hoursworked; private int increaseHours = 10; private double TotalPayout;
I am supposed to be doing a class assignment that calculates the area of a triangle and outputs with JOptionPane. I was able to fix some errors, but it's uncovering more errors.Here is my code:
public class Area { public static void main (String [] args) { double a, b, c; //Input sides of triangle double x; //Perimeter of triangle double area; //Area of triangle StringTokenizer st;
I'm trying to make a method that creates objects of a parameterized type randomly, but also to store the hashCode of different objects created and if at any time the percentage of different objects is less than 50% throw an exception.
This last part is where I've gotten stuck. I have created a population property where I store the different hashCodes and update it in the method adding the new hashCode from the new object. But I don't know how to do for to know if the percentage of different objects is less than 50%.
package fp.tipos.apps; import java.util.ArrayList; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.List; import java.util.Random; public class FactoriaApps {
I'm currently in the process of creating a shopping cart simulation. The main GUI consists of two lists, one is a list of the inventory. (products stored within a .dat file which is automatically loaded upon launch) The other is blank and is to model my shopping basket. The idea is to be able to scan items from my inventory into the checkout basket. As this is happening i want a text field i created to dynamically update with the cost of all the items in the basket.
Below is the method for my scan button, which is supposed to perform the above :
public void actionPerformed(ActionEvent evt) { //Get the newly added list values. JList list = productList.getSelectedValuesList(); double totalAddedValue = 0.0; double oldCartValue = 0.0;
I am trying to do the following java assignment and every thing seems to work fine except when I put a number<4 or >10 it prints both "Invalid grade!"
"You didn't enter any data!" what I wanted is to print only "Invalid grade!" I tried to fix it but I couldn't.
Create a program that asks for results of exams and calculates the mean average of the grades. Grades are floating point numbers between 4 and 10. Program asks for grades until a negative number is typed. If user gives a grade other than a number between 4 and 10, the text "Invalid grade!" will be printed on screen and program asks for another grade. Finally the program prints the number of inputted grades and their mean average on screen as shown in the example print. If no grades were inputted, the notice "You did not input any grades." is the only thing printed on screen.
A double type variable is to be used to store the value of the average.
Program is written to a class called Average.
Example output
Program calculates the average of inputted grades.
Finish with a negative integer.
Input a grade (4-10): 5 Input a grade (4-10): 6,5 Input a grade (4-10): 7,5 Input a grade (4-10): 7 Input a grade (4-10): 0 Invalid grade! Input a grade (4-10): -4 4 grades inputted. Average of the grades: 6.5
Java Code:
import java.util.Scanner; public class apples { public static void main(String[] args) int inputNumber=0; int sum; int count; double average;
//program that calculates the circumference and area of a circle
import java.util.Scanner; public class circle{ public static void main(String[] args){ Scanner input= new Scanner( System.in); double r; //declares radius
[Code] .....
And here is what is displayed in the command prompt when I compile my code:
circle.java:17: error: cannot find symbol r.input.nextdouble();//entered the radius symbol: method nextdouble() location: variable input of type Scanner 1 error