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

Thread: *Java Assignment*

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default *Java Assignment*

    This is the assignment that I need help to do:

    Assignment Background
    It's time for the Java Olympics, the biggest java extravaganza in Java Town, with not 1, but 2 Java events! Who will win gold? It could be you!

    Event 1: Math Functions
    Write a program that simulates the tossing of two dice. Toss the die, display what each dice displays and display the total of the two die. Have this program continue until a 7 or 11 is the total roll.

    Event 2: String Functions
    Ask the user to input two strings. Display the strings in alphabetical order. Calculate and display the number of characters in the two words. Next convert the first string to all uppercase and the second string to all lowercase. Display the resulting strings.

    ***The Bonus Event:
    Ask the user to input a sentence. Count the number of spaces in the sentence to determine the number of words entered. Output the number of characters in the sentence, the number of words in the sentence and the average number of characters per word.

    Can anyone help me??!!!!

    Michelle


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: *Java Assignment*

    What have you done so far? Do you have any specific questions about your assignment or the code you have written?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: *Java Assignment*

    I have no idea of how to start....><

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: *Java Assignment*

    Make a list of the simple steps the program must do. Then work on one at a time. If you have problems, post the code and your questions.
    For example: a die has 6 sides. Use the Random class to randomly generate a number from 1 to 6.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: *Java Assignment*

    What should I do next.....??
    import java.util.*;

    public class Dice {
    public static void main(String[] args) {
    Random rand = new Random();
    int tries = 0;

    int sum = 0;
    while (sum != 7 or 11) {
    // roll the dice once
    int roll1 = rand.nextInt(6) + 1;
    int roll2 = rand.nextInt(6) + 1;
    sum = roll1 + roll2;
    System.out.println(roll1 + " + " + roll2 + " = " + sum);
    tries++;
    }

    System.out.println("You won after " + tries + " tries!");
    }
    }

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: *Java Assignment*

    What should I do next.....??
    What parts of the assignment have you done so far? What parts need to be done next?
    Did you make a list of the steps the program needs to do? Which have you done?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: *Java Assignment*

    This code is the dice section. I don't know whether this code is right or not... This is the first step of the assignment (regarding the dice).

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: *Java Assignment*

    What happens when you compile and execute the program? Does it do what you want it to do?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Apr 2012
    Posts
    160
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Default Re: *Java Assignment*

    The only problem I can see in your first code is the while statement. It would read something like this

    while (sum != 7 && sum != 11)

    Other than that it looks like you're doing pretty well.

Similar Threads

  1. 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
  2. Help with a java assignment?
    By rberry719 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: September 30th, 2011, 01:02 PM
  3. [SOLVED] OOP java assignment
    By enkei in forum Object Oriented Programming
    Replies: 1
    Last Post: April 27th, 2011, 11:16 AM
  4. my java assignment -- please help
    By java_beginner in forum Java Theory & Questions
    Replies: 6
    Last Post: May 20th, 2010, 08:32 AM
  5. Replies: 1
    Last Post: February 22nd, 2010, 08:20 AM