
-----------------------------------
Caceres
Fri Jun 30, 2006 10:13 pm

Program Help! Please!Important!
-----------------------------------
Hello. I was wondering if someone could help me with making this program. I'm not sure of the codes (the info I put into the editor).
I used Crimson Editor.
And so far..I have..

import TerminalIO.KeyboardReader;

public class ass25c {
	public static void main(String[] args) {
		System.out.print("Please enter marks\nWhen you've entered them all, type -1.\n");
	}
}

The assignement is" Write a program that will calculate the average for a set of marks. The user enters a -1 when there are no more marks to enter. The program will count the number of marks entered and calculate the average. The output could look like this :

You entered 24 marks and the average is 73.8. "

I'm a newbie programmer (literally an extreme newb) and i Don't know how to make this program.
Thank you.
~Caceres

-----------------------------------
TheFerret
Sat Jul 01, 2006 1:19 am


-----------------------------------
We are not going to write your program, so don't expect that... But, you have to find what number people input and then add it onto a total and add 1 to how many numbers people enter and if they enter -1 exit... After that, you output total/number...

-----------------------------------
cool dude
Sat Jul 01, 2006 9:43 am


-----------------------------------
wow i recently just started learning java myself and even i can make such a simple program. its really simple

1) make a variable count and every time a mark is inputed make count increase by 1 int count = count + 1;

2)everytime a new mark is entered make a sum variable and add the new mark to the old mark and store it in the sum variable. 

3)make a average variable and to get average divide the sum of all the marks by the count (how many marks in total) int average = sum / count

4)then all you have left is to display the output system.out.println("you entered " + count + " marks and the average is " + average);

Note: make a conditional loop for when your entering marks so that you can exit the loop when user enters -1 or it will keep asking for marks. 

hope that helps

-----------------------------------
wtd
Sat Jul 01, 2006 9:52 am


-----------------------------------
wow i recently just started learning java myself and even i can make such a simple program. its really simple

1) make a variable count and every time a mark is inputed make count increase by 1 int count = count + 1;

This is not quite right.  ;)

-----------------------------------
cool dude
Sat Jul 01, 2006 11:00 am


-----------------------------------
wow i recently just started learning java myself and even i can make such a simple program. its really simple

1) make a variable count and every time a mark is inputed make count increase by 1 int count = count + 1;

This is not quite right.  ;)

hmmm... i think its because i can't declare it on the same line like that because i have to first initialize it. right? 


int count = 0;
count = count + 1;

-----------------------------------
wtd
Sat Jul 01, 2006 11:51 am


-----------------------------------
Yes.  Variables should always be initialized before they're used.  It just happens that in Java that initialization should be explicit.

-----------------------------------
Token
Sat Jul 01, 2006 12:20 pm


-----------------------------------
Just a shortcut

count++; 

increments by one  :D

-----------------------------------
wtd
Sat Jul 01, 2006 12:39 pm


-----------------------------------
Or more generally:

count += 1;

-----------------------------------
Caceres
Sat Jul 01, 2006 1:35 pm


-----------------------------------
public class ass25c {
	public static void main(String[] args) {
		KeyboardReader reader = new KeyboardReader();
		int count = 0;
		int stop = -1;
				
		System.out.println("Please enter marks\nWhen you've entered them all, type -1:");
		
		for(count=0; count==stop; count=count++) {;
		}
}
}

My information still doesn't work. :S

-----------------------------------
cool dude
Sat Jul 01, 2006 1:42 pm


-----------------------------------
you need to learn the basics of java! firstly why are u using a counted loop to see if the user pressed -1 to exit??? thats incorrect. if u read my post i told you use a conditional loop also you don't even know how to make a counted loop! although you don't need it. read my post carefully, because i tell you step be step wat to write! 

P.S. obviously your information still doesn't work and i really hope you see why!

-----------------------------------
Caceres
Sat Jul 01, 2006 4:09 pm


-----------------------------------
I don't know whta a condition loop is.
This is my 5th day with Java. All i've learned is "if", "while" and "for".

-----------------------------------
wtd
Sat Jul 01, 2006 4:19 pm


-----------------------------------
A "counting loop" is a "conditional loop."  Just a fairly predictable loop.

Basically, in a loop you start with some initial state.  You then proceed to do something.  At some point you check to see if a condition holds true.  If it does not, then you exit the loop.  At the end of each iteration of the loop, you have some kind of update.

A simple loop:

for (int i = 0; i < 10; i++) {
   System.out.println(i);
}

Includes all four parts.  The initial state is:

int i = 0

The test is:

i < 10

The update is:

i++

And the thing you're doing is:

System.out.println(i);

-----------------------------------
cool dude
Sun Jul 02, 2006 10:14 am


-----------------------------------
instead of your counted loop which uses "for" use something like this:

while (mark != -1) {
//code
}

as you can see the loop will keep looping while the mark is not -1. as soon as the user enters the mark -1 it will exit the loop. now inside this loop you put your code.

-----------------------------------
Aziz
Wed Jul 12, 2006 2:01 pm


-----------------------------------
It seems you barely even know the basics of programming, so I suggest a full-blown tutorial:

[url=http://java.sun.com/docs/books/tutorial/getStarted/intro/index.html]The Java Tutorial

Follow that, young friend. Then go to "Learning the Java Language" on the same site.

-----------------------------------
Aziz
Wed Jul 12, 2006 2:04 pm


-----------------------------------
ADD: (sorry, I can't seem to remember how to edit, or why it won't let me)

Or check out this tutorial here:
http://www.compsci.ca/v2/viewtopic.php?t=9576
