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


ADVERTISEMENT

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

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

Comparing Specific Elements Of Two Arrays

May 5, 2015

I’ve been working on this problem for a couple days already but I came to a point where I don’t really know what to do. Basically I’ve got two arrays filled with int values (0, 1, and 2), which I get from Class B through their respective getMethods.

1 stands for black and 2 stands for something else.

The program counts how many times the value 1 (if chosen color is black) occurs in both arrays and then compares the both counts. If it detects any difference the program does something else, otherwise it waits.

public class A {
private static boolean finished;
public A() {
B objectClassB = new B();
int[] numbers = objectClassB.getNumbers();
int[] numbers2 = objectClassB.getNumbers2();
String color = objectClassB.getColor();

[Code] ....

Here the class B.

public class B {
private int[] numbers = new int[] { 2, 2, 0, 2, 1, 0, 1, 2, 1, 1, 0, 2, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 2, 1 };
private int[] numbers2 = new int[] { 2, 2, 0, 2, 1, 0, 1, 2, 1, 1, 0, 2, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 2, 0 };
private String color = "black";
public B() {
}
public int[] getNumbers(){

[Code] .....

this would be the Output:

[2, 2, 0, 2, 1, 0, 1, 2, 1, 1, 0, 2, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 2, 1]
[2, 2, 0, 2, 1, 0, 1, 2, 1, 1, 0, 2, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 2, 0]
number of black tokens of first array: 8
number of black tokens of second array: 7
the number of black tokens has changed

The actual problem is that I will be getting one array at a time (meaning: the array int[] numbers from Class B updates itself and might change its values). I just declared and initialize both arrays for illustration purposes.

That would mean I need to hold the array’s values the first time I get them in a temporary variable until I get the values of the updated array. Then I could use them in the method –numberOfRelevantElements- and check if any changes have occurred.

What would be the best approach for doing this? I though of inserting the different counts that I get into a queue and then comparing these values one after the other. But I’m not really sure if that would work.

View Replies View Related

Find Highest Rated Movie

Apr 17, 2014

import java.io.*;
import java.util.*;
import java.util.StringTokenizer;
class read {
public static void main(String[]args) {
populateFilmVector();
bestfilm();

[Code] .....

There are my two java files I want to search through film items and find the one with highest rating ...

Film title ain & Gain
Lead role wayne Jhonson
Run time :123
Rating :4.5
id :23415

[Code] .....

That is my output. I want this to be output along with which ever one has the highest rating....

View Replies View Related

Find The Column With Highest Average Number

Feb 14, 2015

code a 10 * 10 matrix, with random numbers from 1 to 100,

i) Find the most repeated number.
ii) Use the Binary Sort, to sort the matrix in ascending order.
iii) Find the Column, with the highest average number.

View Replies View Related

Declare Array Of 50 Elements Of Type Double - Print Output 10 Elements Per Line

Feb 5, 2015

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class array
{
public static void main(String[] args)

[Code] ...

Is there a way to write this, where, alpha is one array.

Write a program that declares an array "alpha" of 50 elements of type "double". Initialize the array so that the first 25 elements are equal to the square of the index variable and the last 25 elements are equal to three times the index variable. Output the array so that 10 elements per line are printed.

If I have an array of 50 integers, can I break that to read in lines of 10?

View Replies View Related

Java Program - Find Next Highest Or Lowest Prime Number

May 2, 2014

Java program takes positive int from user and determine if prime. Next the program finds next highest or next lowest prime number.

import java.io.*;
import java.util.*;
public class pa2take2 {
public static void main (String[]args){
int menus; //menu selection

[Code] ......

View Replies View Related

Add Elements To 2D Array Without Losing Elements

Jan 12, 2015

I am trying to make a 2d array that keeps track of comparison counts. what I have so far works ok but writes over the previous elements with 0. can't seem to find where I am re-initializing the previous elements.

//this is one of my fill sort arrays

public void fillSelectionArray(int index, long countSum) {
//rand = new Random( );
//for ( int i = 0; i < listsize; i++) {
selectionList[ index -1] = countSum;
// }

[Code] ....

I know I am missing something just not sure what.

View Replies View Related

How To Get Highest Value Of Array Of Integers

Jul 1, 2014

I am trying to write a method that returns the busiest hour in a logAnalyzer class that read web server data and analyze hourly access patterns and stores them in an array. My problem is, in order to get the busiest hour, I need to go through the hourCounts array to find the element with the biggest count.

View Replies View Related

Highest Value In Array List?

Feb 2, 2015

I have 3 classes Pet, Cat and Dog classes. Cat and Dog classes are childs of Pet class.

Each pet has the properties of

private String myName;
private int myX;
private int myY;
private int mySpeed;
private int myAge;

I have an array list which creates 100 dogs. How can I print out the dogs with the two highest age values?

View Replies View Related

Between Two ArrayLists / How To Find Which Elements They Have In Common

Apr 6, 2015

I have two ArrayLists and I want to compare them for common elements, and based on the result I want to update the first Arraylist to only have these elements. sort of like the opposite of RemoveAll() which removes elements in common and keep the ones that are unique. so far I thought of using for loop and .contains() in case it was fault,element not present, remove from list. but I was wondering
in what other ways, perhaps APIs i can use to do that?

View Replies View Related

Find Common Elements In Collection?

Mar 19, 2014

I need to create an algorithm that finds the common element(s) in all arrays that has a signature of public Comparable[] findCommonElements(Object[] collection) that has an efficiency of at most O(knlogn), uses a query array, and accepts as input a collection of arrays. I am aware my time would be better spent learning how to use array lists and hash sets, but I am supposed to use concepts already covered, and these have not been.

I feel like this code should work, but it is returning null for the array of common elements. Which means it obviously is not working correctly. I am also likely going to need implementing the sort algorithm, but I wanted to get the part of finding the common elements set first.

public class CommonElements2<T extends Comparable<T>>
{
Comparable[] tempArr;
Comparable[] common;
Comparable[] queryArray;
/*
sort algorithm goes here
*/
public Comparable[] findCommonElements(Object[] collections)

[code]....

View Replies View Related

How To Find How Many Number Of Elements Are Landing In Same Bucket In HashSet

Jan 12, 2015

Is there any way to find how many number of elements are landing in same bucket in HashSet. I know Reflection could be one way but i am not able to design a program for that.

View Replies View Related

Java Program To Find Index Of Greater Element Whose Value Is Sum Of Remaining Elements

Aug 25, 2014

I need to write a java program to find the index of the element whose value is the sum of the remaining elements. Recently I have been asked this question in an Interview which I couldnt solve properly.

View Replies View Related

Calling Methods For Java GradeBook - Calculate Highest And Lowest Grades In Array

Apr 15, 2015

In this project each individual will create a data analysis program that will at a minimum,

1) read data in from a text file,
2) sort data in some way,
3) search the data in some way,
4) perform at least three mathematical manipulations of the data,
5) display results of the data analysis in numeric/textual form, and
6) display graphs of the data. In addition,
7) your program should handle invalid input appropriately and
8) your program should use some "new" feature that you have not been taught explicitly in class.

