Seriously screwed for Java assessment

Associate
Joined
13 Jan 2007
Posts
2,424
Location
Belfast,Northern Ireland
Got an assessed practical tomorrow, im normally pretty pants at Java but to add to things i've deleted my practical work from the last 2 sessions on arrays and now really am in the dark. Is there any site at all java programmers can use for knowledge? Everything i've found so far has been extremely unhelpful, including sun microsystems own stuff
 
I worked through a bit of it but found it was mainly definations/explainations or overly simplified examples like 'Helloworld.' Guess i'll crack on through it once i get some time.

Its really simple problems, i've lost all my files and cant get on my unis net storage, which i find not so great!

I just want to create an array which the user enters 30 elements into (through getScannerInput) between the numbers 0-20 which are ordered as they were entered. Then print these numbers in order seperated by a comma and a space e.g. (1, 3, 6, 19)

I know its really basic but its been one of those days to say the least. I know how to restrict numbers okay but does this change for arrays somehow as it could mess up entry order?
 
i think i love you magical trevor!

getScannerInput is a .class written by my lecturer or something in my uni which lets you ask the user to input the data basically.

So for example: int a = getScannerInput.anInt("Enter first number: ");

Allows the user to enter the number. This has just added to confusion as it functions differently from everything i can find on the web so i cant make it work for this array.

What makes it worse is i did it last week but dont have my old files for reference :(
 
Not really, teachings been of a fairly poor standard but to be fair i should be doing a lot more private study than what i have been. But i have been doing this for the other 2 modules as they've been very heavy workloads of late.

Cheers for the code, i'd just solved it myself actually but i hadnt stuck the restrictions in yet and yours is much neater.

Can i ask what this is ? Just a comment?
// x is the number of marks to get
private int[] getMarks(int x)
 
Cant help but gulp at this stuff!

Must say i really do feel almost cheated. Though i can slack i am generally a pretty good student in terms of actually working hard and attending all my lectures etc. But despite this my grasp of java is turd so far, lectures seem to be a 50minute session of the lecture trying to make ppl fall asleep his hardest. And though i pay attention, a 15minute recap on what we did last lecture, followed by new things which explained once, hazzah i understand, explained another 7 times getting dumber as he goes just serves to bore me.

Then practicals which were going fine till about 3 weeks ago when suddenly we were meant to pull solutions out of our rear ends to things we'd never seen before. As for our textbook, biggest waste of 20quid ever. It in no way delivers any useful information as it only just exceeds about 20 bloody pages. Upon asking the lecturer why we didnt have a better, more detailed book, he said it was too confusing for those performing not so well in the class.......the rest i would have to bleep out.

Not impressed by the standard of teaching or any help im getting at all

/rant over

*Forgot to say thanks to you guys for the help, i was dead in the water there without my old files for reference, at least tomorrow i'll go in there with some grasp of what im doing
 
cheers guys, that sorting of the array isnt a problem mate, sirusb and magical trev sorted me out.

As for that BlueJ book its already on order, think yourself and some other guys recommended it in my last java thread. How long do you continue to use java for? Throughout my time at uni or do we switch languages?

I was wondering how to make a method that will display the most frequently occurring mark and display how many people got it? From the array of course. I've had to do max's, min's, averages, and displayed how many passed in terms of true/false
 
urgh i changed it so it would go inside a method and now its completely ballsed when i try to return the array so i can use it for other stuff in the main method. I HATE JAVA! killing rampage coming soon
 
Does anybody know how to return an array?

I thought it would have been 'return ArrayName;'

but it isnt happening :(
 
return the variable, and make sure your method signature contains the class name of the object you are returning.
Code:
public Array foo () {
    Array foobar = new Array();
    return foobar;
}

Dont quite understand there. I have this:
Code:
public static int enterMarks();
	{
		
		int[] classMarks = new int[30];

at the start. then simply return classMarks;

at the end of the method. I dont quite understand as it works in the textbook im looking at, yet wont for me, and the functioned fine when it was part of the main method.

As for doing my homework, fair enough magical trevor did help me to a degree i didnt expect, but what he did helped me get a grasp of what i was trying to do and i've since completed another 5 sections. Plus its an assessed practical in a few hours, not homework.

Even still i thought asking what is probably a relatively simple one line question to most on here, wasnt exactly asking a huge amount
 
Ah right, i'd never been shown that before. Though it still isnt working for me. Its saying im trying to return outside the method, which i've got on a few variations and now im getting that the method ody is missing. This is what i've got for the array and the part of the main which matters in terms of the array.

Code:
public class marks2
{	// creates the array which the user will enter 30 values between 0-20 into
	public static int[] enterMarks();
	{
		
		int[] classMarks = new int[30];
		int a = 0;
		
		for(int i = 0; i < classMarks.length;)
		{
		a = getScannerInput.anInt("Please enter a mark: ");
		if (a >= 0 && a <= 20)
    	{
     	classMarks[i] = a;
     	i++;
    	}
    	else
    	{
      System.out.println("The number you entered was not between 1 and 20");
   		}
  		}		
	
		for (int i = 0; i < classMarks.length; i++)
		{
 		if (i < classMarks.length - 1)
  		{
   		System.out.print(classMarks[i] + ", ");
 		}
  		else
  		{
    	System.out.print(classMarks[i]);
  		}
  		return classMarks;
		}

Code:
public static void main (String args[])
	{
		enterMarks();
	}

Is that not right or am i getting completely the wrong idea? I thought by changing the public static int[] enterMark would mean im able to return an array to work on through main?
 
But aren't I returning the array from within the method so i can use it in main? Therefore it should indeed be int[] ? I tried using void anyway and got nowhere.

As for the i++ i thought it stopped the value being entered into the array if it was outside the values i need and stopped it skippin ahead with no value or something dodgy.

I suggest you give up on me after a valiant effort! Thanks all for the patience but i dont see me getting this in a hurry. Again thank you for all the help, i'll hopefully get my head around it later when i try to go over where i screwed up :)
 
Back
Top Bottom