-3

I am trying to print out the whole of the "f" variables in one line of code.. f obviously standing for female but when I use the way I have code it is showing errors?

I am sorry, i am beginner.

import java.util.*;

class university {
    public static void main(String[] args){
            Scanner scanner = new Scanner(System.in);
            Person2 mPerson, fPerson = null;`

        String fFirstName, fSurname, mFirstName, mSurname;
        int fAge, mAge;

        System.out.println("Please enter the firstname of your favourite female author");
        fFirstName = scanner.nextLine();
        System.out.println("Please enter her second name");
        fSurname = scanner.nextLine();
        System.out.println("Please enter her age");
        fAge = scanner.nextInt();
        scanner.nextLine();

        System.out.println("Please enter the firstname of your favourite female author");
        mFirstName = scanner.nextLine();
        System.out.println("Please enter her second name");
        mSurname = scanner.nextLine();
        System.out.println("Please enter her age");
        mAge = scanner.nextInt();

        fPerson = new Person2(fFirstName, fSurname, fAge);

        System.out.print(fPerson);
    }
}
sdanzig
  • 4,510
  • 1
  • 23
  • 27
Ceri Westcott
  • 59
  • 1
  • 8

2 Answers2

4

The problem you have is that you did not read any tutorial about Java and you try to solve the upcoming issue blinded.

The problem you face is that you did not declared a place where the computer gets the information you expect him to have. The coding is not a magic thing, you get what have you wrote.

What you are missing is implementation of toString() method in your Person2 class.

@Override
public String toString() {
 return fFirstName 
}

Do not loose more time to solve platform issues and try to read a the trial.

0

Implement toString() method for Person class, just printing the object won't print the values.

public String toString() {
   //format the way you want the values to be printed
   return fFirstName + " " + fSurname + " " + fAge;
}
Abdullah Shaikh
  • 2,567
  • 6
  • 30
  • 43