Scanner problems Easy for people who know Java (I dont!)- Need Immediate Help!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ryann18
    New Member
    • Oct 2006
    • 22

    Scanner problems Easy for people who know Java (I dont!)- Need Immediate Help!!!

    What is wrong with this?? Here are the two classes...SandB ox and KittyKitty?? I need to also know what happens if two or more values are equal and if exactly two values are equal, does it matter whether the equal values are lower or higher than the third?? And can somebody please help me answer the questions at the bottom???

    //A place to play with your kitty

    public class SandBox
    {
    public static void main(String[] args)
    {
    Scanner scan = new Scanner(System. in);
    KittyKitty cat = new KittyKitty();

    /////////////////////////////////////////////////////////////
    // This is where you put YOUR code to have "cat"
    // call ( use ) the methods ( services ,function , procedures)
    // YOU have defined ( written ) in the class called KittyKitty
    /////////////////////////////////////////////////////////////

    int able = 10;
    int cdef = 5;
    String ghi = "good";
    cat.myMethod_1( able, cdef, ghi);
    }//End main()

    }//End class definition
    _______________ _______________ _______________ _______________ ______

    public class KittyKitty {

    {
    /////////////////////////////////////////////////////////////
    // Here is where you will write ( define ) the methods of
    // this class
    /////////////////////////////////////////////////////////////
    public KittyKitty()
    {
    }//End constuctor

    void myMethod_1( int able, int cdef, String ghi)
    {
    if( able < cdef)
    {
    System.out.prin tln("The answer is=" + ghi);
    }// End if
    System.out.prin tln("The answer is not=" + ghi);
    }//End myMethod_1()
    }//End class definition
    _______________ _______________ _______________ _______________ ______

    What is wrong with this and how do I rewrite it to produce the correct output??

    if (total == MAX)
    if (total < sum)
    System.out.prin tln ("total == MAX and is < sum.");
    else
    System.out.prin tln ("total is not equal to MAX");
    _______________ _______________ _______________ _______________ ______

    Whats wrong with this and will it compile if it is part of an otherwise valid program? I'm supposed to explain

    if (length = MIN_LENGTH)
    System.out.prin tln ("The length is minimal.");
  • foleyflint
    New Member
    • Oct 2006
    • 9

    #2
    Let me give you an example of a Scanner Object below:

    System.out.prin t("Type input: ");
    Scanner reader=new Scanner(System. in);
    String myText=reader.n extLine();
    System.out.prin tln("Your text is: "+myText);

    This way you are I think able to adjust your code and make it work.

    Comment

    • foleyflint
      New Member
      • Oct 2006
      • 9

      #3
      _______________ _______________ _______________ _______________ ______

      What is wrong with this and how do I rewrite it to produce the correct output??

      if (total == MAX)
      if (total < sum)
      System.out.prin tln ("total == MAX and is < sum.");
      else
      System.out.prin tln ("total is not equal to MAX");
      _______________ _______________ _______________ _______________ ______

      Whats wrong with this and will it compile if it is part of an otherwise valid program? I'm supposed to explain

      if (length = MIN_LENGTH)
      System.out.prin tln ("The length is minimal.");[/QUOTE]
      ----------------------------------------------------------------------------------------------
      You have to be aware of WHAT you are comparing: Integers, doubles, Strings
      etc.
      To compare integers you can use == or != for resp. equal and not equal
      The same thing with doubles. What you can't do is compare an integer and double. You will have to cast one of them to the other. Most likely you would want them both to become a double. if variable 'count' is an integer, you can cast it to a double like this: (double) count.

      I'm not really sure what you want with your first code though.

      your second if-statement:
      you should compare again with ==, != , <, > , <=, >=

      If you want more info, you should pass me the whole code, because otherwise I won't be sure if I can help you without it.

      Comment

      • ryann18
        New Member
        • Oct 2006
        • 22

        #4
        Originally posted by foleyflint
        _______________ _______________ _______________ _______________ ______

        What is wrong with this and how do I rewrite it to produce the correct output??

        if (total == MAX)
        if (total < sum)
        System.out.prin tln ("total == MAX and is < sum.");
        else
        System.out.prin tln ("total is not equal to MAX");
        _______________ _______________ _______________ _______________ ______

        Whats wrong with this and will it compile if it is part of an otherwise valid program? I'm supposed to explain

        if (length = MIN_LENGTH)
        System.out.prin tln ("The length is minimal.");
        ----------------------------------------------------------------------------------------------
        You have to be aware of WHAT you are comparing: Integers, doubles, Strings
        etc.
        To compare integers you can use == or != for resp. equal and not equal
        The same thing with doubles. What you can't do is compare an integer and double. You will have to cast one of them to the other. Most likely you would want them both to become a double. if variable 'count' is an integer, you can cast it to a double like this: (double) count.

        I'm not really sure what you want with your first code though.

        your second if-statement:
        you should compare again with ==, != , <, > , <=, >=

        If you want more info, you should pass me the whole code, because otherwise I won't be sure if I can help you without it.[/QUOTE]

        The question is supposed to be used with the code I had, the KittyKitty and the Sandbox... I'm not sure what the crap to do???

        Comment

        • foleyflint
          New Member
          • Oct 2006
          • 9

          #5
          =ryann18
          The question is supposed to be used with the code I had, the KittyKitty and the Sandbox... I'm not sure what the crap to do???
          I gave you the Scanner Code, because you definately need to chang that one.

          Comment

          Working...