You have been tasked with developing a Java program that tracks customers and order data. The company wants to determine the purchasing behavior of its customers. All order data is based on the total sales amounts (revenue) for each customer.
Write a Java program that displays a menu to allow the user the following functionality:
1. Add multiple new customers - prompt user for the number of customers to be loaded and then prompts for each customer's name, customer id (5 digit number), and total sales
2. Add single new customer - prompts the user for customer data: customer name, customer id, and total sales
3. Display all customers - displays each customer's data to the console, one customer per line
4. Retrieve specific customer's data - prompts the user for the customer id and displays the corresponding customer's data: customer id, customer name, and total sales
5. Retrieve customers with total sales based on the range - prompts the user for the lowest and highest total sales and displays all customers with total sales in that range. Display each customer on a separate line with all information – Customer Name, Customer ID, and Total Sales
6. Exit



Answer :

Java is a programming language and computing platform that is widely used for building a variety of applications.

How to write the given code in java?

Here is an example of a Java program that provides the functionality described in the question:

import java.util.Scanner;

import java.util.ArrayList;

public class CustomerTracker {

   static ArrayList<Customer> customers = new ArrayList<>();

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);

       int option = 0;

       while (option != 6) {

           System.out.println("Menu:");

           System.out.println("1. Add multiple new customers");

           System.out.println("2. Add single new customer");

           System.out.println("3. Display all customers");

           System.out.println("4. Retrieve specific customer's data");

           System.out.println("5. Retrieve customers with total sales based on the range");

           System.out.println("6. Exit");

           System.out.print("Enter option: ");

           option = sc.nextInt();

           sc.nextLine();

           switch (option) {

               case 1:

                   addMultipleCustomers();

                   break;

               case 2:

                   addSingleCustomer();

                   break;

               case 3:

                   displayAllCustomers();

                   break;

              case 4:

                   retrieveCustomerData();

                   break;

               case 5:

                   retrieveCustomersInRange();

                   break;

              case 6:

                   break;

               default:

                   System.out.println("Invalid option. Please try again.");

           }

       }

   }

   public static void addMultipleCustomers() {

       Scanner sc = new Scanner(System.in);

       System.out.print("Enter number of customers to add: ");

       int numCustomers = sc.nextInt();

       sc.nextLine();

       for (int i = 0; i < numCustomers; i++) {

           System.out.print("Enter customer name: ");

           String name = sc.nextLine();

           System.out.print("Enter customer id (5 digits): ");

           int id = sc.nextInt();

           System.out.print("Enter total sales: ");

           double sales = sc.nextDouble();

           sc.nextLine();

           Customer c = new Customer(name, id, sales);

           customers.add(c);

       }

   }

   public static void addSingleCustomer() {

       Scanner sc = new Scanner(System.in);

       System.out.print("Enter customer name: ");

       String name = sc.nextLine();

       System.out.print("Enter customer id (5 digits): ");

       int id = sc.nextInt();

       System.out.print("Enter total sales: ");

       double sales = sc.nextDouble();

       sc.nextLine();

       Customer c = new Customer(name, id, sales);

       customers.add(c);

   }

   public static void displayAllCustomers() {

       for (Customer c : customers) {

           System.out.println(c.getName() + " " + c.getId() + " " + c.getSales());

       }

   }

   public static void retrieveCustomerData() {

       Scanner sc = new Scanner(System.in);

       System

To Know More About Java, Check Out

https://brainly.com/question/13261090

#SPJ4

Other Questions