Oop example lecture 3

Page 1

GS311-CS602 Ms Halima Ateeyah OOP Example (Lecture 3) public static void main(String[] args) { // TODO code application logic here double subject[] = {80,30,90}; //creating an objects std myinput = new std(234567,"IVY",subject); System.out.printf("id is : %d\n name of student:" + " %s\n the result : %f" ,myinput.id,myinput.name,myinput.calculation()); } } …………………………………………………………………………………………………………………………………………. public class std { //fields int id; String name; double subjects[]; double result; //constructor public std (int i , String n, double sub[]) { id= i; name= n; subjects=sub; } //function to set public void setid(int i) { id = i; } //get public int getid() { return id; }

1


public double calculation () { //function to get the percentage double number=0; for (int i=0 ; i<subjects.length; i++) number = number + subjects[i]; result = number /300*100; return result;

} }

2


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.