11 Replies - 528 Views - Last Post: 29 April 2012 - 11:20 PM Rate Topic: -----

#1 Jan714  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 29-April 12

Help with Array Related Java Program

Posted 29 April 2012 - 08:50 PM

Hello all,
I have just enrolled in my first Computer Science course this spring and encountered a problem with completing these codes.
I have one main and four classes. The object of the program is to create a program that gives the user information about the popularity of different names from the years 1900 to 2000. Given a file with All of the information.

I have to:
Display all the rankings from 1900-2000 for a single name given
Display a competition between two names through the years 1900-2000 and tell which was more popular.
Find and sort the Top 50 names for a year by rank.

Here are my different codes so far.


this is my main code:
import javax.swing.*;
import java.io.*;


public class PA6JBER
{
	public static void main(String [] args)
	
	{
		
		
		String input = JOptionPane.showInputDialog(null, "What is the name of the file you would like to input?");
		Processor myProcessor = new Processor();
		myProcessor.readData();
		
		int option = menu();
		
		
		
		switch(option)
		{
			case 1: 
				double Rankings = myProcessor.Rankings();
				JOptionPane.showMessageDialog(null, " rankings for that name from 1900 - 2000 are " +Rankings ); //add method that reads the rankings and call
				break;
			case 2: 
				String Competition = myProcessor.Competition();
				JOptionPane.showMessageDialog(null, "The winner of that year between the two names is" +Competition );//add method that compares
				break;
			case 3:
				int top50 = myProcessor.Top50();
				JOptionPane.showMessageDialog(null, "Here is a list of the top 50 names for that year:" + top50); //top 50 method
				break;
			case 4:
				JOptionPane.showMessageDialog(null, "Goodbye and thank you for using this program" );
				break;
			default:
				JOptionPane.showMessageDialog(null, "Goodbye");
							
		}
			option = menu();
	}
		private static void announce()
	{
		JOptionPane.showMessageDialog(null,"This program will process the file names according to your choice.");
	}
	
	private static int menu()
	{
		String option = JOptionPane.showInputDialog(null,"Please enter what you would like to do:\n"
		+ "1: Find the rankings from 1900 - 2000 for a single name\n" + "2: Compare the rankings between two names and see which was more popular\n" 
		+ "3: Find the top 50 names for a single year\n" + "4: End program");
		
		return Integer.parseInt(option);
	}
}





This is my Names Class:
import javax.swing.*;
import java.io.*;

public class Names
{
	double Year1;
	double Year2;
	double Year3;
	double Year4;
	double Year5;
	double Year6;
	double Year7;
	double Year8;
	double Year9;
	double Year10;
	double Year11;
	String [] names;
	String name;
	double [] rankings;

	
	String names(String n, double y1, double y2, double y3, double y4, double y5, double y6, double y7, double y8, double y9, double y10, double y11)
	{
		String name = n;
		Year1 = y1;
		Year2 = y2;
		Year3 = y3;
		Year4 = y4;
		Year5 = y5;
		Year6 = y6;
		Year7 = y7;
		Year8 = y8;
		Year9 = y9;
		Year10 = y10;
		Year11= y11;
	}
	public String names(String n)
	{
		name = n;
		names = new String[11]; //empty array of grades
	}
	
	public String getName()
	{
		return name;
	}
	
	public double getRanking(int num)
	{
		return rankings[num];
	}
	
	public double getYear1()
	{
		return Year1;
	}
	
		public double getYear2()
	{
		return Year2;
	}
	
		public double getYear3()
	{
		return Year3;
	}
		public double getYear4()
	{
		return Year4;
	}
		public double getYear5()
	{
		return Year5;
	}
		public double getYear6()
	{
		return Year6;
	}
		public double getYear7()
	{
		return Year7;
	}
		public double getYear8()
	{
		return Year8;
	}
		public double getYear9()
	{
		return Year9;
	}
		public double getYear10()
	{
		return Year10;
	}
		public double getYear11()
	{
		return Year11;
	}
	
	public String toString()
	{
		return Year1 + "" + Year2 + "" + Year3 + "" +Year4 + "" + Year5 + "" + Year6 + "" + Year7 + "" + Year8 + "" + Year9 + "" + Year10 + "" + Year11 + ""; 
	}
	
	public String Names(String name,double year1,double year2,double year3,double year4,double year5,double year6,double year7,double year8,double year9,double year10,double year11)
	{
	
	}

