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: Help with a java assignment

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

    Default Help with a java assignment

    I need help making a java program that allows the user to enter two numbers, and the program should list multiples of the first number to check if the second number is a multiple of the first. If it is, then the player gets +2 score, and if its not then the user gets -1, the user starts of the 0 score. The loop breaks when the value of the multiple exceeds 1000, and the program is supposed to ask the user to play the game as many times as they want as long as they have a POSITIVE score.

    Due tommorow

    Can anybody help me start?

    That would be great! Thanks.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,592
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default Re: Help with a java assignment

    Make a list of the features the program should have, work out the logic needed to do what the program is to do, find java classes that will implement those features and write some code.

    If you are having problems with your code, post the code and ask questions about your problems.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    proera92 (January 6th, 2013)

  4. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help with a java assignment

    Quote Originally Posted by Norm View Post
    Make a list of the features the program should have, work out the logic needed to do what the program is to do, find java classes that will implement those features and write some code.

    If you are having problems with your code, post the code and ask questions about your problems.
    I know what i'm supposed to do, just not how to express it through the java language,

    Here's what I got so far:

    import javax.swing.*;
    class GuessMultiple{
    public static void main(String str[]){
    int value = 0;
    double firstnumber, secondnumber;
     
    String input1=JOptionPane.showInputDialog("Enter your first number");
    firstnumber=Double.valueOf(input1).doubleValue();
    System.out.println("First number:" +firstnumber);
     
    String input2=JOptionPane.showInputDialog("Enter your second number");
    secondnumber= Double.valueOf(input2).doubleValue();
    System.out.println("Second number:" +secondnumber);
     
    	}
    }

    I don't know how to make the first number multiply by 1, 2, 3 etc and make it check that it equals to the second number.

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,592
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default Re: Help with a java assignment

    make the first number multiply by 1, 2, 3 etc
    Use a for loop. In the loop multiply the number by the loop's index variable which can start at 1 and increment by 1 each time around the loop.
    check that it equals to the second number
    Use a condition in an if statement.

    Please edit the posted code and indent the nested statements to make the code easier to read.
    All statements should not start in column 1.


    Also posted at http://www.java-forums.org/new-java/...ssignment.html
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. java assignment; please help
    By willc86 in forum Java Theory & Questions
    Replies: 3
    Last Post: November 4th, 2012, 07:05 AM
  2. *Java Assignment*
    By michelle_smile in forum Java Theory & Questions
    Replies: 8
    Last Post: May 30th, 2012, 05:10 PM
  3. assignment troubles polymorphism (guide for assignment included)
    By tdawg422 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 8th, 2011, 10:01 AM
  4. Java Assignment Help
    By welsh_rocker in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 12th, 2011, 05:02 AM
  5. Replies: 1
    Last Post: February 22nd, 2010, 07:20 AM