I was trying to make a program that asks the user to create a person or a group of persons and assign names and age to them. So I made a constructor "Try" and a method "AskUser". In AskUser(), I use a do/while loop where user is asked to input a name, an age and if he likes to create another person. Now how do I take the input data each time the loop runs, and send it to constructor to create new objects with it? And how these new objects will be called?

import java.util.Scanner;
public class Try{
    static String name;
    static int age;
    static Scanner a = new Scanner(System.in);
    static Scanner b = new Scanner(System.in);
    static Scanner c = new Scanner(System.in);

    public Try(String name, int age){
       this.age= age;
       System.out.println("this is "+name+", and he is "+age+" old.");

    public static void AskUser(){
       int x=0;
          System.out.print("what's the name of the person ?");
          name= a.nextLine();
          System.out.print("how old is he? ");
          age= b.nextInt();
          System.out.print("would u like to creat another person ");
          String yes = c.nextLine();

   public static void main (String[] args)

Related posts

Recent Viewed