a) An internet service provider has three different subscription packages for it
ID: 3629100 • Letter: A
Question
a)
An internet service provider has three different subscription packages for its customers:
Package A: For $9.95 per month, 10 hours of access are provided. Additional hours are $2.00 per hour.
Package B: For $13.95 per month, 20 hours of access are provided. Additional hours are $1.00 per hour.
Package C: For $19.95 per month, unlimited access are provided.
Write a program that calculates a customer's monthly bill. It should ask the user to enter the letter of the package the customer has purchased (A, B, or C) and the number of hours that were used. It should then display the total charges.
b)
Modify the program you wrote for last question so it also calculates and displays the amount of money Package A customers would save if they purchased Packages B or C, and the amount of money Package B customers would save if they purchased Package C. If there would be no savings, no message should be printed.
c) Write a program that asks the user for a positive nonzero integer value. The program should use a loop to calculate the product of all the integers from 1 up to the number entered. For example, if the user enters 5, the loop will find the result for 1x2x3x4x5.
Explanation / Answer
please rate - thanks
CRAMSTER RULE- 1 question per post
import java.util.Scanner;
public class IspDriver
{
public static void main(String[] args)
{Scanner in = new Scanner (System.in);
char choice;
String c;
double h,bill,hours;
System.out.println("Enter the package: ");
do{
System.out.println("A .Package A B. Package B C. Package C");
c=in.next();
choice=c.charAt(0);
if(choice<'A'||choice>'C')
System.out.println("Invalid choice");
}while(choice<'A'||choice>'C');
System.out.println("Enter hours used: ");
hours=in.nextDouble();
if(choice=='A')
{
h=hours-10;
bill=9.95+(2*(int)(h+.5)); //round hours up
}
else if(choice=='B')
{
h=hours-20;
bill=14.95+(int)(h+.5); //round hours up
}
else
bill=19.95; //round hours up
System.out.printf("Your bill is is $%.2f ",bill);
}
}
-------------------
import java.util.Scanner;
public class IspDriver
{
public static void main(String[] args)
{Scanner in = new Scanner (System.in);
char choice;
String c;
double h,bill,hours,bbill=0,cbill=0;
System.out.println("Enter the package: ");
do{
System.out.println("A .Package A B. Package B C. Package C");
c=in.next();
choice=c.charAt(0);
if(choice<'A'||choice>'C')
System.out.println("Invalid choice");
}while(choice<'A'||choice>'C');
System.out.println("Enter hours used: ");
hours=in.nextDouble();
if(choice=='A')
{
h=hours-10;
bill=9.95+(2*(int)(h+.5)); //round hours up
h=hours-20;
bbill=14.95+(int)(h+.5);
cbill=19.95;
}
else if(choice=='B')
{
h=hours-20;
bill=14.95+(int)(h+.5); //round hours up
cbill=19.95;
}
else
bill=19.95; //round hours up
System.out.printf("Your bill is is $%.2f ",bill);
if(choice=='A')
{System.out.printf("If you had chosen plan B you would have saved $%.2f ",bill-bbill);
System.out.printf("If you had chosen plan C you would have saved $%.2f ",bill-cbill);
}
else if(choice=='B')
System.out.printf("If you had chosen plan C you would have saved $%.2f ",bill-cbill);
}
}
--------------------------
import java.util.*;
public class Main
{public static void main(String [] args)
{int i,n,nf=1;
Scanner in=new Scanner(System.in);
System.out.print("a positive non zero number: ");
n=in.nextInt();
for(i=1;i<n;i++)
nf*=i;
System.out.println(n+"!= "+nf);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.