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

  • Home
  • SEARCH
  • 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 8893197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:11:10+00:00 2026-06-14T23:11:10+00:00

I have an assignment to carry out using BlueJ where I am given a

  • 0

I have an assignment to carry out using BlueJ where I am given a class called HW4CustomerList and I must create a Text-Based UI for it. The class I have to create is called CustomerTUI and contains a method called addCustomer which adds a new Customer object of mine to an ArrayList. This method in particular is what I am stuck with. The class specification says that I cannot take any parameters (i.e. a no-args method). In previous work we have used the BlueJ ‘method box’ to interact with objects and add them to ArrayLists, however I do not know if this can be used in this particular instance. Please find below my code so far for CustomerTUI and the code for the Customer class and HW4CustomerList class. Many thanks in advance.

CustomerTUI class:

import java.util.Scanner;

public class CustomerTUI
{
private HW4CustomerList customerList;
private Scanner myScanner;

public CustomerTUI()
{
    customerList = new HW4CustomerList();
    myScanner = new Scanner(System.in);
}

public void menu()
{
    int command;
    boolean running = true;

    while(running)
    {
        displayMenu();
        command = getCommand();
        execute(command);
    }
}

private void addCustomer()
{
    customerList.addCustomer();
}

private void displayMenu()
{
    System.out.println("            CustomerList program         ");
    System.out.println("=========================================");
    System.out.println("|Add a customer to the list..........[1]|");
    System.out.println("|Get number of customers.............[2]|");
    System.out.println("|Remove a customer from the list.....[3]|");
    System.out.println("|Show all customer details...........[4]|");
    System.out.println("|Show a specific customers details...[5]|");
    System.out.println("|Quit................................[6]|");
    System.out.println("=========================================");
}

private void execute(int command)
{
    if(command == 1)
    {
        addCustomer();
    }

    else if(command == 2)
    {
        getNumberOfCustomers();
    }

    else if(command == 3)
    {
        removeCustomer();
    }

    else if(command == 4)
    {
        showAllCustomers();
    }

    else if(command == 5)
    {
        showCustomer();
    }

    else if(command == 6)
    {
        quitCommand();
    }

    else
    {
        unknownCommand(command);
    }
}

private int getCommand()
{
    System.out.println("Enter the command of the function you wish to use: ");
    int command = myScanner.nextInt();
    return command;
}

private void getNumberOfCustomers()
{
    if(customerList.getNumberOfCustomers() == 1)
    {
        System.out.println("We have " + customerList.getNumberOfCustomers() + " customer.");
    }
    else
    {
        System.out.println("We have " + customerList.getNumberOfCustomers() + " customers.");
    }
}

private void quitCommand()
{
    System.out.println("The program is now closing down...");
    System.exit(0);
}

private void removeCustomer()
{
    String accNo;

    System.out.println("Enter the account number of the customer you wish to remove: ");
    accNo = myScanner.next();
    if (customerList.removeCustomer(accNo) == true)
    {
        System.out.println("Customer with account number " + accNo + " was successfully removed.");
    }
    else
    {
        System.out.println("Customer with account number " + accNo + " was NOT successfully removed.");
        System.out.println("Please try again.");
    }
}

private void showAllCustomers()
{
    customerList.getAllCustomers();
}

private void showCustomer()
{
    String accNo;

    System.out.println("Enter the account number of the customer you wish to view: ");
    accNo = myScanner.next();
    if(customerList.getCustomer(accNo) == false)
    {
        System.out.println("Could not find customer with account number " + accNo + ".");
    }
    else
    {
        return;
    }
}

private void unknownCommand(int command)
{
    System.out.println("Command number " + command + " is not valid. Please try again.");
}
}

HW4CustomerList class:

import java.util.*;

public class HW4CustomerList
{
private ArrayList<Customer> customers;    

public HW4CustomerList()
{
   customers = new ArrayList<Customer>();
}

public void addCustomer(Customer customer)
{
    customers.add(customer);
}

public int getNumberOfCustomers()
{
    return customers.size();
}

public boolean getCustomer(String accountNumber)
{
   for(Customer customer : customers)
   {
       if(accountNumber.equals(customer.getAccountNumber()))
       {
          customer.printCustomerDetails();
          return true;
      }
  }
  return false;
}


public void getAllCustomers()
{
    for(Customer customer : customers)
    {
        customer.printCustomerDetails();
        System.out.println("\n");
    }
}


public boolean removeCustomer(String accountNumber)
{
     int index = 0;
     for (Customer customer: customers)
     {
          if (accountNumber.equals(customer.getAccountNumber()))
        {
            customers.remove(index);
            return true;
        }
        index++;
    }
    return false;
}
}
  • 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-06-14T23:11:11+00:00Added an answer on June 14, 2026 at 11:11 pm

    I think all you need to do is create a new Customer object in your addCustomer() method. This would probably require getting additional details:

    public void addCustomer()
    {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter customer name: ");
        String name = scanner.nextLine();
        //any additional details
        Customer customer = new Customer(name, otherParams);
        customers.add(customer);
    }
    

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assignment to create a GUI using MATLAB GUIDE and am having
I have an assignment in a language-independent class, and part of it is using
I have an assignment to write some numbers in a text file using PrintStream
I have an assignment to create a secure communication between 2 people with a
I have an assignment to learn how to use boost::variant. I'm trying to create
I have an assignment from my programming class, which is very poorly worded... The
I have an assignment to use JavaBeans to create an online Banking application. I
I have an assignment for my first OOP class, and I understand all of
I have an assignment that requires us to implement a doubly linked list class.
I have assignment using R and have a little problem. In the assignment several

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.