CoffeePriceCalculator2 - .java Computer Science 111 Boston...

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

/* * CoffeePriceCalculator2.java * * Computer Science 111, Boston University * * This version is still unstructured, but it reduces some * code duplication by factoring out the code for computing * the tax and printing the prices. This code used to appear in * the code for both choices, but it now appears only once, * AFTER the if-else-if statement. * * See CoffeePriceCalculator1.java for the original unstructured version * See CoffeePriceCalculator3.java for the fully structured version. */ import java.util.*; public class CoffeePriceCalculator2 { /* Class constants */ public static final double TAX_RATE = 0.0625; // sales tax public static void main(String[] args) { Scanner console = new Scanner(System.in); // only create this once! System.out.println("Welcome to Javabucks!"); System.out.println(); System.out.println("What type of drink would you like?"); System.out.println("1) brewed coffee"); System.out.println("2) latte"); System.out.print("Enter your choice (1-2): "); int choice = console.nextInt(); double price = 0.0; /**** WE MUST NOW DECLARE PRICE HERE. ****/ if (choice == 1) {
Image of page 1

Subscribe to view the full document.

Image of page 2
  • Spring '13
  • DaveSullivan

{[ snackBarMessage ]}

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