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 4 of 4

Thread: Confused with homework

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Confused with homework

    Hi there.. I'm new to Java and don't fully understand yet how to call methods from other classes. If somebody could take a look at my code and offer suggestions, it'd be much appreciated. Here are my classes, Multiply and MultiplyTest:

    __________________________________________________ _______

    // Ch06_Assignment: MultiplyTest.java
    // Author: Joshua Nelson
    // Date: 3/5/2013

    public class MultiplyTest
    {
    public static void main( String[] args )
    {
    Multiply myMultiply = new Multiply();

    myMultiply.createQuestion();
    myMultiply.quiz();
    myMultiply.checkResponse(response);
    } // end main
    } // end class:MultiplyTest

    __________________________________________________ _______

    // Ch06_Assignment: Multiply.java
    // Author: Joshua Nelson
    // Date: 3/5/2013
    import java.util.Scanner;
    import java.util.Random;

    public class Multiply
    {
    public static int product;

    public static int createQuestion()
    {
    Random randomNumbers = new Random();
    int num1 = randomNumbers.nextInt(9);
    int num2 = randomNumbers.nextInt(9);
    product = num1 * num2;
    System.out.printf( "How much is %d times %d?", num1, num2 );
    return product;
    } // end method:createQuestion

    public static void checkResponse( int guess )
    {
    if (guess != product)
    System.out.println( "No. Please try again" );
    else
    {
    System.out.println( "Very Good!" );
    createQuestion();
    } // end else
    } // end method:checkResponse

    public static int quiz()
    {
    createQuestion();
    Scanner input = new Scanner( System.in );
    System.out.println( "Enter your answer (-1 to exit):" );
    int response = input.nextInt();
    while (response != -1)
    {
    checkResponse(response);
    System.out.println( "Enter your answer (-1 to exit):" );
    response = input.nextInt();
    } // end while
    return response;
    } // end method:quiz
    } // end class:Multiply


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Confused with homework

    You will want to tell us what the current code is supposed to be doing and what problems you are having with it. My experience here is that we're usually terrible at mind reading.

  3. #3
    Member Zyrion's Avatar
    Join Date
    Feb 2013
    Location
    Iowa
    Posts
    106
    My Mood
    Angelic
    Thanks
    2
    Thanked 8 Times in 8 Posts

    Default Re: Confused with homework

    Please format your code appropriately with tags so we can look at your code without having a headache.

    [C0DE=java]
    <your code>
    [/CODE]

  4. #4
    Junior Member Robertgif's Avatar
    Join Date
    Feb 2013
    Posts
    19
    My Mood
    Amazed
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Confused with homework

    What don't you understand about calling methods? Is there a specific issues you have with them, or a specific issue?
    "You should not let technology (or method) drive your design, but make your design drive the technology".

    Always learning!

Similar Threads

  1. So confused, I need help!
    By sessypeanut in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 2nd, 2012, 10:45 PM
  2. I'm confused
    By Wonderlandslost in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 2nd, 2012, 01:33 PM
  3. help me , im confused!!!!
    By sephskie in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 11th, 2011, 10:52 AM
  4. Confused..
    By jadowers in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 5th, 2011, 12:56 PM
  5. [SOLVED] confused
    By joon in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 12th, 2011, 11:40 AM