Closed Thread
Results 1 to 2 of 2

Thread: Need Help...Java assignment due today

  1. #1
    lostgoat is offline Newbie
    Join Date
    Jun 2009
    Posts
    1
    Rep Power
    0

    Question Need Help...Java assignment due today

    I am looking for help in the code at areas with //, please help.
    I am also getting a compiler error with (import java.Date maybe this will be cured when other lines are ??
    Code:
    import java.util.Scanner;
    import java.util.Random;
    import java.io.*;
    import java.Date;
    
    public class PGM1
    {
    public static void main(String[] args) throws IOException
    {String fname; Random rrd = new Random(System.currentTimeMillis());
    Scanner kbd = new Scanner(System.in);
        System.out.println("What is the output filename? ");
    fname = kbd.nextLine();
        PrintWriter outfile = new PrintWriter(fname);
        System.out.println("What's the size of the array? ");
        int sz = kbd.nextInt();
        if(sz < 25 || sz > 100)
          System.out.println("The array size is out of range." + 
                             "Please enter a size between 25-100. ");
        int [] nums = new int[sz];
        System.out.println("Random Numbers: ");
          System.out.println();
    
    
    // Fill nums[] with random numbers in the range 0 thru 23456
    
    // Write (to outFile) numbers from nums, 5 to a line - well aligned
    
    int highest = nums[0];
        for (int index = 1; index < nums.length; index++)
        {
          if (nums[index] > highest)
            highest = nums[index];
        }
        int lowest = nums[0];
        for (int indexL = 1; indexL < nums.length; indexL++)
        {
          if (nums[indexL] < lowest)
            lowest = nums[indexL];
        }
        int total = 0;
        int average;
        for (int indexA = 0; indexA < nums.length; indexA++)
          total +=nums[indexA];
        average = total/nums.length;
        System.out.print("Smallest: " + "/t" + lowest);
        System.out.println("/t/t/tLargest: " + "/t" + highest);
        System.out.println("Average: " + "/t" + average);
    
    // close outFile
    Last edited by WingedPanther; 06-22-2009 at 08:18 AM. Reason: add code tags (the # button)

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,851
    Blog Entries
    4
    Rep Power
    49

    Re: Need Help...Java assignment due today

    I have done some...
    Now do it a little more...on your own dude...
    Code:
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Random;
    import java.util.Scanner;
    public class PGM1	{
    public static void main(String[] args) throws IOException	{
    String fname; 
    char check;
    int sz;
    do {
    Random r = new Random();
    Scanner kbd = new Scanner(System.in);
        //System.out.println("What is the output filename? ");
        //fname = kbd.nextLine();
       	// if(fname.equals(null) || fname.equals("")) {
        //		System.out.println("No file found");
       	// }
        //PrintWriter outfile = new PrintWriter(fname);
    do {
        System.out.println("What's the size of the array? "+
        		"\nRemember from 25-100");   
        sz = kbd.nextInt();
    }
        while(sz < 25 || sz > 100);
        int [] nums = new int[100];
        for(int i=0; i<sz; i++) {
        nums[i] = r.nextInt(1)+23456;
        
        }
    // Write (to outFile) numbers from nums, 5 to a line - well aligned
    
    int highest = 23456;
        for (int index = 0; index < nums.length; index++) {
          if (nums[index] > highest)
            highest = nums[index];
        }
        int lowest = 0;
        for (int indexL = 0; indexL <nums.length; indexL++) {
        	if (nums[indexL] < lowest)
        		lowest = nums[indexL];
        }
        int total = highest+lowest;
        int average;
        for (int indexA = 0; indexA < nums.length; indexA++)
          total +=nums[indexA];
          average = total/nums.length;
        System.out.println("Random Numbers");
        System.out.println("Smallest: "+lowest);
        System.out.println("Largest: "+highest);
        System.out.println("Average: "+average);
        //outfile.close();
        System.out.print("Wanna do again?" +
        		"\nYes or No?");
        String in = kbd.next();
        check = in.charAt(0);
    	}
    while(check=='y' || check=='Y');
    	}
    }
    Cheers !

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help in a Java Assignment
    By codehunter22 in forum Java Help
    Replies: 0
    Last Post: 05-21-2011, 02:49 PM
  2. Need some help with a Java assignment
    By Bloodpanda in forum Java Help
    Replies: 5
    Last Post: 12-09-2009, 04:38 AM
  3. Java Assignment Help
    By rgs1400 in forum Java Help
    Replies: 2
    Last Post: 11-30-2009, 09:02 PM
  4. Java Assignment Help
    By rgs1400 in forum Java Help
    Replies: 4
    Last Post: 10-08-2009, 08:02 PM
  5. need code help, assignment due today
    By kris1976 in forum Java Help
    Replies: 13
    Last Post: 06-29-2009, 05:26 AM

Tags for this Thread

Bookmarks

Posting Permissions

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