Results 1 to 3 of 3
  1. #1
    The Taco is offline Member
    Join Date
    Aug 2013
    Posts
    1
    Rep Power
    0

    Default Using import java.util.Scanner

    I am new to Java and I had a question. I coded a program in Eclipse Kepler. The code is here (it is made up of 3 classes). (Please pardon the ridiculously long class names. I made this a while back):

    First class:

    public interface IntExample {

    public void Hello();

    public void Fine();

    public void notFine();

    public void Goodbye();

    public void askQuestion();

    public void A();

    public void B();

    public void sayJoke();

    public void meltComputer();

    public void Funny();

    public void notFunny();

    public void theTruth();

    public void listCommands();


    }



    Next Class:

    public class DefiningInterfaceClass {

    public void Hello(){
    System.out.println("Hello there! How are you?");
    }

    public void Fine(){
    System.out.println("That's good!");
    }

    public void notFine(){
    System.out.println("That's too bad.");
    }

    public void Goodbye(){
    System.out.println("Goodbye");
    }

    public void askQuestion(){
    System.out.println("What is the capital of Mali? A. Timbuktu B. Bamako");
    }

    public void A(){
    System.out.println("Wrong!");
    }


    public void B(){
    System.out.println("Correct!");
    }

    public void sayJoke(){
    System.out.println("So a duck walks into a restaurant, he orders a steak , and says...PUT IT ON MY BILL!");
    }

    public void meltComputer(){
    for (int i=1;i < 999999999; i++)


    System.out.println("Pie!");
    }

    public void Funny(){
    System.out.println("Congratulations! You get the joke!");
    }

    public void notFunny(){
    System.out.println("You have no sense of humor!");
    }

    public void theTruth(){
    System.out.println("42 is the meaning of life.");
    }


    public void listCommands(){
    System.out.println("Hello (respond with Fine or notFine), Goodbye, askQuestion(respond with A or B), sayJoke(respond Funny or notFunny), meltComputer, listCommands, theTruth");
    System.out.println("NOTE: The command meltComputer won't actually crash your computer. However, it can cause lag on slower machines. USE AT OWN RISK!");
    System.out.println("NOTE: The meltComputer command is simply going to type Pie! 999,999,999 times!");
    }

    }


    The final class (where you put the input):


    public class DefiningInterfaceClassDemo {

    public static void main(String[] args) {

    DefiningInterfaceClass definingInterfaceClass = new DefiningInterfaceClass();


    //Do listCommands to see a list of commands to choose from
    //Note that commands are case sensitive
    //Remember to save each time before you run the application
    //DO NOT EDIT ANYTHING BUT THE COMMANDS
    //Only type between the "." and "("


    definingInterfaceClass.listCommands();





    }

    }


    Put this into your favorite IDE and run it. My question is: How could I make it so that instead of typing the commands within the code, I can type it in the console (and still receive the output)? Again, I am new so I am sorry if this is an easy fix.


    Thanks!

    The Taco

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default Re: Using import java.util.Scanner

    A remark: nothing implements that IntInterface ... shouldn't that first class do that?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Using import java.util.Scanner

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. import java.util.* doesn't works
    By Martino Milani in forum New To Java
    Replies: 6
    Last Post: 01-24-2012, 03:05 AM
  2. import java.util ????
    By kris09 in forum New To Java
    Replies: 3
    Last Post: 08-11-2008, 01:39 AM
  3. java.util.Scanner not recognised
    By pjm35@st-and.ac.uk in forum New To Java
    Replies: 4
    Last Post: 06-07-2008, 04:32 PM
  4. java.util.DateFormat not found in import
    By christina in forum New To Java
    Replies: 2
    Last Post: 08-05-2007, 11:31 PM
  5. The import java.util.Scanner cannot be resolved
    By Heather in forum Advanced Java
    Replies: 1
    Last Post: 07-08-2007, 02:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •