Results 1 to 9 of 9
  1. #1
    mmonish91 is offline Member
    Join Date
    May 2010
    Posts
    6
    Rep Power
    0

    Angry Ordered Vector Issue

    Java Code:
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    
    public class OrdVectOfScores{
    
    	private int size;
    	private final int capacity;
    	private Score[] theScores;
    	
    	public OrdVectOfScores (){	
    		this.size = 0;
    		this.capacity = 5;
    	}
    	
    	String[] initials = new String[5];
    	long[] points = new long [5];			
    	Scanner in = new Scanner(System.in);
    				
    	//Reads the data from the file
    	public void readInitialFromFile(){
    		Scanner reader = null;
    		try{			
    			reader = new Scanner(new File("highscores.txt"));
    			}
    		catch(Exception e){
    			System.out.println("Could not locate the file.");
    		}
    		int i;
    		while (reader.hasNextLine()); 
    			if (capacity != 0){
    				String s = reader.nextLine();
    				String[] temp = new String [2];
    				temp = s.split(" ");
    					for (i = 0; i< size; i++) 
    						initials[i] = temp[0];
    						points[i] = temp [1];
    			
    			}
    		//System.out.println();
    		reader.close();
    	}*/
    	
    	/*Writes the new or updated data to the file
    	public void writeFinalToFile(){
    		BufferedWriter writer = null;        
         	try {           
          	writer = new BufferedWriter(new FileWriter("highscores.txt"));
       		}
    		catch (Exception e){
    			System.out.println("Could not locate the file.");
    		}
    	}*/
    	
    	/*public void addScore(Score sc){
    		//sc= tmp;
    		if (size == capacity && sc < theScores[size-1])
    			System.out.println("You did not make it to the Top 5. Sorry, Try Again!");
    		else
    			if (size != capacity)
    				//theScoresVec.add();
    				System.out.println("Congratulations! You made it to the Top 5.");
    		}*/
    
    	//public void showByInit(String init){
    		//for (int i= 0, i<theScores.length, i++)
    			//input= in.nextLine();
    	//}
    
    	/*public void showAbove(int limit){
    	}*/
    }


    As You guys can tell, there is alot of problems with this code. I am very new to this and am in dire need of help! Also how would i put 2 different types of variable in same index of an array.
    For example: int number and string name ( i want them in same index of an array).

    Thanks in Advance!
    Last edited by Eranga; 03-07-2012 at 05:26 AM. Reason: code taggs added

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default Re: Ordered Vector Issue

    So what is your question, what happen when compile and run this code? Did you try that?

  3. #3
    mmonish91 is offline Member
    Join Date
    May 2010
    Posts
    6
    Rep Power
    0

    Default Re: Ordered Vector Issue

    Yes i compiled but i am getting several errors. I am getting this error at line 37
    OrdVectOfScores.java:40: incompatible types

    Thanks for the tags..i didnt know how to do that!

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default Re: Ordered Vector Issue

    Can you please post the complete error message you end-up with. I don't know what you have on line 40.

  5. #5
    mmonish91 is offline Member
    Join Date
    May 2010
    Posts
    6
    Rep Power
    0

    Default Re: Ordered Vector Issue

    OrdVectOfScores.java:40: incompatible types
    found : java.lang.String
    required: long
    points[i] = temp [1];

    Sorry!

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default Re: Ordered Vector Issue

    Oh yes, you have the issue on

    Java Code:
    points[i] = temp [1];

    points is a an array of type long, and you try to assign string. Where temp is a string array. You cannot do that. You have to convert them properly.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default Re: Ordered Vector Issue

    I have notice that there is another issue too. Its not a coding issue but it occurs because of bad practice. Try to figure it out, if not let me know. :)

  8. #8
    mmonish91 is offline Member
    Join Date
    May 2010
    Posts
    6
    Rep Power
    0

    Default Re: Ordered Vector Issue

    Okay let me explain you my project. I have to write a code that reads, writes, and displays top 5 scores in a vector and a linked list. The field for the scores are String Initials and Long Points, How would i make these 2 fit in one index of an array and then convert it to a vector.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Regular Expression issue and setName() method issue
    By geforce in forum New To Java
    Replies: 2
    Last Post: 01-30-2012, 04:33 AM
  2. Ordered list - inserting wherever on the list
    By Mnem in forum New To Java
    Replies: 6
    Last Post: 01-10-2011, 01:21 PM
  3. Ordered Array plz help....due tomorrow!!
    By canyonist in forum New To Java
    Replies: 6
    Last Post: 05-23-2010, 10:57 AM
  4. Vector<vector> loop thru
    By ocean in forum New To Java
    Replies: 11
    Last Post: 11-21-2009, 03:17 PM
  5. viewing records ordered by date
    By nitish.dhar in forum New To Java
    Replies: 3
    Last Post: 07-31-2008, 08:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •