Results 1 to 3 of 3
  1. #1
    zniightmare is offline Member
    Join Date
    Feb 2012
    Posts
    19
    Rep Power
    0

    Default Weird output from Array program

    Hi, I was just curious to why I am receiving a weird output.

    Output:
    GradeBook@5a8a0d5d

    Java Code:
    import java.util.Scanner;
    
    public class GradeBook {
    
    	private char[] letterGrade = new char[5];
    	private String[] studentNames = new String[2];
    	private double[] scores1 = new double[5];
    	private double[] scores2 = new double[5];
    	private double[] scores3 = new double[5];
    	private double[] scores4 = new double[5];
    	int count = 0;
    
    	
    	Scanner keyboard = new Scanner(System.in);
    
    	public void enterInformation(){
    		for(int i = 0; i < studentNames.length; i++){
    		System.out.print("Enter name of Student: ");
    		String name = keyboard.nextLine();
    		System.out.print("Enter student's 1st Test Score: ");
    		double score1 = Double.parseDouble(keyboard.nextLine());
    		System.out.print("Enter student's 2nd Test Score: ");
    		double score2 = Double.parseDouble(keyboard.nextLine());
    		System.out.print("Enter student's 3rd Test Score: ");
    		double score3 = Double.parseDouble(keyboard.nextLine());
    		System.out.print("Enter student's 4th Test Score: ");
    		double score4 = Double.parseDouble(keyboard.nextLine());
    		addStudent(name, score1, score2, score3, score4);
    		}
    	}
    	
    	public String toSting(){
    		StringBuilder z = new StringBuilder();
    		for(int i = 0; i < studentNames.length; i++){
    			if(studentNames[i] == null)
    				continue;
    			z.append("Name: " + studentNames[i] + "\n" +
    					"Average score: " + getAverage(i) +
    					"\n" + "Grade: " + letterGrade[i] + "\n");
    		}
    		return z.toString();
    	}
    	
    	
    	private void addStudent(String name, double score1, double score2, double score3, double score4){
    			studentNames[count] = name;
    			scores1[count] = score1;
    			scores2[count] = score2;
    			scores3[count] = score3;
    			scores4[count] = score4;
    			letterGrade[count] = getLetter(count);
    			count++;
    	}
    	
    	
    	private double getAverage(int count){
    		
    		double score1 = scores1[count];
    		double score2 = scores2[count];
    		double score3 = scores3[count];
    		double score4 = scores4[count];
    		double average = (score1 + score2 + score3 + score4)/4.0;
    		return average;
    	}
    	
    	private char getLetter(int counter){
    		
    		double average = getAverage(counter);
    		char letter = 'z';
    		
    		if(average > 89.0)
    			letter = 'A';
    		else if(average > 79.0)
    			letter = 'B';
    		else if(average > 69.0)
    			letter = 'C';
    		else if(average > 59.0)
    			letter = 'D';
    		else 
    			letter = 'F';
    		
    		
    		return letter;
    	}
    	
    	public static void main(String[] args) {
    		GradeBook testing = new GradeBook();
    		testing.enterInformation();
    		System.out.println(testing);
    	}
    	
    }

  2. #2
    zniightmare is offline Member
    Join Date
    Feb 2012
    Posts
    19
    Rep Power
    0

    Default Re: Weird output from Array program

    just trying to figure out what this mean exactly. Tried searching in google but I have not found anything.

  3. #3
    adjit is offline Senior Member
    Join Date
    Mar 2011
    Posts
    171
    Rep Power
    0

    Default Re: Weird output from Array program

    I believe that is the spot in memory where what you are trying to print belongs. It isn't the actual things within an array.
    Like if I try System.out.print(x) and x is an array it will give me some funny looking thing like that
    but if I print System.out.print(x[i]) it will print the value at that index

Similar Threads

  1. Getting weird characters when trying to write output to file
    By Rabid Hamster in forum New To Java
    Replies: 3
    Last Post: 01-24-2012, 05:10 PM
  2. Weird array output
    By Army in forum New To Java
    Replies: 3
    Last Post: 01-17-2012, 07:58 AM
  3. Weird output
    By gandalf5166 in forum New To Java
    Replies: 2
    Last Post: 02-28-2010, 10:17 PM
  4. Seriously weird output
    By gandalf5166 in forum Java Applets
    Replies: 4
    Last Post: 02-27-2010, 05:16 AM
  5. Weird data output
    By Shaolin in forum New To Java
    Replies: 12
    Last Post: 12-11-2007, 05:27 PM

Posting Permissions

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