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

Array

how to make array

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)
19 views4 pages

Array

how to make array

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 javax.swing.JOptionPane;

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)

this.id = id;

this.name = name;

this.part = part;

this.cgpa = 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 javax.swing.JOptionPane;

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 = JOptionPane.showInputDialog("Enter student id");

String nameStd = JOptionPane.showInputDialog("Enter name");

String sPart = JOptionPane.showInputDialog("Enter part");


String sCgpa = JOptionPane.showInputDialog("Enter cgpa");

int iIdStd = Integer.parseInt(sIdStd);

int iPart = Integer.parseInt(sPart);

double dCgpa = Double.parseDouble(sCgpa);

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

//to display all the students in the array

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

System.out.println(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++;

System.out.println("The best student is :");

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

System.out.println("There are " + scorer + " students whose cgpa 3.0 and above");;

Output

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy