help me..how to print a sum and average of grades using Java?

Start a new thread with your question and your code. Don't expect anyone to do your homework.
You should use a for loop

help me..
Why it is having an error?
please help me to fix this my assignment..

class Example1 
{
	public static void main(String[] args) 
	{

	
 		double total grade = int Korean(90) + English(85) + Mathematics(78) + Biology(65) + Chemistry(83);
		
		average= total/5;
		{
			
		System.out.println("total grade :" + total);
		System.out.println("average :" + average);
	}
}
}

Edited 5 Years Ago by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

help me..
Why it is having an error?
please help me to fix this my assignment..

class Example1 
{
    public static void main(String[] args) 
    {


        double total grade = int Korean(90) + English(85) + Mathematics(78) + Biology(65) + Chemistry(83);

        average= total/5;
        {

        System.out.println("total grade :" + total);
        System.out.println("average :" + average);
    }
}
}

end quote.

Start a new thread. And this is not java: Korean(90)
Start a new thread do some studying before posting again.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Comments
This does not deserve neg-rep
Why be nasty? You asked to see their code, they showed...you told them to go study.

Try something like this:

import java.util.ArrayList;


public class AverageGrade {

	private ArrayList<Double> grades = new ArrayList<Double>();
	
	public void addGrade(double grade) {
		grades.add(grade);
	}
	
	public double getTotal() {
		double sum = 0;
		for (double grade : grades) 
			sum += grade;
		return sum;
	}
	
	public double getAverage() {
		return getTotal() / grades.size();
	}
	
	public static void main(String[] args) {
		AverageGrade ag = new AverageGrade();
		
		ag.addGrade(90); // Korean
		ag.addGrade(85); // English
		ag.addGrade(78); // Mathematics
		ag.addGrade(65); // Biology
		ag.addGrade(83); // Chemistry
		
		System.out.println("Total: " + ag.getTotal());
		System.out.println("Average: " + ag.getAverage());
	}
}

Hopefully that gets you on the right path!

Comments
Are you having fun doing people's homework for them?
Don't give away complete homework solutions. We're here to help people understand, not to make them pass their class without effort

Try something like this:

import java.util.ArrayList;


public class AverageGrade {

	private ArrayList<Double> grades = new ArrayList<Double>();
	
	public void addGrade(double grade) {
		grades.add(grade);
	}
	
	public double getTotal() {
		double sum = 0;
		for (double grade : grades) 
			sum += grade;
		return sum;
	}
	
	public double getAverage() {
		return getTotal() / grades.size();
	}
	
	public static void main(String[] args) {
		AverageGrade ag = new AverageGrade();
		
		ag.addGrade(90); // Korean
		ag.addGrade(85); // English
		ag.addGrade(78); // Mathematics
		ag.addGrade(65); // Biology
		ag.addGrade(83); // Chemistry
		
		System.out.println("Total: " + ag.getTotal());
		System.out.println("Average: " + ag.getAverage());
	}
}

Hopefully that gets you on the right path!

We don't give away solution in this forum and you went and did the poster's entire homework. Not only that, but it is clearly that rhoxart faye don't even know how to declare variables and you wrote a code with ArrayList, object instantiation and confusing for loops. You think that offered any significant help? What you think will happen when rhoxart faye tries to deliver your code to the teacher.

A simple solution would be:

class Example1
{
public static void main(String[] args)
{

// declare variables
double total = 0;
double average = 0;

..... // declare the rest of the grades

// add the grades


average= total/5;

System.out.println("total grade :" + total);
System.out.println("average :" + average);

}

We don't give away solution in this forum and you went and did the poster's entire homework.

Hi, this is not against the rules of these forums. See Member Rules for more information.

I wonder which is easier....reading API (as you suggest) or reading examples of code? Hrmm.....my guess is the later.

nice code you wrote, but i do agree that it is a little to advanced for him since he didnt know how to declare a variable ( from above poster).

Hi, this is not against the rules of these forums. See Member Rules for more information.

I wonder which is easier....reading API (as you suggest) or reading examples of code? Hrmm.....my guess is the later.

You gave a code that the poster cannot understand. From the mistakes that were made from the original code, you think that the poster can understand how to create object, instantiate them and also use ArrayLists ?

And I never said that the poster should read the API. I said that the poster should study how to declare variables, because that was clearly the problem. Don't know how to declare variables: double total grade = int Korean(90) + English(85) + Mathematics(78) + Biology(65) + Chemistry(83); When someone is having difficulty with the above code I am sure that your code makes perfect sense and if the poster submits that to his teacher, the teacher will have no idea that he copied it from someone else.

And whose code is more similar to the poster's ?

Comments
Equalizer

Hi, this is not against the rules of these forums. See Member Rules for more information.

I wonder which is easier....reading API (as you suggest) or reading examples of code? Hrmm.....my guess is the later.

Not a rule but recommendation - We only give homework help to those who show effort as explained there...
Besides as you can see rhoxart faye haven't got time to come back and reply

Edited 5 Years Ago by peter_budo: n/a

You gave a code that the poster cannot understand. From the mistakes that were made from the original code, you think that the poster can understand how to create object, instantiate them and also use ArrayLists ?

And I never said that the poster should read the API. I said that the poster should study how to declare variables, because that was clearly the problem. Don't know how to declare variables: double total grade = int Korean(90) + English(85) + Mathematics(78) + Biology(65) + Chemistry(83); When someone is having difficulty with the above code I am sure that your code makes perfect sense and if the poster submits that to his teacher, the teacher will have no idea that he copied it from someone else.

And whose code is more similar to the poster's ?

So this post where I expressed my opinion with valid arguments has been responded with a negative vote when someone has run out of arguments. The idea of negative votes according to the rules is to mark bad posts, not when you don't like someone's opinion.

Comments
This does not contribute constructively to the thread.
This article has been dead for over six months. Start a new discussion instead.