	public int compareToRank(Names s, int rank)
	{
		int index=rank-1; //since index starts at 0, but test starts at 1
		
		/* compare the 2 test scores */
		if(this.rankings [index] == s.rankings [index])
			return 0;
		else if(this.rankings [index] > s.rankings [index])
			return 1;
		else 
			return -1;
	}
}




This is my Processor Class
import javax.swing.*;
import java.io.*;
import java.util.Scanner;

public class Processor
{

	
	public void readData()
{
	
	File myFile; //file to read from
	int names;
	Names [] myNames;
	int count = 0;
	final int NUM_NAMES = 11; //number of grades to read & store
	int index = 0; //where in the student array to insert next
	String name; //declare name variable to hold name that is read from file
	double[] names3 = new double[NUM_NAMES];
		double year1 = 0;
		double year2 = 0;
		double year3 = 0;
		double year4 = 0;
		double year5 = 0;
		double year6 = 0;
		double year7 = 0;
		double year8 = 0;
		double year9 = 0;
		double year10 = 0;
		double year11 = 0;
	
try{
		Scanner scan = new Scanner(myFile);
			
			/* read and store all data */
		while(scan.hasNext())
			{
				/* read in each line */
		name = scan.next(); //read in name
				
		year1 = scan.nextDouble();
		year2 = scan.nextDouble();
		year3 = scan.nextDouble();
		year4 = scan.nextDouble();
		year5 = scan.nextDouble();
		year6 = scan.nextDouble();
		year7 = scan.nextDouble();
		year8 = scan.nextDouble();
		year9 = scan.nextDouble();
		year10 = scan.nextDouble();
		year11 = scan.nextDouble();
									
				/* add to array */
		myNames[index] = new Names(name,year1,year2,year3,year4,year5,year6,year7,year8,year9,year10,year11);
			index++;
		}//end of while
			
			//save number of students
			numNames = index;
	}//end of try
	
	catch(IOException e)
		{
			System.err.println("Error opening file. Ending program.");
			System.exit(1);
		}
			
}

	public String Competition()
	{

		int Count1 = 0;
		int Count2 = 0;
		int Count3 = 0;
		string name1 = JOptionPane.ShowInputDiolog(null,"What is the name of the first person?");
		string name2 = JOptionPane.ShowInputDiolog(null,"What is the name of the second person?");

				/* create Student objects for comparison */
		names n1 = new names(name1);
		names n2 = new names(name2);
		
		/* find their indices */
		int i1 = SearchName.binSearch(myNames,n1,myNames.length);
		int i2 = SearchName.binSearch(myNames,n2,myNames.length);
		
		
		while(Count1<11)
		{
			if(myNames[i1].getRanking(Count1) > myNames[i2].getRanking(Count1))
			{
				Count2++;
			}
		else 
			if(myNames[i1].getRanking(Count1) < myNames[i2].getRanking(Count1))
			{
				Count3++;
			}
			else
			{
				return JOptionPane.ShowMessageDialog(null, "That is an invalid name");
			}
		Count1++;
		}
		
		if(Count2>Count3)
			{
				JOptionPane.ShowMessageDialog(null, Name1 + "is more popular overall");
			}
		else
			{
				JOptionPane.ShowMessageDialog(null, Name2 + "is more popular overall");
			}
	}
	public int Top50()
	{

		names [] Top50 = new names[11];
		int count=0;
		
		
		
		/* look through entire student array and only remember those who got an A on test "test" */
		for(int i=0; i<numNames; i++)
		{
			if(count < 50)
			{
				Top50[count] = myNames[i];
				count++;
			}
		}
		
				/* sort list of A students by grade */
		SorterNames.selectionSort(Top50,count,rank);
		
		/* output list of A students to System.out.println */
		for(int i=0; i<count; i++)
		{
			JOptionPane.showInputDialog(null, "Here are the Top 50 Names");
			System.out.println(Top50[i]);
		}
	}

	public double Rankings()
	{
		Names Methods = new Names();
		String rank = JOptionPane.showInputDialog(null, "What is the name you want to see the rankings of?");
		
		int tempIndex = SearchName.binSearch(myNames,rank, myNames.length);
		if( tempIndex != -1)
			{
				return myNames[index].toString();
			}
	}
}
	
		
//get rank method
 //returns ranks(#)





Search Name Class
import javax.swing.*;
import java.io.*;

