. develop a java application that uses a class called person which has 2 functions: getdata() and putdata(). The getdata() prompts the user to enter his or her first name, last name and age, the putdata() displays on the screen the user first name last, name and age.
import java.util.Scanner;
public class Person {
private String firstName;
private String lastName;
private int age;
public void getData() {
Scanner in = new Scanner(System.in);
System.out.println("Enter your first name:");
firstName = in.nextLine();
System.out.println("Enter your last name:");
lastName = in.nextLine();
System.out.println("Enter your age:");
age = in.nextInt();
}
public void putData() {
System.out.println(firstName + " " + lastName + " of the age " + age);
}
}
public class Main {
public static void main(String[] args) {
Person person = new Person();
person.getData();
person.putData();
}
}
Comments
good
Leave a comment