Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java Class Question?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


bob
Java Class Question?
1 Answer(s)      3 years and 3 months ago
Posted in : Java Beginners


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.

Create a class named TVShow.java. Data Fields can include a String containing the Name of the show, a String containing the day that the show is broadcast(i.e. ?Monday?) and an integer for the channel where the show can be viewed. Methods will include a constructor that requires values for all of the data fields, plus methods to get, set and display the values of the data fields. Create a UseTVShow.java file that prompts the user to input up to 5 TV shows and stores the data in an array of objects first, then displays them as a list.


Advertisement
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:
Advertisements
Advertisements
 

 

 

DMCA.com