public class SearchName
{
   // return the index of target in the array which contains
   // numbers are indices 0..num-1. Return -1 if traget is not found. 
  public static double binSearch( names [] array, names target, double num)   
  {
     int startIndex = 0;   
     int endIndex = num - 1; 
     int middle;

     while ( endIndex >= startIndex ) 
     {
       middle = ( startIndex + endIndex )/ 2; //find new middle spot to look at 
			
       if (array[middle].equals(target))
             return middle;  //we found it!
       else if ( array[middle].compareTo(target)>0 ) //if we didn't find it, change end or start
            endIndex = middle - 1; 
       else
            startIndex = middle + 1;
     }
	  
     return -1;       // if we reached this line we didn't find it
  }

}




And my sorter Names class
import javax.swing.*;
import java.io.*;

// A class with a static sort method  
public class SorterNames
{
  /**  Uses Selection Sort to sort
  *      an integer array in ascending order
  *    @param array the array to sort
  *    @param n is the number of values in array (at indices  0..n-1)
  */
  public static void selectionSort( myNames [] array, int n, int rank )
  {
    Names temp; // temporary location for swap
    int max;  // index of maximum value in subarray

    for ( int i = 0; i < n; i++ )
    {
      // find index of largest value in subarray
      max = indexOfLargestElement( array, n - i, test );

      // swap array[max] and array[n ñ i - 1]
      temp = array[max];
      array[max] = array[n - i - 1];
      array[n - i - 1] = temp;
    }
  }

  /**  Finds index of largest element
  *    @param    size  the size of the subarray
  *    @ return  the index of the largest element in the subarray
  */
  private static int indexOfLargestElement( myNames [] array, int size, int rank )
  {
    int index = 0;
    for( int i = 1; i < size; i++ )
    {
       if ( array[i].compareToRank(array[index],rank) > 0 )
          index = i;
    }
    return index;
  }
}




I am having certain compile errors for most of these and any help or tips would be very appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Help with Array Related Java Program

#2 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon

Reputation: 5421
  • View blog
  • Posts: 8,717
  • Joined: 19-March 11

Re: Help with Array Related Java Program

Posted 29 April 2012 - 08:55 PM

Quote

I am having certain compile errors for most of these and any help or tips would be very appreciated.


Could you please provide the compiler output?
If we can see the errors, it's easier to diagnose them. :)
Was This Post Helpful? 0
  • +
  • -

#3 Jan714  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 29-April 12

Re: Help with Array Related Java Program

Posted 29 April 2012 - 09:10 PM

okay for the main i see no compile errors

For the Names Class:

