0% found this document useful (0 votes)
22 views4 pages

Array

The document contains a Java program that defines a 'Student' class with attributes for student ID, name, part, and CGPA. It includes methods for setting and getting student information, as well as a main application that collects data for five students, displays their information, and calculates the best student based on CGPA, the number of part 4 students, and those with a CGPA of 3.0 or above. The program utilizes JOptionPane for input and prints results to the console.

Uploaded by

Amir Khuzairi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views4 pages

Array

The document contains a Java program that defines a 'Student' class with attributes for student ID, name, part, and CGPA. It includes methods for setting and getting student information, as well as a main application that collects data for five students, displays their information, and calculates the best student based on CGPA, the number of part 4 students, and those with a CGPA of 3.0 or above. The program utilizes JOptionPane for input and prints results to the console.

Uploaded by

Amir Khuzairi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Array

import [Link];

public class Student

private int id;

private String name;

private int part;

private double cgpa;

public Student()

id = -1;

name = "";

part = -1;

cgpa = -1.0;

public Student(int id, String name, int part, double cgpa)

[Link] = id;

[Link] = name;

[Link] = part;

[Link] = cgpa;

public void setStudent(int i, String n, int p, double c)

id = i;

name = n;

part = p;

cgpa = c;
}

public int getId()

{ return id; }

public String getName()

{ return name; }

public int getPart()

{ return part; }

public double getCgpa()

{ return cgpa; }

public String toString()

{ return("Id = " + id + " Name = " + name + " Part = " + part + " Cgpa = " + cgpa);

import [Link];

public class ArrayStudentApp

public static void main(String [] args)

Student [] StdArray = new Student[5];

//to input 5 students into the array

for (int i=0; i<5; i++)

String sIdStd = [Link]("Enter student id");

String nameStd = [Link]("Enter name");

String sPart = [Link]("Enter part");


String sCgpa = [Link]("Enter cgpa");

int iIdStd = [Link](sIdStd);

int iPart = [Link](sPart);

double dCgpa = [Link](sCgpa);

StdArray[i] = new Student(iIdStd, nameStd, iPart, dCgpa);

//to display all the students in the array

for (int i=0; i<5; i++)

[Link](StdArray[i].toString());

int part4 = 0, scorer = 0, ind = 0;

double cg = 0.0;

for (int j=0; j<5; j++)

//to find the best student

if (StdArray[j].getCgpa() > cg)

{ cg = StdArray[j].getCgpa();

ind = j;

//to count number of students in part 4

if ( StdArray[j].getPart() == 4)

part4++;

//to count the number of students who score cgpa 3.00 and above in part 4

if (StdArray[j].getCgpa() > 3.00)

scorer++;

[Link]("The best student is :");

[Link](StdArray[ind].toString());
[Link]("There are " + part4 + " part 4 students");

[Link]("There are " + scorer + " students whose cgpa 3.0 and above");;

Output

You might also like