Java

whosadork

Chieftain
Joined
Aug 13, 2008
Messages
20
hey mates, i got Java programing program eclypse and i have been teaching myself java for awhile. But i need help with some of it couse when i get stuck i dont go anywere at all and i'm screwd....
 
i'm having a total problem with member systems, pm systems etc.
 
It's a long time since I used Java but still... Huh?!? A bit more elaborated description of your problems could provide more usefull answers.
 
i'm having a total problem with member systems, pm systems etc.

I've been programing in java for a while and I've never heard of such things(google apparently hasn't either).

You should probably post your code that you're having trouble with, post the error that it returns, and bold the part that's giving your trouble.
 
i got the member systems done, now i have a new class i need help with, its a math class. i cant really figure out why eclypse wont take 0.5 or stuff like that.

import java.util.Scanner;

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

int TestOne;
int TestTwo;
int TestThree;
int TestFour;
int sum;

System.out.print( "enter your test score:" );
TestOne = input.nextInt();

System.out.print( "Enter your test score:" );
TestTwo = input.nextInt();

System.out.print( "Enter your test score:" );
TestThree = input.nextInt();

System.out.print( "Enter your Test Score:" );
TestFour = input.nextInt();

sum = (TestOne / 100 ) + (TestTwo / 100) + (TestThree / 100) + (TestFour / 100) / 4;

System.out.printf( "Sum is %d\n", sum );

}
}

(Console)
enter your test score:91
Enter your test score:95
Enter your test score:93
Enter your Test Score:97
Sum is 0

Thats what i dont get, i took the test scores devided them by 100 so they'll be a %, but then i add them up and devide them by 4, and its zero.
???

PS. its to find my average of my tests
 
You're dividing a smaller int by a larger int which gives you a 0. Try making it into:

Code:
import java.util.Scanner;

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

int TestOne;
int TestTwo;
int TestThree;
int TestFour;
int sum;

System.out.print( "enter your test score:" );
TestOne = input.nextInt();

System.out.print( "Enter your test score:" );
TestTwo = input.nextInt();

System.out.print( "Enter your test score:" );
TestThree = input.nextInt();

System.out.print( "Enter your Test Score:" );
TestFour = input.nextInt();

[B]sum = (TestOne / 100.0 ) + (TestTwo / 100.0) + (TestThree / 100.0) + (TestFour / 100.0 ) / 4.0;[/B]

System.out.printf( "Sum is %d\n", sum );

}
}

Or alternatively, you can declare TestOne-Four as doubles:

Code:
import java.util.Scanner;

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

[B]double TestOne;
double TestTwo;
double TestThree;
double TestFour;
double sum;[/B]


System.out.print( "enter your test score:" );
[B]TestOne = input.nextDouble();[/B]

System.out.print( "Enter your test score:" );
[B]TestTwo = input.nextDouble();[/B]

System.out.print( "Enter your test score:" );
[B]TestThree = input.nextDouble();[/B]

System.out.print( "Enter your Test Score:" );
[B]TestFour = input.nextDouble();[/B]

sum = (TestOne / 100 ) + (TestTwo / 100) + (TestThree / 100) + (TestFour / 100) / 4;

System.out.printf( "Sum is %d\n", sum );

}
}

(see all the parts that are in bold)
The first method is easier and probably what you should do if your test scores will never be with a decimal (ex: 97.5), but both methods should be valid.
 
instead of ints try doubles. integers don't hold decimal values so when you divide (something less than 100)/100 you'll get a 0 value.

sum = (TestOne / 100.0 ) + (TestTwo / 100.0) + (TestThree / 100.0) + (TestFour / 100.0 ) / 4.0;

that should still return 0 because sum cannot hold decimal values(it's an integer).

and for what it's worth there's no need to divide all those numbers by 100 to get an average(I assume that's what you mean by sum in this case since you're trying to divide by 4)

sum = (first + second +third+fourth)/4

will get you the average.

and be sure to do your parentheses correctly there is a difference between
sum = (TestOne / 100 ) + (TestTwo / 100) + (TestThree / 100) + (TestFour / 100) / 4;
and this
sum = ((TestOne / 100 ) + (TestTwo / 100) + (TestThree / 100) + (TestFour / 100)) / 4;

This is what i believe you really want
Code:
import java.util.Scanner;
public class Help {
	public static void main( String args[] )
	{
	Scanner input = new Scanner( System.in );

	double TestOne;
	double TestTwo;
	double TestThree;
	double TestFour;
	double sum;


	System.out.print( "enter your test score:" );
	TestOne = input.nextDouble();

	System.out.print( "Enter your test score:" );
	TestTwo = input.nextDouble();

	System.out.print( "Enter your test score:" );
	TestThree = input.nextDouble();

	System.out.print( "Enter your Test Score:" );
	TestFour = input.nextDouble();

	sum = (TestOne +TestTwo + TestThree + TestFour) / 4;

	System.out.printf( "Sum is %.2f", sum );

	}

}
 
Whoops, I forgot to change the sum variable to a double in my first code block. This is what I get for not coding for 2 months.
 
lol thx guys, rofl now me and my friends will know if the teacher is lying that our average is 83%. rofl good night, long day of middle school :(
did mabe 3 test, grammer, algabra, and history.
 
You could also just find that kind of avg on a calculator...
 
rofl yeah but that would be boring, how do i make the class downloadable on the internet.
 
What do you mean downloadable? SO someone else can use it? You need to upload it somewhere that hosts files..
 
yeah, like can i burn it onto a CD or can i put it up on the internet and make it downloadeble. how do i find a place that hosts files??
 
I recomend exporting your file as an executable jar. your friends probably don't want to have to use the command prompt to open up the file so this should save them the hassle.

to do that

right click on your project
select export
select jar file
click next
check export generated classes and resources
select where you want to save it to
click next
check export with compiler warnings
click next
check generate the manifest file
select the class with the main method that you want to run at start up
click finish

I'll leave finding a webhost to you.
 
Back
Top Bottom