Names.java:36: missing return statement
}
^
Names.java:41: missing return statement
}
^
Names.java:108: missing return statement
}
---------------
For the Processor Class.. This is the big one.
Processor.java:54: cannot find symbol
symbol : constructor Names(java.lang.String,double,double,double,double,double,double,double,double,double,double,double)
location: class Names
myNames[index] = new Names(name,year1,year2,year3,year4,year5,year6,year7,year8,year9,year10,year11);
^
Processor.java:59: cannot find symbol
symbol : variable numNames
location: class Processor
numNames = index;
^
Processor.java:76: cannot find symbol
symbol : class string
location: class Processor
string name1 = JOptionPane.ShowInputDiolog(null,"What is the name of the first person?");
^
Processor.java:76: cannot find symbol
symbol : method ShowInputDiolog(<nulltype>,java.lang.String)
location: class javax.swing.JOptionPane
string name1 = JOptionPane.ShowInputDiolog(null,"What is the name of the first person?");
^
Processor.java:77: cannot find symbol
symbol : class string
location: class Processor
string name2 = JOptionPane.ShowInputDiolog(null,"What is the name of the second person?");
^
Processor.java:77: cannot find symbol
symbol : method ShowInputDiolog(<nulltype>,java.lang.String)
location: class javax.swing.JOptionPane
string name2 = JOptionPane.ShowInputDiolog(null,"What is the name of the second person?");
^
Processor.java:80: cannot find symbol
symbol : class names
location: class Processor
names n1 = new names(name1);
^
Processor.java:80: cannot find symbol
symbol : class names
location: class Processor
names n1 = new names(name1);
^
Processor.java:81: cannot find symbol
symbol : class names
location: class Processor
names n2 = new names(name2);
^
Processor.java:81: cannot find symbol
symbol : class names
location: class Processor
names n2 = new names(name2);
^
Processor.java:84: cannot find symbol
symbol : variable myNames
location: class Processor
int i1 = SearchName.binSearch(myNames,n1,myNames.length);
^
Processor.java:84: cannot find symbol
symbol : variable myNames
location: class Processor
int i1 = SearchName.binSearch(myNames,n1,myNames.length);
^
Processor.java:85: cannot find symbol
symbol : variable myNames
location: class Processor
int i2 = SearchName.binSearch(myNames,n2,myNames.length);
^
Processor.java:85: cannot find symbol
symbol : variable myNames
location: class Processor
int i2 = SearchName.binSearch(myNames,n2,myNames.length);
^
Processor.java:90: cannot find symbol
symbol : variable myNames
location: class Processor
if(myNames[i1].getRanking(Count1) > myNames[i2].getRanking(Count1))
^
Processor.java:90: cannot find symbol
symbol : variable myNames
location: class Processor
if(myNames[i1].getRanking(Count1) > myNames[i2].getRanking(Count1))
^
Processor.java:95: cannot find symbol
symbol : variable myNames
location: class Processor
if(myNames[i1].getRanking(Count1) < myNames[i2].getRanking(Count1))
^
Processor.java:95: cannot find symbol
symbol : variable myNames
location: class Processor
if(myNames[i1].getRanking(Count1) < myNames[i2].getRanking(Count1))
^
Processor.java:101: cannot find symbol
symbol : method ShowMessageDialog(<nulltype>,java.lang.String)
location: class javax.swing.JOptionPane
return JOptionPane.ShowMessageDialog(null, "That is an invalid name");
^
Processor.java:108: cannot find symbol
symbol : variable Name1
location: class Processor
JOptionPane.ShowMessageDialog(null, Name1 + "is more popular overall");
^
Processor.java:108: cannot find symbol
symbol : method ShowMessageDialog(<nulltype>,java.lang.String)
location: class javax.swing.JOptionPane
JOptionPane.ShowMessageDialog(null, Name1 + "is more popular overall");
^
Processor.java:112: cannot find symbol
symbol : variable Name2
location: class Processor
JOptionPane.ShowMessageDialog(null, Name2 + "is more popular overall");
^
Processor.java:112: cannot find symbol
symbol : method ShowMessageDialog(<nulltype>,java.lang.String)
location: class javax.swing.JOptionPane
JOptionPane.ShowMessageDialog(null, Name2 + "is more popular overall");
^
Processor.java:118: cannot find symbol
symbol : class names
location: class Processor
names [] Top50 = new names[11];
^
Processor.java:118: cannot find symbol
symbol : class names
location: class Processor
names [] Top50 = new names[11];
^
Processor.java:124: cannot find symbol
symbol : variable numNames
location: class Processor
for(int i=0; i<numNames; i++)
^
Processor.java:128: cannot find symbol
symbol : variable myNames
location: class Processor
Top50[count] = myNames[i];
^
Processor.java:134: cannot find symbol
symbol : variable rank
location: class Processor
SorterNames.selectionSort(Top50,count,rank);
^
Processor.java:149: cannot find symbol
symbol : variable myNames
location: class Processor
int tempIndex = SearchName.binSearch(myNames,rank, myNames.length);
^
Processor.java:149: cannot find symbol
symbol : variable myNames
location: class Processor
int tempIndex = SearchName.binSearch(myNames,rank, myNames.length);
^
Processor.java:152: cannot find symbol
symbol : variable myNames
location: class Processor
return myNames[index].toString();
^
Processor.java:152: cannot find symbol
symbol : variable index
location: class Processor
return myNames[index].toString();
^
SearchName.java:20: cannot find symbol
symbol : method compareToRank(Names)
location: class SearchName
else if ( array[middle].compareToRank(target)>0 ) //if we didn't find it, change end or start
^
----------------
For the Search name Class:

SearchName.java:20: cannot find symbol
symbol : method compareToRank(Names)
location: class SearchName
else if ( array[middle].compareToRank(target)>0 ) //if we didn't find it, change end or start
^
1 error
--------------
And right now none for the Sorter Name class
Was This Post Helpful? 0
  • +
  • -

#4 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon

Reputation: 5421
  • View blog
  • Posts: 8,717
  • Joined: 19-March 11

Re: Help with Array Related Java Program

Posted 29 April 2012 - 09:22 PM

Okay, starting at the top of the list, if you look at line 36 of the Names class, you'll see that you're at the end of a method which promises to return a String and does not do so. You'll have to either return a String or change the return type.

