- import [email protected] Lemuel M [email protected] Book Title From Control Structures through Objects by Tony - import...

This preview shows page 1 - 2 out of 2 pages.

import javax.swing.JOptionPane; /** * @author Lemuel M. Uhuru * @Date June 16, 2013 * Book Title: From Control Structures through Objects by Tony Gaddis * Page: 191 Problem 13: Internet Service Provider * @Description Write a program that calculates a customer's monthly bill. * It should ask the user to 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. */ public class InternetServiceProvider { public static void main(String[] args) { // Declare variables for package prices double priceA = 9.95; double priceB = 13.95; double priceC = 19.95; // Declare variable to hold user package char userPackage; // Declare variable to hold hours used int hours; // Prompt user for package type String input = JOptionPane.showInputDialog("Enter your package letter (A/B/C)").toUpperCase(); // Prompt user for the amount of hours used String input2 = JOptionPane.showInputDialog("Enter the amount of hours used"); // Convert input2 to data-type int hours = Integer.parseInt(input2);
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read both pages?

Unformatted text preview: // Convert input1 to data-type char using the charAt string method // which returns the first element within a given string. userPackage = input.charAt(0); // Calculate total charges for package A and B double totalChargesA = ((hours - 10) * 2) + priceA; double totalChargesB = ((hours - 20) * 1) + priceB; // Design switch statement with nested if-else structures // to display the appropriate total charges. switch (userPackage) { case 'A': if (hours > 10) JOptionPane.showMessageDialog(null, "Package: " + userPackage + "\nTotal Charges: $" + totalChargesA); else JOptionPane.showMessageDialog(null, "Package: " + userPackage + "\nTotal Charges: $" + priceA); break; case 'B': if (hours > 20) JOptionPane.showMessageDialog(null, "Package: " + userPackage + "\nTotal Charges: $" + totalChargesB); else JOptionPane.showMessageDialog(null, "Package: " + userPackage + "\nTotal Charges: $" + priceB); break; case 'C': JOptionPane.showMessageDialog(null, "Package: " + userPackage + "\nTotal Charges: $" + priceC); } } }...
View Full Document

  • Spring '08
  • Garcia,D
  • Java Programming, Java Code, total charges, char userPackage, \nTotal Charges

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors