Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6072903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:12:40+00:00 2026-05-23T10:12:40+00:00

In the code below. I a trying to allow the user to enter entries

  • 0

In the code below. I a trying to allow the user to enter entries into the program. Right now they can only add one entry into the program. How can I edit it so the user can have the option to enter another entry into the program.

Example of output:
Enter ID: 444
Enter FName: John
Enter Lname: Thompson

Would you like to enter another entry Y/N?Y
Enter ID:1
Enter FName: Gail
Enter Lname: Jennings

Would you like to enter another entry Y/N?N

If yes is clicked I want to add the gathered data into the binary tree and allow the user to enter another id. How can I do that?

import java.util.Scanner;

class clubmember {

    public static void main(String[] args) {

        int id;
         String fname, lname;
         Scanner input = new Scanner(System.in);

         System.out.println("Enter ID>");
         id = input.nextInt();

         System.out.println("Enter first name >");
         fname = input.next();

         System.out.println("Enter last name >");
         lname = input.next();



         BinaryTreeTest foo = new BinaryTreeTest(); 


           Person per1 = new Person(id, fname, lname);
           BinaryTreeTest.Node nod1 = new BinaryTreeTest.Node(per1);

           Person per2 = new Person(734, "Smith", "Rick");
           Person per3 = new Person(324, "Gates", "Jill");

           foo.insert(nod1, per2);
           foo.insert(nod1, per3);

           foo.printInOrder(nod1);


    }
}



public class BinaryTreeTest {

  public static void main(String[] args) {

    new BinaryTreeTest().run();
  }

  // Node Class
  static class Node {
    Node left;

    Node right;

    Person value;

    public Node(Person value) {
      this.value = value;
    }
  }

  public void run() {

  }

  public void insert(Node node, Person value) {
    if (value.getId() < node.value.getId()) {
      if (node.left != null) {
        insert(node.left, value);
      } else {
        System.out.println("  Inserted " + value + " to left of "
            + node.value);
        node.left = new Node(value);
      }
    } else if (value.getId() > node.value.getId()) {
      if (node.right != null) {
        insert(node.right, value);
      } else {
        System.out.println("  Inserted " + value + " to right of "
            + node.value);
        node.right = new Node(value);
      }
    }
  }

  public void printInOrder(Node node) {
    if (node != null) {
      printInOrder(node.left);
      System.out.println("  Traversed " + node.value);
      printInOrder(node.right);
    }
  }
}


public class Person {
    private final int id;
    private final String firstName;
    private final String lastName;


    public Person(int id, String firstName, String lastName) {
        this.id = id;
        this.firstName = firstName;
        this.lastName = lastName;
    }

    public int getId() {
        return id;
    }

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }

    @Override
    public String toString() {
        return String.valueOf(id) + ": " + firstName + " " + lastName;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:12:41+00:00Added an answer on May 23, 2026 at 10:12 am

    Consider using a do { ... } while () loop. Something like

    boolean more;
    do {
      insertOneUser();
      System.out.println("Add another?");
      more = "y".equals(input.next().toLowerCase());
    } while (more);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add functionality to a webpage that will allow the user
I have the code below in an attempt to allow the user to Step
I am trying to write a program where my brother and I can enter
In the code below i`m trying to read a list of selected projects and
In the code below I'm trying to load some images and put them in
Afternoon all, Using the code below I'm trying to load what is render by
The code below is what I am trying to use in order to get
I'm trying to use the code below to send messages via System.Net.Mail and am
I am trying to run the code below but it keeps locking up my
I am trying to port the code below to mootools 1.1 code but am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.