You probably also want to give that method an access modifier, public or private, since I'm willing to bet you don't mean to use the "package-private" access.

Do other classes get to call this? If so, make it public. Otherwise, make it private.

There are some obvious ones there. Please have a go at fixing stuff like this for yourself:

Quote

Processor.java:59: cannot find symbol
symbol : variable numNames
location: class Processor
numNames = index;
^


That means exactly what it says: the compiler can't find a symbol called numNames. Why do you think that is?

Try to find the obvious ones and fix them. That'll get this down to a manageable problem, at least.
Was This Post Helpful? 0
  • +
  • -

#5 Jan714  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 29-April 12

Re: Help with Array Related Java Program

Posted 29 April 2012 - 09:29 PM

Thanks, i actually did go, and because i was working with a partner for this one I didnt see those small mistakes. I was probably just overwhelmed by the number. At the moment i have it down to 17 problems. Thank you very much.
Was This Post Helpful? 0
  • +
  • -

#6 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon

Reputation: 5421
  • View blog
  • Posts: 8,717
  • Joined: 19-March 11

Re: Help with Array Related Java Program

Posted 29 April 2012 - 09:32 PM

Okay, keep slashing at them. When you find you're really stuck, bring the residue and we'll have another look.
Was This Post Helpful? 0
  • +
  • -

#7 Jan714  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 29-April 12

Re: Help with Array Related Java Program

Posted 29 April 2012 - 10:11 PM

So i fixed almost everything except 7 errors in the processor class in which i am really stuck on.

here is the code:

public class Processor
{

	int numNames;
	Names[] myNames;
	File myFile;
	
	public void readData()
{
	
	int names;
	int count = 0;
	final int NUM_NAMES = 11; //number of grades to read & store
	int index = 0; //where in the student array to insert next
	String name; //declare name variable to hold name that is read from file
	double[] names3 = new double[NUM_NAMES];
		double year1 = 0;
		double year2 = 0;
		double year3 = 0;
		double year4 = 0;
		double year5 = 0;
		double year6 = 0;
		double year7 = 0;
		double year8 = 0;
		double year9 = 0;
		double year10 = 0;
		double year11 = 0;
	
try{
		Scanner scan = new Scanner(myFile);
			
			/* read and store all data */
		while(scan.hasNext())
			{
				/* read in each line */
		name = scan.next(); //read in name
				
		year1 = scan.nextDouble();
		year2 = scan.nextDouble();
		year3 = scan.nextDouble();
		year4 = scan.nextDouble();
		year5 = scan.nextDouble();
		year6 = scan.nextDouble();
		year7 = scan.nextDouble();
		year8 = scan.nextDouble();
		year9 = scan.nextDouble();
		year10 = scan.nextDouble();
		year11 = scan.nextDouble();
									
				/* add to array */
		myNames[index] = new Names(name,year1,year2,year3,year4,year5,year6,year7,year8,year9,year10,year11);
			index++;
		}//end of while
			
			numNames = index;
	}//end of try
	
	catch(IOException e)
		{
			System.err.println("Error opening file. Ending program.");
			System.exit(1);
		}
			
}

	public String Competition()
	{

		int Count1 = 0;
		int Count2 = 0;
		int Count3 = 0;
		String name1 = JOptionPane.showInputDialog(null,"What is the name of the first person?");
		String name2 = JOptionPane.showInputDialog(null,"What is the name of the second person?");

		Names n1 = new Names(name1);
		Names n2 = new Names(name2);
		
		int i1 = SearchName.binSearch(myNames,n1,myNames.length);
		int i2 = SearchName.binSearch(myNames,n2,myNames.length);
		
		
		while(Count1<11)
		{
			if(myNames[i1].getRanking(Count1) > myNames[i2].getRanking(Count1))
			{
				Count2++;
			}
		else 
			if(myNames[i1].getRanking(Count1) < myNames[i2].getRanking(Count1))
			{
				Count3++;
			}

		Count1++;
		}
		
		if(Count2>Count3)
			{
				JOptionPane.showMessageDialog(null, name1 + "is more popular overall");
			}
		else
			{
				JOptionPane.showMessageDialog(null, name2 + "is more popular overall");
			}
	}
	public int Top50()
	{

		Names [] Top50 = new Names[11];
		int count=0;
		
		
		
		for(int i=0; i<numNames; i++)
		{
			if(count < 50)
			{
				Top50[count] = myNames[i];
				count++;
			}
		}
		
		SorterNames.selectionSort(Top50,count,rankings);
		
		for(int i=0; i<count; i++)
		{
			JOptionPane.showInputDialog(null, "Here are the Top 50 Names");
			System.out.println(Top50[i]);
		}
	}