(Note: this is to give you practice learning new material on your own - a critical skill of today's programmer.) If you do not have a specific plan in mind for your project, below is a specific project that meets all of the qualifications as long as 7) and 8) are addressed in the implementation.

Everything is done except I need to call my methods in my GradeTester.

GradeBook:

/**
*This class creates an array called scores.
*This class determines the length of the array scores and determines the last grade in the array scores.
*This class sorts the array using a bubble sort, and searches the array.
*This class calculates the mean, standard deviation, and the median of the grades in the array scores.
*Once the grades in the array is sorted, the class then calculates the highest and lowest grades in the array.
*/

public class GradeBook {
public final int MAXARRAY_SZ = 20;
double [] scores = new double [MAXARRAY_SZ];
int lastGrade = 0;
double mean = 0;

[Code] ....

View Replies View Related

Comparing In A Two Dimensional Array?

May 3, 2014

I have to make a program in which users inputs a number and the program should search into a two dimensional array and print out all the values that are below the number This is my first time experimenting with 2D Arrays and how to do this program I have the array set up

String firstarray[][]=
{{"", "Store101", "Store102", "Store103", "Store104"},
{"Tennis Shoes", "102", "54", "20", "78"},
{"Sweaters", "45", "25", "35", "75"},
{"Jeans", "12", "35", "45", "65"},
{"Shorts", "54", "25", "34", "45"},
{"Jackets", "15", "35", "50", "25"}
};

View Replies View Related

Comparing Two Dimensional String Array

Mar 7, 2014

I want to compere two element of string array by each other! eventually I want to print Yes or No in matrix . SO, I start reading data from file then split them into two parts .

File file= new File(fileName);
try {
inputStream = new Scanner(file);
while (inputStream.hasNext()){
String data= inputStream.next();
String [] token =data.split(",");
System.out.println("day"+token[0] +"embloyee name:"+ token[1]) ;
}
inputStream.close();

Now I want to compere each cell from token[0] by another array :

String[] day= { "Sunday", "Monday" ................};

if the days are equal then I want print yes in front of the employee name if not then i want to print No..is this gone work with me as I imagine it to be or do I have to take few more steps to get my code going?

View Replies View Related

Comparing String To Array Element?

Oct 17, 2014

I have the following code:

Java Code:

public class Equals {
String[] s1 = {"red", "white", "black", "blue"};
String[] s2 = {"red", "black", "green"};
String[] s3 = {"red", "green"}; mh_sh_highlight_all('java');

What I need is to give me the following output:

Select Strings: s1,s2,s3
Comparing String s1, s2, s3

red 3 matches.

black 2 matches.

green 2 matches.

View Replies View Related

Comparing String To Array Element

Oct 17, 2014

I have the following code:

public class Equals {

String[] s1 = {"red", "white", "black", "blue"};
String[] s2 = {"red", "black", "green"};
String[] s3 = {"red", "green"};

What I need is to give me the following output:

Comparing String s1, s2, s3

red 3 matches.
black 2 matches.
green 2 matches.

View Replies View Related

Make Array From Some Elements Of Another Large Array?

Jan 22, 2015

When I insert: title, category, year, artist in 4 Strings And when I press "enter" i put those 4 in a array "large", and then when I can start a new music insert with 4 new string elements and add those in the large array..So: I have an array "large" with the length 19 (or so..)(max ~100 or so)Then I what to: get,in a new array "title",the elements:0,4,8,12,16 (from the large array) and put them in a scrollable list. And when I select one element in the title array I then whant to get 3 remaining elements from this. And put it in a array called selection.

So the "large" and the "title" arrays must be dynamically sizes... or be copied to a larger sized..

1 can it be done with arrays?
2 how do dynamically change the size of for example the array "title"?
3 how do I receive the elements 0,4,8,12,16 and so on, (to (
large.length-3) and add it to the title array?

View Replies View Related

Comparing Two Array List And Outputting Difference

May 12, 2014

I'm having a bit of trouble outputting the difference between two array list

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.ArrayList;
public static void main(String[] args) throws Exception {

[Code] ....

This prints out something like

Test1
Test1
Test2
Test2
Test2
Test3
Test3
Test3
Test4
Test4
Test5
Test5
Test6
Test6
Test6

Ideally, it's suppose to print out only Test2, Test3, Test6.. I've tried different combinations of loops and equals() but I never get the correct output.

View Replies View Related

Comparing Two Array Lists - Output If They Are Equal Or Not

Nov 21, 2014

I need comparing two array lists. For this program i am comparing 2 array lists. The list is integers entered by the user the second is random generated numbers. So far in my program i am able to compare the 2 arrays together and output if they are equal or not however i need the program to output even if atleast one if the integers match,

EXAMPLE list one: 1, 2 ,3 ,4, 5. LIST TWO: 1, 3, 3, 3, 3.

Since the first number matches i want it to out put there is one match, so on and so forth with if there are 3 or 4 matching integers. here is my code so far.

public static void main(String[] args)
{
final int NbrsEntered = 5; //Number of guessed numbers entered
final int LOTTOnbr = 5;
int[] numbers = new int[NbrsEntered];
int[] randomNum = new int[LOTTOnbr];
//int[] TestArrayOne = { 1, 2, 3, 4, 5 };
//int[] TestArrayTwo = { 1, 2, 3, 3, 5 };
boolean arraysEqual = true;
int index = 0;

[Code] ....

View Replies View Related

Comparing Array Or Int To 4 Digit Number From Random Generator?

Apr 4, 2015

How do I compare an array (or maybe int?) (example: 3572) to a 4digit number from random generator? how many of the four digit match the generated numbers.

View Replies View Related

Sum Of Array Elements?

May 4, 2015

What is the sum of the array ar elements after executing the following code?

int[] ar = {1,2,3,4,5};
for (int i=0; i<ar.length-1; i++)
if (i%2==0) ar[i]=i;

My professor says the answer is 12 i dont know how he got that answer

View Replies View Related

Max And Min Of Elements In Array

May 17, 2014

I cant get this code to work if wont find the right min and range and its printing out my max three times . This is what I got

public static void main(String[] args)
{
double [] Rainfall = new double[12];
Rainfall[0] = 77.4;
Rainfall[1] = 56;
Rainfall[2] = 61.8;
Rainfall[3] = 62.1;
Rainfall[4] = 57.1;

[Code] ....

View Replies View Related







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