Java Class Question?

Java Class Question?

Write an application that prompts the user to make a choice for a Coffee cup size, S for Small, T for Tall, G for Grande and V for Venti ? the prices of the cup sizes will be stored in a parallel double array as $2.00, $2.50, $3.25, and $4.50 respectively. Allow the user to choose if they would like to add a flavor to the coffee and add an additional $1.00 to the price of the coffee, display the total price of the cup of coffee after the user enters a selection.

View Answers

October 10, 2011 at 5:34 PM

import java.util.*;
class Application
{
    public static void main(String[] args) 
    {
        double array[]={2.00,2.50,3.25,4.50};
            Scanner input=new Scanner(System.in);
            System.out.println("Choose Coffee Cup Size:");
            System.out.println("S for Small");
            System.out.println("T for Tall");
            System.out.println("G for Grande");
            System.out.println("V for Venti");
            double price=0;
            double additional=1;
            double totalPrice=0;
            System.out.print("Enter your choice: ");
            char ch=input.next().charAt(0);
            switch(ch){
               case 'S':
                     price=array[0];
               break;
               case 'T':
                     price=array[1];
               break;
               case 'G':
                     price=array[2];
               break;
               case 'V':
                     price=array[3];
               break;
            }
            System.out.print("Do you want to add flavor to coffee?Yes/No: ");
            String check=input.next();
            if(check.equals("Yes")){
             totalPrice=price+additional;
            }
            else{
            totalPrice=price;
            }
            System.out.println("Total Bill is: $"+totalPrice);
    }
}









Related Tutorials/Questions & Answers:
question1 - Java Beginners
java class - Java Interview Questions
Advertisements
inner class - Java Interview Questions
Core Java Interview Questions Page 2, Core Java QuestionQ
abstract class - Java Interview Questions
Pattern class - Java Interview Questions
OBJECT CLASS - Java Interview Questions
Inner class - Java Interview Questions
abstract class - Java Server Faces Questions
abstract class - Java Server Faces Questions
where singleton class used in java - Java Interview Questions
write those 3 questions (class)
Java - Java Interview Questions
Difference between extends thread class vs implements runnable interface - Java Interview Questions
Design a class named BankAccount to hold datas for a bank account in Java using Bluej Software - Java Interview Questions
can i restrict a class that it will not allows create more than two objects - Java Interview Questions
How to call business deleget class(EJB) from JSF Page? - Java Server Faces Questions
java questions - Java Interview Questions
clone() method of object class - Java Interview Questions
Java class
Core Java Interview Questions!
java - Java Interview Questions
java questions
java class
java - Servlet Interview Questions
java class
java questions
JAVA QUESTIONS - Java Beginners
interview questions - Java Interview Questions
Java Questions
Java Questions
interview - Java Interview Questions
Java Questions
java - Java Interview Questions
Java Interview Questions
jvm - Java Interview Questions
Struts - Java Interview Questions
Java Questions & Java FAQ
help me - Java Interview Questions
Questions about Java's String pool
java questions
java questions
java questions
java questions
java Questions
Java inner class and static nested class
java certification questions - Java Beginners
java - Java Interview Questions
java - JSP-Interview Questions
Java Class Size

Ads