	public double Rankings()
	{
		Names Methods = new Names();
		String rank = JOptionPane.showInputDialog(null, "What is the name you want to see the rankings of?");
		
		int tempIndex = SearchName.binSearch(myNames,rank,myNames.length);
		if( tempIndex != -1)
			{
				return myNames[index].toString();
			}
	}
}
	




and here are the errors that it gives me:

Processor.java:56: cannot find symbol
symbol : constructor Names(java.lang.String,double,double,double,double,double,double,double,double,double,double,double)
location: class Names
myNames[index] = new Names(name,year1,year2,year3,year4,year5,year6,year7,year8,year9,year10,year11);
^
Processor.java:80: cannot find symbol
symbol : constructor Names(java.lang.String)
location: class Names
Names n1 = new Names(name1);
^
Processor.java:81: cannot find symbol
symbol : constructor Names(java.lang.String)
location: class Names
Names n2 = new Names(name2);
^
Processor.java:128: cannot find symbol
symbol : variable rankings
location: class Processor
SorterNames.selectionSort(Top50,count,rankings);
^
Processor.java:142: binSearch(Names[],Names,int) in SearchName cannot be applied to (Names[],java.lang.String,int)
int tempIndex = SearchName.binSearch(myNames,rank,myNames.length);
^
Processor.java:145: cannot find symbol
symbol : variable index
location: class Processor
return myNames[index].toString();
^
Processor.java:145: incompatible types
found : java.lang.String
required: double
return myNames[index].toString();
^
7 errors
Was This Post Helpful? 0
  • +
  • -

#8 Jan714  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 29-April 12

Re: Help with Array Related Java Program

Posted 29 April 2012 - 10:39 PM

Okay so now i am encountering only two errors in this processor file. In the last line, the toString method, when i delete the index in the brackets of the myNames array, there are only two errors. when i put index in the brackets [] then there are the errors given above.

here are the errors when i leave "index" out the array:
Processor.java:146: class expected
return myNames[].toString();
^
Processor.java:146: ';' expected
return myNames[].toString();
^
2 errors
Was This Post Helpful? 1
  • +
  • -

#9 collegekid901  Icon User is offline

  • New D.I.C Head

Reputation: 8
  • View blog
  • Posts: 41
  • Joined: 09-March 12

Re: Help with Array Related Java Program

Posted 29 April 2012 - 10:50 PM

Looks like your method return type is wrong. The method says you should be returning a double but you are returning a string
Was This Post Helpful? 1
  • +
  • -

#10 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon

Reputation: 5421
  • View blog
  • Posts: 8,717
  • Joined: 19-March 11

Re: Help with Array Related Java Program

Posted 29 April 2012 - 10:50 PM

Good work. That's a lot of errors to clear away.

This last one is a little complicated. Not sure if I can explain it coherently at this hour, so I'll be brief. myNames is the name of an array. myNames[] would suggest an array of myNames objects, but since myNames isn't an object, the compiler thinks you're trying to do something weird, and it doesn't like it. Hence, error messages.

If you want to refer to one element of the array, use an index in brackets. If you want to refer to the array as a whole, use the name of the array alone, with no brackets. You probably don't want to refer to the array as a whole here, since you'll get the default toString, and that's not anything you want.

Not to mention, as collegeKid points out, unless you've radically changed your code since your last posting, you don't want to return a String there.

This post has been edited by jon.kiparsky: 29 April 2012 - 10:51 PM

Was This Post Helpful? 0
  • +
  • -

#11 Jan714  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 29-April 12

Re: Help with Array Related Java Program

Posted 29 April 2012 - 11:17 PM

So how would i return the string?
Was This Post Helpful? 0
  • +
  • -

#12 collegekid901  Icon User is offline

  • New D.I.C Head

Reputation: 8
  • View blog
  • Posts: 41
  • Joined: 09-March 12

Re: Help with Array Related Java Program

Posted 29 April 2012 - 11:20 PM

I didn't read your whole code so not exactly sure exactly what you want to do there but if you want that method to return a string change public double Rankings() to public String Ranking()
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1