1

when i try to print my competitor names i have this value returning Name@75b84c92 can anyone explain why? i'm a complete beginner at java and this assignment is due in next week. i have no errors in my code but can't understand why the name isn't printing. i'm not sure if i have a problem with calling another class

can anyone help?

public class Competitor {
//create instance variables
    private int competitorNumber;
    private Name competitorName;
    private String competitorLevel;
    private String competitorCountry;
    int[] competitorScore;


    //create constructor 

    public Competitor(int number, Name name, String level, String      country, int[] score) {
        competitorNumber = number;
        competitorName = name;
        competitorLevel = level;
        competitorCountry = country;
        competitorScore = score;

    }



    public Name  getCompetitorName() {
        return competitorName;
    }

    public class CompetitorMain {

    public static void main(String[] args) {




        int[] SRScores = {4,5,4,3,3};
        Competitor sonkeRothenburger = new Competitor (104, new Name    ("Sonke", "Rothenburger"), "Inter 1", "Germany", SRScores);

        int[] LGScores = {5,4,5,4,3};
        Competitor lauraGraves = new Competitor (105, new Name ("Laura", "Verdades"), "Inter 1", "USA", LGScores);

    System.out.println(sonkeRothenburger.getCompetitorName());


public class Name {

private String firstName;
private String middleName;
private String lastName;




    public String getFullName() {
        if (middleName.isEmpty()) { return "" + firstName + lastName;
        }
        else {return "" + firstName + middleName + lastName;
        }
    }

public Name(String firstName,String lastName, String middleName) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.middleName = middleName;
}
public Name(String firstName, String lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.middleName = "";
}
em456
  • 359
  • 2
  • 11
  • `Name` is an object, so what you are seeing is the default `Object.toString()`. Add a `.toString()` method on your `Name` class. – KevinO Oct 11 '18 at 21:48

1 Answers1

0

You try to print object, but you don't override toString(). Override method or get all parts of object and print it.

Egor
  • 1,334
  • 8
  • 22