import java.util.Scanner; import java.util.Date; import java.util.Calendar; impo
ID: 3594978 • Letter: I
Question
import java.util.Scanner;
import java.util.Date;
import java.util.Calendar;
import java.text.*;
class PA1
{
public static void main(String args[])
{
int cablePkg,noOfMovies,totalMovieCharges;
int cableSrv=0;
while(true)
{
System.out.println("WELCOME TO SA CABLE ");
System.out.println("Please enter your name:");
Scanner in=new Scanner(System.in);
String customerName=in.nextLine();
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();
System.out.println(cablePkg);
if(cablePkg !=1 && cablePkg !=2 && cablePkg !=3)
{
System.out.println("Invalid selection!");
System.out.print("Please try again:");
cablePkg=in.nextInt();
}
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");
if(cablePkg == 1)
{ cableSrv = 35;
System.out.printf("SA CABLE CHARGES AS OF "+sdf.format(date));
System.out.println("Customer:"+customerName.toUpperCase()+" ");
System.out.println("Cable Service:"+" "+"$"+cableSrv);
System.out.println("Movie-On-Demand-HD: "+" "+"$"+totalMovieCharges);
System.out.println("TOTAL DUE:"+" "+"$"+(cableSrv+totalMovieCharges));
}
else if(cablePkg == 2)
{ cableSrv = 75;
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("Movie-On-Demand-HD: "+" "+"$"+totalMovieCharges);
System.out.println("TOTAL DUE:"+" "+"$"+(cableSrv+totalMovieCharges));
}
else if(cablePkg == 3)
{
cableSrv = 110;
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("Movie-On-Demand-HD: "+" "+"$"+totalMovieCharges);
System.out.println("TOTAL DUE:"+" "+"$"+(cableSrv+totalMovieCharges));
}
else
{
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("Movie-On-Demand-HD: "+" "+"$"+totalMovieCharges);
System.out.println("TOTAL DUE:"+" "+"$"+(cableSrv+totalMovieCharges));
}
System.out.println("Enter 'Y' to continue or 'N' to exit:");
char toContinue=in.next().charAt(0);
in.close();
if(toContinue =='y')
{
continue;
}
else
{
break;
}
}
System.exit(0);
}
}
Explanation / Answer
import java.util.Scanner;
import java.util.Date;
import java.util.Calendar;
import java.text.*;
class PA1
{
public static void main(String args[])
{
int cablePkg,noOfMovies,totalMovieCharges;
int cableSrv=0;
String cableSub="";
char another='Y';
while(another=='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();
System.out.println(cablePkg);
if(cablePkg < 1 || cablePkg > 3){
do
{
System.out.println("Invalid selection!");
System.out.print("Please try again:");
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("Enter 'Y' to add more subscriptions for a customer or 'N' to exit:");
toContinue=in.next().charAt(0);
}
while(toContinue=='Y');
System.out.println("Enter 'Y' to add another customer or 'N' to exit:");
another=in.next().charAt(0);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.