hi there good evevning >>>>> :lol: :lol:

i hope all of u is good .....
sorry but i know i am new but i face aproblem with array i don't know how to solve problem with array >>>>>
i have problem that said enter name of 15 studemt and there grade i should read information from the key board i don't how to use the array with buffer

i write this code for the problem i don't know :( :( :(

public class StudentGrade

{

private double grade;
private String name;

public void setgrade( double G)
{
grade=G;
}

public double getgrade()
{
return grade;
}
public void setname( String n)
{
name=n;
}

public String getname()
{
return name;
}

}

public class StudentGradeU

{
StudentGrade E1 = new StudentGrade();
StudentGrade [] student= new [15] StudentGrade;

public static void main ( String argv[])
{
StudentGrade [] student = int [15] StudentGrade;
double Average= Average (student);
}

public  static double Average ()
{
for ( inti=0 ; i<10 ; i++)
    sum = sum+ arr[i];
return (sum/15);
}
}

plz he;p me with that >>>>>
thanks alot

warm heart

Dani AI

Generated

— you were on the right track with a StudentGrade class, but the code posted has several syntax and logic errors. rightly asked what you had tried and asked for clarification; below is a clear, working pattern showing how to declare the array, read 15 names/grades from the keyboard, store them, and compute the average.

Common fixes to apply:

  • Declare the array as StudentGrade[] students = new StudentGrade[15]; (elements start as null).
  • Create a new StudentGrade for each index before storing it: students[i] = new StudentGrade(name, grade);.
  • Use Scanner to read input; prefer nextLine() and Double.parseDouble(...) to avoid the leftover-newline issue.
  • Sum the grades with a loop and divide by students.length. Initialize sum to 0.0 and validate numeric input.

Example (compile-and-run ready):

import java.util.Scanner;

class StudentGrade {
    private String name;
    private double grade;
    public StudentGrade(String name, double grade) {
        this.name = name;
        this.grade = grade;
    }
    public double getGrade() { return grade; }
}

public class StudentGradeU {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        StudentGrade[] students = new StudentGrade[15];
        for (int i = 0; i < students.length; i++) {
            System.out.print("Student " + (i+1) + " name: ");
            String name = in.nextLine();
            System.out.print("grade: ");
            double grade = Double.parseDouble(in.nextLine());
            students[i] = new StudentGrade(name, grade);
        }
        double sum = 0;
        for (StudentGrade s : students) sum += s.getGrade();
        System.out.printf("Average = %.2f%n", sum / students.length);
        in.close();
    }
}

Notes: validate input to avoid NumberFormatException; if you want a variable number of students use ArrayList<StudentGrade>. Official references: Java arrays overview (arrays tutorial) and input with Scanner (Scanner API).

Recommended Answers

All 3 Replies

no one reaply i am sad >>>

thanx

warm heart

What have you tried?
Except the declaration of the array you don't seem to have done anything...

It also helps to state the problem that you are having. Just saying HELP gives me no clue as to the problem you are having.

I can infer somewhat from your statement above, but my determination is you want to know how to read input and place it into the array?

If that is not it, then you need to be more specific.

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.