Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Inputs not being applied.

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Inputs not being applied.

    My code is not applying my input and I can't figure out why. Any help is appreciated.

       import java.util.Scanner;
     
        public class CoffeeCup_Driver
       {
           public static void main (String[] args)
          {
             String typeofCoffee;
             double height, radius, addCoffee, amount;
             int input;      
             Scanner scan = new Scanner(System.in);
     
          // prompt user for the name of coffee and the height/radius of the cup
     
             System.out.print("Enter the type of Coffee: ");
             typeofCoffee = scan.nextLine();
             System.out.print("Enter the height of coffee cup: ");
             height = scan.nextDouble();
             System.out.print("Enter the radius of coffee cup: ");
             radius = scan.nextDouble();
     
          //create a new coffee cup with the parameters entered
             CoffeeCup cup = new CoffeeCup (typeofCoffee, radius, height); 
          //prints the cup object
             System.out.println(cup);
          //allow the user to enter the amount they want to pour into the cup
             System.out.print("Enter the amount of coffee to pour: ");
             amount = scan.nextDouble();
             cup.addCoffee(amount);
             System.out.println(cup);
     
     
          //allow the user to enter the width of a sugar cube to add
             System.out.print("Enter the width of a sugar cube:");
             input = scan.nextInt();
             System.out.println(cup);
     
     
          //allow the user to enter the amount of coffee they want to drink
             System.out.print("Enter the amount of coffee to drink:");
             amount = scan.nextDouble();
             cup.drinkCoffee(amount);
             System.out.println(cup);
     
          //empty the coffee cup
             cup.emptyCup();
             System.out.println("Emptying Cup...");
     
          //print the cup object
             System.out.println(cup);
          }
       }

     
        public class CoffeeCup
       {
          private double volofCup,amtofCoffee;
          private String typeofCoffee;
          private String overflow;
          private int emptyCup;
          private double volofCube;
     
           public CoffeeCup(String type, double radius, double height)
          {
             type = typeofCoffee;
             volofCup =Math.PI * Math.pow(radius, 2) * height;
     
          }
     
           public void emptyCup()
          {
             emptyCup = 0;
          }
     
           public boolean addCoffee(double amtofCoffee)
          {
             amtofCoffee += emptyCup;
     
             if(amtofCoffee >= volofCup)
             {
                amtofCoffee = volofCup;
                return true;
             }
             else
                amtofCoffee = amtofCoffee;
             return false;
          }
     
     
     
     
           public boolean addSugarCube(double width)
          {
             volofCube = Math.pow(width, 2);
             volofCube += amtofCoffee;
             if(amtofCoffee > volofCup)
             {
                amtofCoffee = volofCup;
                return true;
             }
             else{
                return false;
             }
          }
           public void drinkCoffee(double drinkCoffee)
          {
             amtofCoffee -= drinkCoffee;
             if(drinkCoffee > amtofCoffee)
                amtofCoffee = 0;
     
             else{
                this.amtofCoffee -= drinkCoffee; 
     
             }
          }
     
           public String toString(){
             String output = "Cup of Decaf Coffee " +  "\n" +
                "Vol. of the Cup is: " + volofCup +" Cubic Centimeters\n" + 
                           "Cup is: " + amtofCoffee +  "% full";
             return output;
          }
     
     
       }

    Those are my two programs but It seems like my main is not calling the driver when i try to enter any input. Any help is appreciated.


  2. #2
    Member
    Join Date
    Feb 2010
    Location
    Dehradun, India
    Posts
    37
    Thanks
    1
    Thanked 7 Times in 6 Posts

    Default Re: Inputs not being applied.

    I can run your program and CoffeeCup class is being called from CoffeeCup_Driver.

    So you have to check where you are wrong. And if my help is needed then tell me the output you needed.

Similar Threads

  1. [SOLVED] Facing java error "cannot be applied to (java.lang.String)"
    By tazjaime in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 23rd, 2009, 10:19 AM