When continuing with the same customer only, how do get it to combine the result
ID: 3595746 • Letter: W
Question
When continuing with the same customer only, how do get it to combine the results together like the image above?
java.util.Scanner;
import java.util.Date;
import java.util.Calendar;
import java.text.*;
class myclass
{
public static void main(String args[])
{
int cablePkg,noOfMovies,totalMovieCharges;
int cableSrv=0;
String cableSub="";
char repeat='Y';
while(repeat=='Y')
{
System.out.println("WELCOME TO SA CABLE ");
System.out.println("Please enter your name:");
Scanner in=new Scanner(System.in);
String customerName=in.nextLine();
char toContinue='Y';
do
{
System.out.println("SA CABLE - SUBSCRIPTION PACKAGES ");
System.out.println("1.Basic: Local & major TV network channels $35");
System.out.println("2.Deluxe:Local, major TV, cable & 100 other channels $75");
System.out.println("3.Premium: Deluxe package plus HBO, on-demand & 300 other channels $110");
System.out.println(" Select your cable subscription package:");
cablePkg=in.nextInt();
if(cablePkg < 1 || cablePkg > 3){
do
{
System.out.println("Invalid!");
System.out.print("Choose 1, 2 or 3.");
cablePkg=in.nextInt();
}
while(cablePkg < 1 || cablePkg > 3);
}
System.out.println("SA CABLE-MOVIES ");
System.out.println("Enter the number of Movies-On-Demand-HD purchases:");
noOfMovies=in.nextInt();
totalMovieCharges=noOfMovies*7;
Date date = Calendar.getInstance().getTime();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy");
switch (cablePkg) {
case 1:
cableSrv = 35;
cableSub="Basic";
break;
case 2:
cableSrv = 75;
cableSub="Deluxe";
break;
case 3:
cableSrv = 110;
cableSub="Premium";
break;
}
System.out.println("SA CABLE CHARGES AS OF "+sdf.format(date));
System.out.println("Customer:"+customerName.toUpperCase()+" ");
System.out.println("Cable Service:"+" "+"$"+cableSrv);
System.out.println("Cable Subscription type: " +cableSub);
System.out.println("Movie-On-Demand-HD: "+" "+"$"+totalMovieCharges);
System.out.println("TOTAL DUE:"+" "+"$"+(cableSrv+totalMovieCharges));
System.out.println(" Thank you for being a valued SA Cable customer!");
System.out.println(" Enter 'Y' to continue with another subscription for the same customer or 'N' to exit:");
toContinue=in.next().charAt(0);
}
while(toContinue=='Y');
System.out.println("Enter 'Y' to continue with another customer or 'N' to exit:");
repeat =in.next().charAt(0);
in.close();
}
System.exit(0);
}//END main()
}//END APPLICATION
SA CABLE CHARGES AS OF 10/05/17 Customer: 110.00 70.00 Cable Service: Premium Movies-On-Demand-HD 10 75.00 35.00 Cable Service: Deluxe Movies-On-Demand-HD 5 185.00 105.00 Total Cable Services: Total Movies-On-Demand-HD TOTAL DUE Thank you for being a valued SA Cable customer! Enter 'Y' to continue with another customer or 'N' to exit: Y 290.00Explanation / Answer
import java.util.Scanner;
import java.util.Date;
import java.util.Calendar;
import java.text.*;
class myclass
{
public static void main(String args[])
{
int cablePkg,noOfMovies,totalMovieCharges=0;
int cableSrv=0,a=0,b=0,c=0,a1=0,b1=0,c1=0,TOTAL=0;
String cableSub="";
char repeat='Y';
//a for storing basic subscription cost
//a1 for storing number of channel
//b for storing deluxe subscription cost
//b1 for storing number of channel
//c for storing premium subscription cost
//c1 for storing number of channel
Date date = Calendar.getInstance().getTime();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy");
while(repeat=='Y')
{
System.out.println("WELCOME TO SA CABLE ");
System.out.println("Please enter your name:");
Scanner in=new Scanner(System.in);
String customerName=in.nextLine();
char toContinue='Y';
do
{
System.out.println("SA CABLE - SUBSCRIPTION PACKAGES ");
System.out.println("1.Basic: Local & major TV network channels $35");
System.out.println("2.Deluxe:Local, major TV, cable & 100 other channels $75");
System.out.println("3.Premium: Deluxe package plus HBO, on-demand & 300 other channels $110");
System.out.println(" Select your cable subscription package:");
cablePkg=in.nextInt();
if(cablePkg < 1 || cablePkg > 3){
do
{
System.out.println("Invalid!");
System.out.print("Choose 1, 2 or 3.");
cablePkg=in.nextInt();
}
while(cablePkg < 1 || cablePkg > 3);
}
System.out.println("SA CABLE-MOVIES ");
System.out.println("Enter the number of Movies-On-Demand-HD purchases:");
switch (cablePkg) {
case 1:
cableSrv = 35;
a1=noOfMovies=in.nextInt();
a=totalMovieCharges=noOfMovies*7+cableSrv;
cableSub="Basic";
break;
case 2:
cableSrv = 75;
b1=noOfMovies=in.nextInt();
b=totalMovieCharges=noOfMovies*7+cableSrv;
cableSub="Deluxe";
break;
case 3:
cableSrv = 110;
c1=noOfMovies=in.nextInt();
c=totalMovieCharges=noOfMovies*7+cableSrv;
cableSub="Premium";
break;
}
System.out.println("SA CABLE CHARGES AS OF "+sdf.format(date));
System.out.println("Customer:"+customerName.toUpperCase()+" ");
System.out.println("Cable Service:"+" "+"$"+cableSrv);
System.out.println("Cable Subscription type: " +cableSub);
System.out.println("Movie-On-Demand-HD: "+" "+"$"+totalMovieCharges);
System.out.println("TOTAL DUE:"+" "+"$"+(cableSrv+totalMovieCharges));
System.out.println(" Thank you for being a valued SA Cable customer!");
System.out.println(" Enter 'Y' to continue with another subscription for the same customer or 'N' to exit:");
toContinue=in.next().charAt(0);
}
while(toContinue=='Y');
System.out.println("SA CABLE CHARGES AS OF "+sdf.format(date));
System.out.println("Customer:"+customerName.toUpperCase()+" ");
if(a!=0)
{
System.out.println("Cable Service:"+" "+"$ 35");
System.out.println("Cable Subscription type: Basic");
System.out.println("Movie-On-Demand-HD: "+" "+"$"+a1+" "+a);
TOTAL=TOTAL+a+35;
}
if(b!=0)
{
System.out.println("Cable Service:"+" "+"$ 75");
System.out.println("Cable Subscription type: Deluxe");
System.out.println("Movie-On-Demand-HD: "+" "+"$"+b1+" "+b);
TOTAL=TOTAL+b+75;
}
if(c!=0)
{
System.out.println("Cable Service:"+" "+"$ 110");
System.out.println("Cable Subscription type: Premium");
System.out.println("Movie-On-Demand-HD: "+" "+"$"+c1+" "+c);
TOTAL=TOTAL+c+110;
}
System.out.println("TOTAL DUE:"+" "+"$"+(a+b+c));
System.out.println(" Thank you for being a valued SA Cable customer!");
System.out.println("Enter 'Y' to continue with another customer or 'N' to exit:");
repeat =in.next().charAt(0);
in.close();
}
System.exit(0);
}//END main()
}//END APPLICATION
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.