Java Class for Customer Management

Java Class for Customer Management

This code defines a Java class named ClientesSC designed to manage customer data, including their names, ID numbers (DNI), phone numbers, and debts.

Class Attributes

  • ArrayList<ClientesSC> aprobar: Stores instances of ClientesSC.
  • Scanner src: Used for reading input from the console.
  • String nombre: Stores the customer’s name.
  • String dni: Stores the customer’s ID number (DNI).
  • int tlf: Stores the customer’s phone number.
  • int deuda: Stores the customer’s debt.

Constructors

  • ClientesSC(): Default constructor.
  • ClientesSC(String nombre, String dni, int tlf, int deuda): Parameterized constructor to initialize customer data.

Methods

ClientesSC cargar(ArrayList<ClientesSC> ap)

Prompts the user to enter customer data (name, DNI, phone, debt), validates the DNI, checks for duplicates, and returns a new ClientesSC object.

void cargararray(ArrayList<ClientesSC> ap)

Adds a new customer to the aprobar list by calling the cargar method.

void ver(ArrayList<ClientesSC> ap, int b)

Displays the details of a specific customer at index b in the list.

void vertodos(ArrayList<ClientesSC> ap)

Iterates through the list and displays the details of all customers.

int deuda(ArrayList<ClientesSC> ap)

Calculates and returns the total debt of all customers in the list.

int deudatotal(ArrayList<ClientesSC> ap)

Calculates and returns the total debt of all customers (similar to deuda).

int buscar(ArrayList<ClientesSC> ap)

Searches for a customer by DNI and returns the index if found, otherwise returns -1.

ClientesSC cargarActualizar(ArrayList<ClientesSC> ap, int b)

Allows updating the details of a specific customer at index b. The user can choose which field to modify (name, DNI, phone, or debt).

void cargarArrayListActualizar(ArrayList<ClientesSC> ap, int b)

Updates the customer at index b in the list with the modified data from cargarActualizar.

void menĂº(ArrayList<ClientesSC> ap)

Displays a menu with options to add a customer, list all customers, view the total debt, search for a customer, modify customer data, and exit.

Main Functionality

The menĂº method provides the main interaction loop, allowing users to manage customer data through a text-based menu. It handles user input and calls the appropriate methods based on the selected option.