Write a program that will gather information for up to 10customers (once the max
ID: 3610950 • Letter: W
Question
Write a program that will gather information for up to 10customers (once the maximum has been reached, do not allow any moreinformation to be input). You may prompt for the number ofcustomers that will be entered. The input will include thecustomer’s name, email, and information on how to calculatetheir bill. Once you have this information, you will display amessage for the customer that includes their name, email and totalbill amount.
You will use a function to calculate the customer’s totalbill. This function will also add applicable tax and any fees yourcompany charges. Once you have calculated the bill for thecustomer, you will store ONLY the bill amount in an array.
You will, when the time comes, display for the user the totalnumber of customers entered and the average bill for thoseusers.
You will use a menu to determine what the user wants to do atany given time. The menu will look like the following:
Customer Menu
1) Enter customer information
2) Print average billinformation
3) Exit
You are required to use all of your knowledge acquired in theclass not to exclude loops, functions and arrays.
Explanation / Answer
private String name;
private String emailId;
private double sum;
CustInfo()
{
}
void print(){
System.out.println("Name :" + name);
System.out.println("Email id :" + emailId);
System.out.println("Total amount:" + sum);
}
CustInfo( int c)
{
int n,i;
Scanner input = new Scanner(System.in);
System.out.println((c+1) + " Customer Information ");
System.out.println("Enter the name:");
name = input.next();
System.out.println("Enter emailid:");
emailId = input.next();
System.out.println("Enter the number of Items this customer " +(c+1) + " purchased:");
n=input.nextInt();
double [] balance = new double[n];
sum=0;
System.out.println("Enter the cost of each item:");
for(i=0;i<n;i++)
{
balance[i] = input.nextFloat();
sum += balance[i];
}
}
double getSum()
{
return sum;
}
};
class CustInfoTest
{
public static void main(String args[])
{
char ch;
String str;
int i;
float amt,sum;
boolean c=false;
Scanner input = new Scanner(System.in);
CustInfo CustInfo1;
int n,count=0;
CustInfo []CustInfoArr = new CustInfo[10];
while(true)
{
if(!c)
System.out.println(" 1) Enter customer information 2) Printaverage bill information 3) Exit ");
str=input.nextLine();
if(str.length()==1)
ch=str.charAt(0);
else
{ c=true;
continue;
}
c=false;
try{
if(ch =='1')
{
do{
System.out.println("HOw many customers u want toenter:");
n = input.nextInt();
}while(n+count>10);
for(i=0;i<n;i++)
{
CustInfo1= new CustInfo(count);
CustInfoArr[count]= CustInfo1;
count++;
}
}
else
if(ch =='2')
{sum =0;
for(i=0;i<count;i++){
CustInfoArr[i].print();
sum += CustInfoArr[i].getSum();
}
if(count==0)
System.out.println("You have not entered anyCustomer");
else
System.out.println("Average is :" + (sum/count));
}
else
if(ch =='3')
break;
}catch(Exception e) {
System.out.println("Invalid intput ");
continue;
}
}
}
}
/*
*
Sample output
1) Enter customer information
2) Print average bill information
3) Exit
2
You have not entered any Customer
1) Enter customer information
2) Print average bill information
3) Exit
1
HOw many customers u want to enter:
2
1 Customer Information
Enter the name:
name
Enter emailid:
name1@yahoo.com
Enter the number of Items this customer 1 purchased:
2
Enter the cost of each item:
1
23
2 Customer Information
Enter the name:
name2
Enter emailid:
name2@yahoo.com
Enter the number of Items this customer 2 purchased:
3
Enter the cost of each item:
12 23 42
1) Enter customer information
2) Print average bill information
3) Exit
2
Name :name
Email id :name1@yahoo.com
Total amount:24.0
Name :name2
Email id :name2@yahoo.com
Total amount:77.0
Average is :50.5
1) Enter customer information
2) Print average bill information
3) Exit
3
**/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.