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


ADVERTISEMENT

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

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

How To Make A Program That Determines The Highest Value Out Of Inputted Numbers

Sep 14, 2014

how to make a program that determines the highest value out of the inputted numbers.

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

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

Binary Search Method - Find Int Within Array

May 14, 2014

We are required to write a binary‐search method to find an int within an array of ints. Without using any functions besides the basics (for loops, if statements, etc.)

I have this so far:

public int binarySearch(int[] ints, int n) {
for(int i = 0; i < ints.length; i++) {
if(ints[i] == n) {
return ints[i];
}
}
}

Does this look somewhat correct?

View Replies View Related

Recursion Method With 2d Array To Find A Column With Lowest Sum

Jan 28, 2015

i have to write a method, The method receives a parameter of two-dimensional array of integers. The method returns the number of the column which has the lowest sum of the integers.I'm allowed to use only recursion! no loops allowed!-of course i need to make a private method that will sum a column as a single array and then i have to do another private method that compares the column , but it doesn't really work .

View Replies View Related

Make Linear Search Method To Check If Number N Is Included In Array

Jun 8, 2014

im trying to make a linear search method to check if a number 'n' is included in an array.

PHP Code:

package test;
public class Recursion {
public static void main(String[] args) {
}
static int linearSearch(int n, int[] array)

[code]....

Im getting the following error: this method must have a result type of type int ?? i already have a return type of type int...

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

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

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

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

How To Make A Method Splitting A String

Jan 14, 2014

How do I make a method that can seperate parts of a String. The String is [name,aid]... example [John,5],

I want to remove [ , and ] from the String... How can I do this?

This is what i've done this far:

static public String splitta(String tf)
{
String part1 = "";
String part2 = "";
String part11 = "";
String part22 = "";
String part111 = "";
String part222 = "";
String[] parts = new String[2];

[Code] ....

This dosn't work, it wont compile... It states the following:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1
at testprojekt.Validering.splitta(Validering.java:130)

View Replies View Related

Cannot Find Symbol Method

Apr 10, 2014

I was given the Java code for a project and I am supposed to build unit tests to test the performance of seven sorting algorithms and I am getting the following error in my Lab1Test file...cannot find symbol: method sorta(int[]) location: class Lab1Test.

Lab1.java
Java Code: package funcollege.comp10062.perflib;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Random;

[code]...

View Replies View Related

Cannot Find Symbol / Method Add

Oct 16, 2014

i'm working on a "name sorter" program and i want it so when i add names and such to the list box i can click sort and it sorts the names in A,B,C format.Here is my code:

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collections;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;

[code]....

I'm using Netbeans FYI and a java desktop application. Also, i have looked everywhere and even my teacher has had to look further into it, i really want to get it to work.

View Replies View Related

Cannot Find Method AvailableProcessors

Jul 21, 2014

What's wrong with this statement that it cannot find the method AvailableProcessors();?

Java Code:

Runtime.getRuntime().AvailableProcessors(); mh_sh_highlight_all('java');

View Replies View Related

Find Whole Syntax Of API Method Online?

Jul 5, 2014

I was trying to find the complete readLine() method In the online docs but all I can get hold of Is:

readLine
public String readLine()
throws IOException

Reads a line of text. A line is considered to be terminated by any one of a line feed

('
'), a carriage return ('
'),

or a carriage return followed immediately by a linefeed.

Returns:A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reachedThrows:IOException - If an I/O error occursSee Also:Files.readAllLines(java.nio.file.Path, java.nio.charset.Charset)

Is It possible to view the actual method syntax online ?

View Replies View Related

Cannot Find Method Append Error

Mar 24, 2014

I am trying to run the following code but getting the error above.
 
import java.io.*;
public class StringBuilder {
    public StringBuilder() {
        super();
    }   
    public static void main(String args[]) {
            // creates empty builder, capacity 16
            StringBuilder sb = new StringBuilder();
            // adds 9 character string at beginning
            sb.append("Greetings");
    }
}

View Replies View Related

Setting All Variables In Class To Null Or 0 To Make A New Method To Clear Everything

Mar 31, 2014

I am very Java illiterate and I need to know how would i set all the variables in the first class to null or 0 to make a new method to clear everything.

import java.util.Arrays;
import java.util.Scanner;
public class studentMethods
{
private double totalScore;
private int count;

[Code] ....

View Replies View Related

Make Array With Three Stacks

May 17, 2014

public class ThreeStackArray
{
static int row = 10;
static int col = 2;
int[][] stack = new int[row][col];
//place numbers into the first row of array
public void push(int num)

[Code] .....

I found this program idea online. Make a array with three stacks. Either I jump out of bounds if I use "continue" instead of "break" in my loop in the push method. If I use break the output looks like:

12900
0000
0000
0000
0000

if I use continue the output looks like:

An error has occured java.lang.ArrayIndexOutOfBoundsException: 2
1212
1212
1212
1212
1210

View Replies View Related

Find Node Method Within Binary Tree

Mar 29, 2015

I have some work where I have to create a binary tree. Anyway I am stuck on one of the classes which has several methods I must fill in! The code is below

The headers for each method are: public Node find (member p1)The method find(Member p1) is used to return the node which contains a particular member. It is a private method because the interface to CabinetTree should not provide direct access to the internal nodes. It makes use of the method Node findNode (Member p1, Node current)

and the next method is : Node findNode(Member p1, Node current) which searches the tree from current node to find a node whose value is equal to the Member p1, i.e. a node in the tree such that p1.equals(current.getMember()) is true. If there is no such node then the method should return null.

public class CabinetTree {
private Node head;
CabinetTree(Member p1) {
head = new Node(p1, null);

[Code] ....

View Replies View Related

Error In Main Method - Cannot Find Symbol

Dec 15, 2014

I am writing a palindrome program. I don't understand what is wrong with my Main method. It is giving me error and error is "Can not find symbol in main method"

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PalindromeA extends JFrame {
private JTextField inText;
private JTextField outText;

[Code] ....

View Replies View Related

Find Any String Length Without Using Library Method?

Apr 10, 2014

How can find any string length without using any library method??

View Replies View Related

Find Which Algorithm Java Uses For Its Sort Method

Apr 27, 2014

I have been looking around and I cannot seem to find which algorithm java uses for its sort method. Merge, sort etc.

While I am on the topic BinaryTree is a balanced heap right?

Are there any libraries for depth or breath first search?

Is the ArrayList a double linked list?

View Replies View Related







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