Results 1 to 4 of 4
  1. #1
    javanewbiemo is offline Member
    Join Date
    Feb 2017
    Posts
    2
    Rep Power
    0

    Angry New to Java...stuck on program

    Hello,

    I have a program that I need help with getting started. It will generate a series of random numbers and produce a table containing these values and some calculations with them. At the end some statistics will be printed.

    //Info about program
    -The program should define format strings to output results as shown in the sample at the bottom. Every row in the table must be printed using the printf command.
    -The program will get from the user the maximum random number to be computed (an integer). Initially, the program will get this value from the user as a String variable.
    -The program will then use the Integer wrapper class to parse the integer out of the String above and store it inside an integer variable.
    -Then the program will ask the user how many random numbers will be generated. It should also receive this number from the user as a String and use the Integer wrapper class to get the integer value into another integer variable.

    -Using a for-loop, output a table with the following characteristics:
    o Print a header of titles using a header format and printf (this should be before
    the loop, not inside the loop).
    o There should be one line per each random value generated.
    o Each line should contain the following information:
    A line number, also known as round.
    The generated random number.
    The fraction of the random number divided by the maximum random number.
    The power of three of the random number.
    You may use Math.pow method to calculate this value, or multiply two times the
    value by itself.
    The square root value of the random number.
    You may use Math.sqrt method to calculate this value.
    The logarithm (base e) of the random number.
    You may use Math.log method to calculate this value.

    -After all the rows of the table have been generated, the program should print 4 values: the smallest random number generated, the largest random generated, the total of adding all random numbers generated and their average.

    Here is what I have so far:

    import java.util.Scanner;

    public class test5
    {
    public static void main(String[] args)
    {
    Scanner stdIn = new Scanner(System.in);

    //declare variables
    final String HEADING_FMT_STR = "%-25s%13s%13s%15s\n";
    final String DATA_FMT_STR = "%-25s%,13.4f%,13.4f%,13.4f%,15.4f\n";
    String rows; //number of rows
    String round; //line number
    String number; //random number
    String randomNumber;
    int i;

    //print heading
    System.out.printf(HEADING_FMT_STR, "Round", "Rand#", "Fraction", "x^3", "Sqrt", "Log");

    // get input
    System.out.print("Please enter the maximum random number to be used: ");
    number = stdIn.next();
    randomNumber = Integer.parseInt(number);
    System.out.print("Please enter the number of rounds: ");
    round = stdIn.next();
    }
    }

    Any assistance or direction would be helpful...very basic stuff here but I am a novice. Thanks!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: New to Java...stuck on program

    Do you have any specific java programming questions about your project?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    6

    Default Re: New to Java...stuck on program

    It is all pretty much there already. You might want to think about the sequence in your main() method and you are missing a loop that runs for the count of random numbers that the user gave you. Inside the loop you create the random number and do the Math stuff and then print it all out. You will also need a counter that you initially set to zero and tick one up in each loop. The counter is your line number. The method for conversion from String to Integer will be int parseInt(String). The quickest way to get this done is to take a white piece of paper and write down the steps you would take if you did it by hand.

  4. #4
    javanewbiemo is offline Member
    Join Date
    Feb 2017
    Posts
    2
    Rep Power
    0

    Default Re: New to Java...stuck on program

    Thanks...I have just been a little overwhelmed with a lot of other stuff going on. The insight really helps for sure...just didn't want to go down the wrong path.

Similar Threads

  1. Stuck at one program. Needs Help
    By Sinman in forum New To Java
    Replies: 3
    Last Post: 07-14-2014, 01:06 PM
  2. Getting stuck developing CAD program
    By Digital Larry in forum AWT / Swing
    Replies: 1
    Last Post: 03-23-2013, 06:03 AM
  3. Stuck on a banking program
    By Ortlep in forum New To Java
    Replies: 2
    Last Post: 12-14-2011, 07:37 PM
  4. Stuck - simple program
    By dirtycash in forum New To Java
    Replies: 4
    Last Post: 11-24-2008, 07:44 PM
  5. FireSimulation Program, got stuck with a bug...
    By riz618 in forum New To Java
    Replies: 5
    Last Post: 01-28-2008, 03:48 PM

Posting Permissions

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