How To Find Overall Averages Of Columns In Array

Nov 6, 2014

How can I find the overall averages of the columns in this array?when i run my code it gives me an output that looks like this (showing me wrong averages): 0 1 2 3 overall grade

Badger,Bradley 37 70 51 48 68.66666666666667
Emu,Emma 35 81 75 40 72.83333333333334
Aardvark,Alice 42 85 22 0 65.11111111111111
Dodo,Donald exc 12 25 0 54.17391304347826
Cassowary,Cassie 50 97 72 68 62.758620689655174

my code is :

Java Code: public static double[] computeAllGrades(int[][] scoreTable, int[] itemPointValues)
{
{
double totalPoints = 0;
double totalPointsPossible = 0;
double allGrades[];
double grade =0;

[code]....

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Jtable Find Duplicates By Two Columns

Nov 30, 2014

I'm trying to remove duplicates from table. I want to remove only those rows which are both id and data equal. My code failed at fourth line.

int i=jTable1.getSelectedRow();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
jXDatePicker1.setFormats(dateFormat);
String date = dateFormat.format(jXDatePicker1.getDate()).toString();
String c1=jTable1.getValueAt(i, 0).toString();
String c2=jTable1.getValueAt(i, 1).toString();

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Create TreeTable - Parent Row With 6 Columns And Child Row Having 4 Columns

Dec 2, 2005

I am very new to Java Swing. I have to create a TreeTable in Java Swing with a Parent Row having say 6 columns and its all child row having just 4 columns. like shown below

Parent row:
-Column1-+-Column2-+-Column3-+-Column4-+-Column5-+-Column6-+

Child row:
--CloumnC1--+--CloumnC2--+--CloumnC3--+--CloumnC4--+

Can this be achieved using JSwing ?Also, Can I be able to Change the Column Headers Correspondingly when user clicks on Parent row and Child rows?

View Replies View Related

Summing Columns And Displaying Array

Apr 24, 2015

public static void displayOutputs (int[][] anArray) {
System.out.println("Here is your 2Dim array:");
for (int i = 0; i < anArray.length; i++) {
System.out.println(Arrays.deepToString(anArray));
}
}

This is my code and I get this as a result when I input 10,20,30,...,90 into array[0][0], array[0][1], ..., array[2][2] (3rows, 3columns array)

[[10, 20, 30], [40, 50, 60], [70, 80, 90]]

[[10, 20, 30], [40, 50, 60], [70, 80, 90]]

[[10, 20, 30], [40, 50, 60], [70, 80, 90]]

While I expect to get only

[10, 20, 30]

[40, 50, 60]

[70, 80, 90]

I get no errors at least when I have the same # of rows and # of columns. However, when I have more columns than rows, a compiler stops running when it runs columnSum method.Here's an error message.

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at lab10.Array2DMethods.columnSum(Arrays2DDemo.java:70)
at lab10.Arrays2DDemo.main(Arrays2DDemo.java:111)
Java Result: 1

And here's my code

public static void columnSum (int[][] anArray) {
int sum =0;
for (int col=0; col < anArray.length; col++) {
sum=0;
for (int r = 0; r < anArray[col].length; r++ ){
sum += anArray[r][col];
}
System.out.println("Sum of column " + col + " = " + sum);
}
}

why my code doesn't work when I have more columns.

View Replies View Related

How To Transpose 2D Array As In Switch Rows And Columns

Apr 14, 2015

how to switch the elements in a 2D array. As an example row 1 would become column 1 in a second array.

View Replies View Related

Multidimensional Array - Show Values In Rows And Columns

Aug 20, 2014

I am trying to write a code for multidimensional array, allocate memory for variables and access the value of the arrays. I want them to be shown as rows and columns. but my code only shows one column and no rows. here is my code:

public static void main(String[] args) {
int[ ][ ] aryNumbers = new int[2][2];
aryNumbers [0][0] = 1;
aryNumbers [0][1] = 2;
aryNumbers [1][0] = 3;
aryNumbers [1][1] = 4;
int rows = 2;
int columns = 2;

[code]....

View Replies View Related

2-dimensional Array - Print Black Image Depending On Number Of Rows And Columns

Nov 21, 2014

I wrote this code which print a black image depends on the number of rows and columns you give it

public class BlackImg {
private Mycolor[][] colorArr; //Mycolor is a class i wrote that represents colors.
// no need for showing the class here.
// so i created here an array of type Mycolor, for example:
// { {(255,255,255), {(127,127,0)} }

[Code] .....

my problem is that my output comes good except the last line ,

Output:
(0,0,0) (0,0,0) (0,0,0) (0,0,0)
(0,0,0) (0,0,0) (0,0,0) (0,0,0)
(0,0,0) (0,0,0) (0,0,0) (0,0,0)
BlackImg@1db9742 //what is this line , why does it showing up ?

View Replies View Related

Code Averages Across Column

Nov 5, 2014

i am trying to code the averages across column but I end up with the wrong averages.

My test cases:

name 0 1 2 3 overall grade
Badger,Bradley 37 70 51 48 68.66666666666667
Emu,Emma 35 81 75 40 72.83333333333334
Aardvark,Alice 42 85 22 0 65.11111111111111
Dodo,Donald exc 12 25 0 54.17391304347826
Cassowary,Cassie 50 97 72 68 62.758620689655174

My code:

public static double[] computeAllGrades(int[][] scoreTable, int[] itemPointValues) {

{
double totalPoints = 0;
double totalPointsPossible = 0;
double allGrades[];
double grade =0;

[code]....

View Replies View Related

Gradebook Program - Calculate Averages Of 25 Students Using 2D Arrays

Apr 16, 2014

I am making a gradebook program that calculates the averages of 25 students using 2D arrays in which the students have four test grades. I have figured out how to display the averages of each student in one column but I cant seem to figure out how to display the letter grade of the average into another column.

Right now my program reads from a .txt doc

Heres what I've got.

TestGradeBook.java

import java.util.*;
import java.io.*;
public class TestGradeBook {
public static void main (String [] args ) throws IOException{
//Declarations
final int ROWS = 100;
final int TESTS = 4;

[Code] .....

GradeBook_Data.txt
Name100100100100
// basic name and grades

View Replies View Related

Create A Java Program That Can Read Specific Data Within Csv File To Work Out Averages

Aug 7, 2014

i am fairly new to java but have made a few projects so i do know most aspects that would allow me to complete the task its just i have been stuck at the same place now for 2 days.The project is to create a java program that can read specific data within a csv file to work out the averages etc. The csv file is a database of different weather stats . an example of the first 12 months of the csv file is below..

[CSV FILE]

year ,month,average rainfall etc

1946 15.70.616108.131.5
1946 28.23.56111.871
1946 38.82932.9 102.9
1946 414.16.3029.2 150.5
1946 513.96060.7 143.6

[code]...

I know that once the data is indexed i can than use a double to find the average of the 12 specific pieces of data and so on. once this is complete i should than be able to transfer the data to a simple graph.

View Replies View Related

Create 2D Array Out Of CSV File And Find Number Of Elements To Determine Array Size

Mar 24, 2015

I am taking the Class Algorithms and Datastructures and got an assignment for Lab that really throws me off. The goal is to create an Array out of a given CSV file, implement several Methods that get the size of array, etc.

I am still stuck in the first part where the CSV has to be imported into the Array. My problem is that I need a mechanism that figures out the needed size for the Array, creates the array, and only then transfers the data from the CSV.

The list consists of the following wifi related values:

MAC-Adress, SSID, Timestamp, Signalstrength.

These are on the list, separated by comma. The Columns are each of these, and the rows are the four types of values making up the information on a certain wifi network.

The catch is, we are not allowed to use any of the following:

java.util.ArrayList
java.util.Arrays
and any class out of java.util.Collection.

So far I used the BufferedReader to read in the file and tried to implement the array, but I get an arrayindexoutofboundsexception.

Below is my Code (Its still an active construction zone):

public class WhatsThere {
public WhatsThere(String wifiscan) throws IOException {
}
public static void main(String[] args) throws IOException {
// WhatsThere Liste = new WhatsThere(String wifiscan);
String[][] arrayListe = new String[0][0];

[Code] ....

View Replies View Related

How To Find Corners Of Array

Nov 10, 2014

So as part of my program I have to find the corners of an array (the array can vary in size but is always square) but I'm not exactly sure how to do this. I thought of one possible way but I am not sure if I can do it or how to write it,

if array[row][col] = [0][0] or [row length][col length] or [0][col length] or [row length][col length].

I'm just giving examples of what I am trying to find here I know none of these are actual syntax. I don't even know if I can check whether an array's coordinates are equal to coordinates on that array or not. How I can write this or if there is another way to do it? If yes, what about edges of the array?

View Replies View Related

Find The Longest Decreasing Sub-array

Oct 30, 2014

I have a given array of numbers, and I have to find the longest decreasing sub-array, but the thing is that the elements don't have to be next to each other!

For example, the longest decreasing sub-array for this array : 546 -156 165 -156 -56 -13 5

is 3 (check the bold numbers)

Until now, I have nearly finished my code, but I have one problem...

private static int decreasing(int[] a) {
int result=1, temp=0, br=1;
//Checking all the elements one by one:
for(int i=0;i<a.length;i++){
temp=a[i]; //placing the element on a temp value

[Code] ....

The problem with this code is that it's not smart.. let's say I have : 100 -500 90 80 70

Once it hits -500, none of the other if's with pass....

View Replies View Related

Find Slot Number In Array?

Jan 30, 2015

what I needed to know to complete the lesson, but now it just tells me what the output should be and I have to research the information on my own. anyways, here is my code from the previous lesson:

import java.util.Random;
import java.util.Scanner;
public class tnArray {
public static void main(String[] args) {
int [] array;

[code]....

Now I have to change it so that instead of counting the number of times a number will appear in the array, I must output which slot in the array the number is in.

View Replies View Related

Find Largest And Smallest Value From Array

Nov 15, 2014

I am trying to display Largest value and Smallest value in an array but when I execute I get Largest value as 0.

Following is the code:

package simpleArray;
import javax.swing.JOptionPane;
class ArrayInteractive {
static String ch = "Q";
static boolean flag = true;
static String a[];

[code]....

View Replies View Related

How To Find A Path Through Array Maze

Mar 4, 2015

So what I'm trying to do is write a code in java which finds a path through a maze. I want it to go through the maze and determine if there's a * symbol at that location or not. If there is a * symbol at the specified location then the program would search for another position until it finds one without the * symbol and if it can't then I'll have the program return null. I also want it to implement backtracking which I'm not sure how to do. Here's my code so far

private boolean findPath(int fromRow, int fromCol, int toRow, int toCol){
boolean solved = true;
for(int i=fromRow; i<toRow; i++){
for(int j=fromCol; j<toCol; j++){
if (x[i][j] == ('*')){
//do something
}
}
}
return false;
}

the code isn't finished yet however what I'm not sure is what do I do with the if statement and how do I implement backtracking?

View Replies View Related

Searching Through Array / Find Name And Print

Oct 5, 2014

An array which contain a list of names. I let for a user input and I use that to search through the array. For example lets say the string name "Christian" is stored inside the names array and the user types in Chri, the program looks in the array and finds a name that contains Chri and prints them out. How do I go about doing this?

View Replies View Related

Find Biggest Number From Array

Jun 26, 2014

I have 2 arrays in random order of 10 numbers.I need to find the biggest number from array A and B and then when its on a screen second thing is to multiply those numbers by 2.

import java.util.Random;
public class Projektas {
public static void main(String arng[]){
int i,j;
int A[] = new int [10];
int B[] = new int [10];;

[code]..

View Replies View Related

For Specified Array Find Value Of Downloaded Characters

Nov 5, 2014

I would like to ask how with such an array:

x_z01
x_z02
x_q01
x_q02
x_q03

From this table I have searched:
for the
"x_01"

algorithm chosen:
x_z01
for the
"x"

algorithm chose :
"x_z01"
for the
"Z01"

algorithm chose :
"x_z01"
for the
"x_q"

algorithm chose :
"x_q01"

For any character - chose any value from an array
 
import java.util.Scanner;
/** */
public class Array_value{
/**      * @param args the command line arguments      */
public static void main(String[] args) {

[Code] ....

Whether this algorithm: [Code] ....

View Replies View Related

How To Make A Method That Find Highest Value In Array

Dec 5, 2014

I made a method which takes values from a data set and finds out which one is the highest value. When it finds the highest value, it returns the country which is associated with the value. Here's the data set.

"Country""Total CO2 2005 (million tonnes)""Road CO2 (million tonnes)""Road CO2 per person (tonnes)""Cars per 1000 people"
10
USA5951.131530.35.16777
UK2573.4119.681.99470
Italy476.08116.862592
Germany841.78150.211.82550
Canada553.02123.423.82562
France414.03128.132.04477
Russia1575.44114.690.8178
Japan1254.47224.241.76447
China5100.6228.020.317
India1147.4691.060.18

So if the number was 5951.13 then the program would return USA. How do I do that? I've already started on trying to get this code to work but it doesn't seem to compiler so what's wrong with it?

public static CO2Data highest (CO2Data [] arr2){
Scanner sc = new Scanner(System.in);
CO2Data highestindex = arr2[0];
CO2Data currentcountry = arr2[0].getCountry(sc.nextLine());

[Code] ....

Also the array is a CO2Data array which is part of the following class:

public class CO2Data { //The CO2Data class will be called in other methods
 
private String country; //A private variable will prevent other users from accessing and changing these variables.

private double totalCO2;
private double roadCO2;
private double CO2PerPerson;
private int carsPerPerson; 
public CO2Data() {
country = "";//this sets the initial values for the different variables

[code].....

View Replies View Related

Find Arithmetic Mean Of The Numbers Stored In Array

Feb 23, 2014

The program below is intended to find the arithmetic mean of the numbers stored in the array q in two ways: once by storing the numbers in an ArrayList d, where you allow all the necessary conversions to be performed automatically; and once by storing them in an ArrayList e, where you perform all the conversions by hand. Complete the program.

Here is what I have so far:

double[] q = { 0.5, 2.4, 7.4, 2.8, -6.2 };
ArrayList<Double> d = new ArrayList<Double>();
ArrayList<Double> e = new ArrayList<Double>();
for ( double x : q ) {
d.add( x );
e.add ( new Double ( x ) );

[Code] .....

Why does it still show "a / d.size?" I thought I fixed that. Whatever, it's supposed to be "dTotal / d.size()", etc.

View Replies View Related

Logic To Find Adjacency Of Numbers 0 And 1 In Array

Oct 3, 2013

I should mention here that number of elements can be from 1....10'000. And it has to be done as O(N)

I attempted at the problem like so :

public static int adjacencies(int[] A) {
int count = 0;
boolean found = false;
for(int i = 0; i < A.length-1; i++) {
if (A[i] == A[i+1]) {

[Code] .....

To me it looks right and it seems to work.

View Replies View Related

How To Find How Many Times A Number Appears In Array

Dec 7, 2014

This is my code up to now and I can't do anything to make it work. I want it to tell me how many times the number 3 appears, and the last position it was in. I am getting errors like"Cuanto.java:88: getPosition(double[],double) in Cuanto cannot be applied to (double) ....

a = getPosition(a);" and unreachable statements, and value not found. It's all over the place every time I make a change to it.

Java Code:

public class Cuanto {
static int getPosition(int count,double listOfValues[],
double targetValue) {
int a = 0, i;
for (i=0; i < listOfValues.length; i++) {
if (listOfValues[i] == targetValue) {
a++;

[Code] ....

View Replies View Related

Comparing Elements In Array To Find Highest Int

Sep 3, 2014

So in this program, which is a grading program, I am trying to compare all the students averages to find who has the highest one and list the grades and the student's names from least to greatest. Yes, I see there are other problems in the program but it is nowhere near finished.

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String[] studentName = new String[20];
int[] studentAverage = new int[20];
Scanner input = new Scanner(System.in);

[code]....

View Replies View Related

How To Find Maximum Element Of Each Column In 2D Array

Oct 26, 2014

import java.io.IOException;
public class Largestcolumn
{
public static void main ( String[] args ) throws IOException
{
int largest = 0;
int newnumber = 0;
int[][] data = { {3, 2, 5},

[Code] ....

When I run this code, I get this following output: The largest element in column 0 is: 9.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at largestcolumn.Largestcolumn.main(Largestcolumn.java:27)
Java Result: 1

It outputs the first column's maximum element but then throws an out of bounds error. I'm new to Java and I can't figure out how to fix my code so that it will work for this multidimensional array and output the maximum elements in all of the columns.

View Replies View Related

Program That Find Minimum Value In Array Of Integers

Feb 3, 2014

I'm required to create a program that finds the minimum value in an Array of integers.

Here is my approach :

public class Person {
public static void main(String [ ] args){
int theArray[]=new int [10];
int result = 0;
for (int i:theArray){
if (i < Integer.MAX_VALUE)

[Code]...

I can't really progress from this position. I keep getting told to change the return type to int on main method, then when i do it says change it to void..

View Replies View Related







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