Answer to Question #281069 in Java | JSP | JSF for rubix

Question #281069

In a school there are students and teachers, but they all are persons. An every “Person” has attributes “name”, “age” and “gender”. Every person should have a method to set their details(setPersonDetails()) and to print their details(printPersonDetails()).


1
Expert's answer
2021-12-20T09:54:47-0500


import java.util.Scanner;


class Person {
	private String name;
	private int age;
	private String gender;


	public void setPersonDetails() {
		Scanner keyBoard = new Scanner(System.in);
		System.out.print("Enter the name: ");
		name = keyBoard.nextLine();
		System.out.print("Enter the age: ");
		age = keyBoard.nextInt();
		keyBoard.nextLine();
		System.out.print("Enter the gender: ");
		gender = keyBoard.nextLine();
		keyBoard.close();
	}


	public void printPersonDetails() {
		System.out.println("The name: " + name);
		System.out.println("The age: " + age);
		System.out.println("The gender: " + gender);
	}


}


public class App {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		Person p=new Person();
		p.setPersonDetails();
		p.printPersonDetails();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog