Java Code To Calculate Variance Of A Set Of Number?

May 2, 2014

I'm trying to write a java code that calculates the varince of a set of number and I wanted to know if this is the proper way to do it.

for (int i = 0; i <= (myArray.length - 1); i++){
variance = Math.pow((myArray[i] - average), 2);

}

View Replies


ADVERTISEMENT

Calculate Total Length Of N Number Of Bamboo Trees In M Number Of Seasons

Feb 20, 2014

In a forest, there are some bamboo trees .The length of each tree get doubled during winter and increases by one unit in summer , write a Java program to calculate the total length of n number of bamboo trees in M number of seasons. The season always starts with winter.

import java.util.Scanner;
public class Tree {
public static void main(String args[]) {
int length;
int season;

[Code] ....

View Replies View Related

Java Code That Asks User For Integer And Then Counts Down From That Number To 0

Oct 23, 2014

Write a java code that asks the user for an Integer and then counts down from that number to 0. Printing each number. For example:

Enter an Integer: 5 (enter) <--- user hits the enter key

5
4
3
2
1
0

import java.util.Scanner;
public class Exam{
public static void main(String args[]){
Scanner in = new Scanner(System.in);

View Replies View Related

Rational Number Class - Java Client Code For Testing

Mar 7, 2014

We are making a Rational Number class. After that we must create client code to test it out. The instructions-

•Create 3 instances of RationalNumber. Remember every time you say “new” you are creating an instance.
oOne of them should use the default constructor
oOne of them should use the constructor with one parameter
oOne of them should use the concstructor with two parameters.
•Print out the int and double value of each Rational Number
•Print out the sum (as a double) of all the numbers.
•Print out the sum (as an int) of all the numbers.

My rational number class :

public class RationalNumber{
private int numerator;
private int denominator;
public RationalNumber()
{
numerator =1;
denominator = 4;

[Code] .....

View Replies View Related

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;

[Code] ....

11 errors

Although I am sure there are many more to come.

View Replies View Related

Calculate If Code Matches

Jan 19, 2015

I have for example a letter code "EECC"...Now i want to have a good loop that checkes if the code typed in by the player matches or not? For example if player types CECE it should say it matches because C occurs 2 times and E occurs 2 times. This function must return than 4.If player types CEEE, it must return 3, because the code has 2 C en 2 E, player input is 1 C and 3 E, the last E is wrong.I've tried some loops with breaks but they all fail..

for example:

String test = "EFCC";
String test3 = "ECEC";
for(int i = 0; i < test.length(); i++){
matchFound = false;

[Code] .....

This returns 2 instead of 3.

View Replies View Related

Code Will Not Calculate Or Print Intersection And Difference Of Two Sets Using Arrays

Nov 19, 2014

As part of the instructions we are required to use loops and methods to solve to program this code. We are not allowed to use any set functions that are already built in java.The methods for intersection and difference MUST return int value.

import java.util.Scanner;
public class setPractice {
public static Scanner kbd;
public static final int MAXSIZE = 20;
public static void main(String[] args) {
kbd = new Scanner(System.in);

[code]...

View Replies View Related

Calculate SUM And AVERAGE Of ODD Number Digits Between 25 And 75

Jun 19, 2014

You are to write a parallel program that will receive a large array of unsorted integers containing digits from 0 to 99. The program will have to calculate the SUM and AVERAGE of ODD number digits between 25 and 75 (inclusive).

The user may specify the size or the array and the total processor that the machine has. The size of the array must be divisible by number of processor. Based on the given size, the computer will generate random integer numbers automatically to populate the array.

The program should display the status of the calculation for each processor. The result should be displayed after all calculations are completed.Error messages should be displayed appropriately

a) Write a sequential (non-parallel) program that will accomplish above task.
b) Write a concurrent (parallel) program that will produce the result of the above task.

View Replies View Related

Fibonacci Sequence - Calculate Nth Number

Apr 29, 2014

Write a recursive method that calculates the Nth number in the Fibonacci sequence. The first and second numbers in the sequence (the base cases) are both 1. After that, each subsequent number is the sum of the previous two. Stated a bit more formally:

fib(n)={1fib(n−1)+fib(n−2)n<2otherwise

For example, here is the first few numbers in the sequence:

1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Your fib method should be part of a class named Fibonacci. In addition to the fib method, the Fibonacci class should have a main method that calls fib(9). If the result doesn't equal 34, you should print an error message. Otherwise, it should print out a message saying that it was successful.

After writing your Fibonacci class, answer the following question: How many times is the fibonacci method called when calculating the 5th number in the sequence?

View Replies View Related

Calculate The Factors Of A Positive Integer Number

Mar 16, 2014

lines 7, 8, &12 "primes" are underline in red (prime cannot be resolved) is what pops up when i hover over the x's.

i don't get why that is.

package assignment7;
public class Exercise3
{
public static void main(String[] args)
{
Prime.setSize(1000);
for (int p = Primes.next(); p < 30; p = Primes.next())

[Code]...

View Replies View Related

Calculate Factors Of Positive Integer Number

Mar 17, 2014

Lines 7, 8, &12 "primes" are underline in red (prime cannot be resolved) is what pops up when i hover over the x's.

I don't get why that is.

Java Code :

public class Exercise3
{
public static void main(String[] args) {
Prime.setSize(1000);
for (int p = Primes.next(); p < 30; p = Primes.next()) {
int n = (int)Math.round(Math.pow(2,p)) - 1;
System.out.printf("%d 2^%d-1%d", p, p, n);
if (Primes.isPrime(n))

[Code] ....

View Replies View Related

Calculate Nth Fibonacci Number And Returns That To User

May 1, 2014

I have to create a program that calculates the nth Fibonacci number and returns that to the user. Fibonacci said his number sequence would describe the ideal breeding patterns of immortal rabbits. So, you are going to make this vision a reality.

First, take in a numeric value from the user and calculate that value in the fibonacci series. Next, find an image of a rabbit and display the image on a GUI (put the image as an icon on a label!) the number of times returned by the algorithm (Put all the aforementioned labels on one panel with FlowLayout!).

You need to remove the old images from the Panel. Probably the easiest way to do this is to create a whole new panel and remove the old one (hint: the remove method of JPanel should come in handy)

You could use an array of JLabels
You will need to create a new JLabel and add each member of the array to the panel
I should be able to scroll to see any images that are off screen

I am having difficultly on to making the array list for JLabel, and getting the Fibonacci sequence to show the pictures of rabbits. Below is my current code.

import java.awt.FlowLayout;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Rabbit extends JFrame

[Code] ....

View Replies View Related

Get Certain Number Of Items And Then Calculate How Much Every Item Cost

Jan 4, 2015

This is supposed to get a certain number of items, and then calculate how much every item costs. It adds up the sum of those prices and checks if it is over 150$, if it is, it returns true, if it's not, it returns false.

import java.util.*;
class Cust
{
public static boolean DelPay (int a) {
Scanner reader=new Scanner (System.in);
int b,s=0;
for (int i=1;i<=a;i++) {
b=reader.nextInt();
s=s+b;
}
if (s>150)
return true;
return false;
}
}

View Replies View Related

Parallel Program - Calculate SUM And AVERAGE Of Odd Number Digits Between 25 And 75

Jun 11, 2014

You are to write a parallel program that will receive a large array of unsorted integers containing digits from 0 to 99. The program will have to calculate the SUM and AVERAGE of ODD number digits between 25 and 75 (inclusive). The user may specify the size or the array and the total processor that the machine has. The size of the array must be divisible by number of processor. Based on the given size, the computer will generate random integer numbers automatically to populate the array.

The program should display the status of the calculation for each processor. The result should be displayed after all calculations are completed.Error messages should be displayed appropriately

a) Write a sequential (non-parallel) program that will accomplish above task.
b) Write a concurrent (parallel) program that will produce the result of the above task.

View Replies View Related

Unable To Print Out Results Of Program That Calculate Number Of Seats

Nov 11, 2014

I'm trying to print out the results of a program that calculates the number of seats the parties will get in an election.I have to print the partial results and the national results.

I can print te number of seats per party in each constituency, but how can i sum all seats per party in each constituency and print the national results?I'm working with vectors, which I know it might not be the best option, but everything is working, except the fact that I can't loop throuhg the vector and retrieve the total sum per party.Like, adding the seats for labour party in Constituency A and B and C, etc, and print the sum. And do the same for conservative party.Is it possible, or doIhave to create a method in Parties class to solve the problem?

This is what I have now.

for (Parties p : h.geral) {
show += String.format("Constituency - %5s - %5s - %d%n",
p.getConstituency(), p.getParty(), p.getNum_seats());
}

View Replies View Related

Calculate Number Of Square Feet In A Tract Of Land With 3.5 Acres

Jan 27, 2014

1. Land Calculation

One acre of land is equivalent to 43,560 square feet. Write a program that calculates the number of square feet in a tract of land with 3.5 acres. Hint: Multiply the size of the tract of land (in acres) by the number of square feet in an acre to get the number of square feet in the tract.

a) You must have a variable called nrAcres where you will store the number of acres in the track.

b) Output must look as follows:

Size of land in acres: 3.5
Size of land in square feet: 152460

c) if the value of the variable nrAcres is changed the output should change accordingly. In other words: it would be wrong to have the following statement:

System.out.println("Size of land in square feet: 152460");

previous statement will print the correct output but will not change if you change the value of nrAcres.

View Replies View Related

Calculate Number Of Square Feet In A Tract Of Land With 3.5 Acres

Jan 27, 2014

Land Calculation

One acre of land is equivalent to 43,560 square feet. Write a program that calculates the number of square feet in a tract of land with 3.5 acres. Hint: Multiply the size of the tract of land (in acres) by the number of square feet in an acre to get the number of square feet in the tract.

a) You must have a variable called nrAcres where you will store the number of acres in the track.
b) Output must look as follows:

Size of land in acres: 3.5 Size of land in square feet: 152460

c) if the value of the variable nrAcres is changed the output should change accordingly. In other words: it would be wrong to have the following statement:

System.out.println("Size of land in square feet: 152460");

previous statement will print the correct output but will not change if you change the value of nrAcres.

this is what i got so far

public class Land
{
public static void main(String[] args){
double nrAcres = 3.5;
int feetInAcre = 43560;
double feetInTract = nrAcres * feetInAcre;
System.out.println("Size of land in acres: " + nrAcres + "
Size of land in square feet: " + feetInTract);
}
}

i tried to compile it but it says

error: class names, Land, are only accepted if annotation is explicitly requested 1 error

what is wrong with my code

View Replies View Related

User Enter A Number For Width And Length - Calculate Area And Perimeter

Apr 27, 2014

I am trying to make a program so that the user has to enter a number for the width and length and it will give the area and perimeter:

import java.util.* ;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class jframe extends JFrame {
private static final int WIDTH = 400;
private static final int HEIGHT = 300;

[Code] ....

It is giving me an error saying that the ExitButtonHandler and ebHandler do not have classes but I don't understand why.

View Replies View Related

How To Reduce Number Of Parallel Arrays In Code

Mar 8, 2015

I'm building a text based "game" where you are communicating with this android creature called Gargoid , at a VERY primitive level . how it works is, simply the user type in a sentence which is decoded for meaning by comparing it with a built in list of words in order to figure out what the user is saying, and then reply with a a relevant response also from a list of built in words. the whole thing would look something like this,

user: what is your name
Gargoid : my name is Gargoid, nice to meet you
user: how is the weather
Gargoid: the weather is wonderful

so far I have 11 arrays which are the following

String[] for user typed in words used for comparison to find meaning ..An Array of String[] , 7 so far, to hold what I call the Gargoid dictionary for example String[] greeting={hi,hello,aloha}, words that indicates greeting int[] called frequency to determine which of the 7 arrays have the greatest "relevancy" to what is being said. and finally another String[] for responses here's the actual code, I want you guys to tell me if there's a way to reduce all this never ending number of arrays? and also is this code a good application of object oriented programming?

MainClass
public class GargoidMain {
public static void main(String[] args) {
TheKeyBoard keyboard=new TheKeyBoard();
TheTranslator translator=new TheTranslator();
TheBrain brain=new TheBrain();
translator.translate(keyboard.userSaysWhat());
brain.respond(translator.userSays());

[code]....

View Replies View Related

Code That Prompts For And Reads In The Number Of Coins In One Of The Piles

Oct 26, 2014

I'm very new to writing code (college freshman) and I need a code that prompts for and reads in the number of coins in one of the piles, as well as a String containing a single letter to indicate the type of coin in that pile: "P" for pennies, "N" for nickels, "D" for dimes, and "Q" for quarters. The program then computes the value of that pile of coins and prints it out. Here's what I have so far:

import java.util.Scanner;
/**
This program reads a student's final class average,
and prints out the appropriate letter grade..
*/
public class Coins
{
public static void main(String[] args)
{
// Define constants

[Code]...

View Replies View Related

Code That Reads In Lines Of Text And Returns Number Of Spaces

Nov 28, 2014

I am trying to make a java code that reads in lines of text and returns the number of spaces in each line.I think i have made it but i can not compile it..

Here is my code:

class Mainh {
public static void main( String args[] ) {
System.out.print( "#Enter text : " );
String text = BIO.getString();
while ( ! text.equals( "END" ) )

[Code] ....

View Replies View Related

Write A Code That Allows A User To Input Number Of Stones In A Basket

Nov 20, 2014

I am trying to write a code that allows a user to input the number of stones in a basket, then put the stones in my pocket, after the stones are in my pocket, the stones must be taken out, one by one, and thrown in a pond. I get stuck at this part because my for statement has to subtract the number of stones in my pocket (one at a time) and add a stone to the pond (one by one) at the same time.I can get the pond stones to increase until the max amount of stones with the following:

for (int i = 0; i < stones; i++) {

System.out.println("Pocket:" ? " " + "Pond:" + i);

how to reduce one and add to other. Is it possible to do this in one for statement? I tried to put stones-- in place of the question mark, but that is not working.

View Replies View Related

Calculate Percent In Java

Jan 3, 2014

I would like to change the precent from *1.17 (17%) to calc of precent like this :

3% + 5% + 5$

For example :

The resault is 10$ - i want to get :

10$ +3%(0.3$) + 0.5% (0.51$) + 5$ = 15.81$

How i change this line to this calc

if(results[i].getSite()=='Xxx'&&XPrice==0)
{
XPrice =(results[i].getPrice() *1.17);
}
}

View Replies View Related

Calculate Coupon Discount In Java?

Feb 9, 2015

i finished up a project here and seem to be running into some issues. I figured its my notation, when i ask a user to enter a number, if its below 10, it should *only* print "No Coupon." but what appears to happen is that the program prints "No Coupon" Plus the "discount coupon and % of purchase."

import java.util.Scanner;
public class assign1c { /* Start of Class 1c */
static double cost;
static double coupon = 0;
static String x = "No coupon";
public static void main(String[] args) {
// TODO Auto-generated method stub

[code]...

View Replies View Related

Java Program To Calculate Diameter?

May 6, 2014

Assume the tanker is a cylinder of length 19.35 feet and volume 1320 gallons. What is the diameter in feet of the tanker truck? To solve this problem, write a Java program to calculate the diameter. For full credit, your Java application must follow these specifications.

1. The program must interactively input the capacity of the tanker in gallons and its length in feet. This should be done in the main method of your Tester class.

2. The input data should then be used to construct a TankerTruck object. You will need to write the TankerTruck class.

3. A TankerTruck method should be used by main to calculate the resulting diameter of the truck in feet.

4. Your program should use the standard Java constant for the math constant PI.

5. The output should be displayed using fixed-point notation, rounding to one decimal place of precision

View Replies View Related

Java Program Method To Calculate Distance

Feb 20, 2015

Write method distance, which calculates the distance between two points (x1, y1) and (x2, y2). All numbers and returned values should be of type double. Incorporate this method into an program that enable the user to enter the coordinates of the points, then calculate and display the distance by calling the method –distance.

I've tried numerous times to make it work and I'm on the right path, however I'm missing some things in the code to make my results look like this later on, which I've attached onto this post.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved