I'm running into a problem here. I was told to initialize values through a parameterized constructor. Write a method "getInput" to take in values for these attributes, call the parameterized constructor and then return a Child object.
I think this is what I did...but when I call the method i get something like this: Child@75d9fd51 Is this just the object reference? I'm trying to get it to print the inputted age, name and grade. Thank you in advance!
So far this is what i have:
import java.util.Scanner;
class Child{
int age;
String name;
char grade;
public Child(){
}
public Child(int age, String name, char grade) {
this.age = age;
this.name = name;
this.grade = grade;
}
public int getAge() {
return age;
}
public void setAgel(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public char getGrade() {
return grade;
}
public void setGrade(char grade) {
this.grade = grade;
}
}
public class Data {
public static Child getInput(Child s){
Scanner input = new Scanner(System.in);
System.out.println("Input age: ");
int age = input.nextInt();
System.out.println("Input name: ");
String name = input.next();
System.out.println("Input grade: ");
char grade = input.next().charAt(0);
s = new Child(age, name, grade);
return s;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Child x = new Child(20, "James", 'A'); //I want this to be changed with input
getInput(x);
System.out.print(x);
}