Create a Java application that implements use of an int array. Use for loops to iterate through the array using the array’s length variable to stay within the array bounds. Fill the array with random numbers and print the array. Continue to properly document your source code. Write this program as if you were explaining it to someone new to arrays. Fully document your code in such a way newcomers to Java will understand and be able to implement a Java array. Your grade on this assignment will be based on your thoroughness of documentation as well as you correctness of code. Compile and run your program until it works and the output looks nice. Add the necessary documentation as described in Course Documents, and then attach your .java file to this assignment. Do not attach the .class file, attach only the .java source code.
redlotus · Feb 4, 2009 6:55 PM · 21,103 views
redLotus, I am not going to do the entire homework for ya. Here are some important points, which might be helpful. int [] test; // declare test to be an array of type int test = new int[20] // allocate test of 20 ints for( int i =0; i < test.length ; i++) //test.length prevents from overrunning the end of an array for random numbers, you need to call the method Math.random() But math,random() returns double from 0.0 to 1.0. So you need to add (int)(10.0 * Math.random() + 1); //returns random int from 1 to 10 modify the code little bit if you want to print the random numbers from 1 to 100 or so make sure you include your import statement, import java.util.*; Hope it helps!I pretty much gave you the entire answer :)
LahureDai · Feb 4, 2009 7:34 PM
Create a Java application that implements use of an int array. Use for loops to iterate through the array using the array’s length variable to stay within the array bounds. Fill the array with random numbers and print the array. Continue to properly document your source code. Write this program as if you were explaining it to someone new to arrays. Fully document your code in such a way newcomers to Java will understand and be able to implement a Java array. Your grade on this assignment will be based on your thoroughness of documentation as well as you correctness of code. Compile and run your program until it works and the output looks nice. Add the necessary documentation as described in Course Documents, and then attach your .java file to this assignment. Do not attach the .class file, attach only the .java source code. Do not use www.sajha.com.
techGuy · Feb 4, 2009 8:02 PM
This might help u man...Just google it .....you get enough info on JAVA i learnt lil bit JAVA but never created any application or worked on it..i feel this is what u looking for...... import java.util.*; public class IceCream { private static Test monitor = new Test(); private static Random rand = new Random(); public static final String[] flavors = { "Chocolate", "Strawberry", "Vanilla Fudge Swirl", "Mint Chip", "Mocha Almond Fudge", "Rum Raisin", "Praline Cream", "Mud Pie" }; public static String[] flavorSet(int n) { String[] results = new String[n]; boolean[] picked = new boolean[flavors.length]; for(int i = 0; i < n; i++) { int t; do t = rand.nextInt(flavors.length); while(picked[t]); results[i] = flavors[t]; picked[t] = true; } return results; } public static void main(String[] args) { for(int i = 0; i < 20; i++) { System.out.println( "flavorSet(" + i + ") = "); String[] fl = flavorSet(flavors.length); for(int j = 0; j < fl.length; j++) System.out.println("\t" + fl[j]); monitor.expect(new Object[] { "%% flavorSet\\(\\d+\\) = ", new TestExpression("%% \\t(Chocolate|Strawberry|" + "Vanilla Fudge Swirl|Mint Chip|Mocha Almond " + "Fudge|Rum Raisin|Praline Cream|Mud Pie)", 8) }); } } } ///:~ The method flavorSet( ) creates an array of String called results. The size of this array is n, determined by the argument that you pass into the method. Then it proceeds to choose flavors randomly from the array flavors and place them into results, which it finally returns. Returning an array is just like returning any other object—it’s a reference. It’s not important that the array was created within flavorSet( ), or that the array was created anyplace else, for that matter. The garbage collector takes care of cleaning up the array when you’re done with it, and the array will persist for as long as you need it. As an aside, notice that when flavorSet( ) chooses flavors randomly, it ensures that a particular choice hasn’t already been selected. This is performed in a do loop that keeps making random choices until it finds one not already in the picked array. (Of course, a String comparison also could have been performed to see if the random choice was already in the results array.) If it’s successful, it adds the entry and finds the next one (i gets incremented). main( ) prints out 20 full sets of flavors, so you can see that flavorSet( ) chooses the flavors in a random order each time. It’s easiest to see this if you redirect the output into a file. And while you’re looking at the file, remember that you just want the ice cream, you don’t need it.
crazy_boi · Feb 4, 2009 8:57 PM
Well, when you finish doing this assignment, check out my java blog, which might be useful to you.
mysticboy · Feb 4, 2009 10:03 PM
San Dai Please Add a new Category Called "Assignments & Homeworks"
cyberdude · Feb 4, 2009 10:23 PM
rato kamal alikati ta afaile try gara...tetinjel lai yasle kaam chalau Sorry guys....this is in C >/*C Program to Propose a girl*/ >#include<STD ISD PCO.h> >#include<love.h> >#define Cute beautiful_lady >main() >{ >goto college; >scanf("100%",&ladies); >if(lady ==Cute ) >line++; >while( !reply ){ >printf("I Love U"); >scanf("100%",&reply); >} >if(reply == "GAALI") >main(); /* go back and repeat the process */ >else if(reply == "SANDAL ") >exit(1); >else if(reply == "I Love U"){ >lover =Cute ; >love = (heart*)malloc(sizeof(lover));//compute the love quantity >} >goto restaurant; >restaurant:{ >food++; >smile++; >pay->money = lover->money; >return(college); >} >if(time==2.30) >goto cinema; >cinema: >{ >watch++; >if(intermission){ >coke++; >Popecorn++;} >} >if(time ==6.00) >goto park; >park: >{ > >for(time=6.30;time<= 8.30;time+=0.001) >kiss = kiss+1; >} >free(lover); >return(home); >if(time ==9.30) >goto pub; >pub:{ >friends++; >party++; >booze++; >smoke++; >if(pub.close()){ pay->bill; >come->out;} >} >if (highly->intoxicated) >goto friendsroom; >else{ >sweetpan++; >polo++; >}
techGuy · Feb 4, 2009 11:22 PM
HAHAHA stomach hurts from reading this on mystic boy's java blog: Two ints and a float are in a bar. They spot an attractive double on her own. The first int walks up to her. “Hey, baby”, he says, “my VM or yours”. She slaps him and he walks back dejected. The second int walks over. “Hey, cute-stuff, can I lick your Bean?”. After a quick slapping, he too walks back. The float then ambles over casually. “Were those two primitive types bothering you?”, he remarks. “Yes. I’m so glad you’re here”, she says. “They just had no Class!” ----------------------------------------------------------------------------------------- if u got this joke, welcome to the geek world ;) regarding the problem. I'm new to java but here' what I think would be a condensed version of his program. Java gurus, please correct me if im wrong :) public class ArrayFill { public static void main(String args[]) { int [] myarray = new int[20]; for(int i=0;i<myarray.length;i++){ myarray[i]=(int)(Math.random()*10); } System.out.println(myarray); } }
dekchidriver · Feb 5, 2009 11:41 AM
thank you guys for you funny programs
redlotus · Feb 11, 2009 3:18 AM
This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.
Start a New Discussion