0% found this document useful (0 votes)
4 views7 pages

Object Oriented Programming 1

The document contains a Java class named 'Student' with attributes for name, age, and grade. It includes a constructor for initializing these attributes, a method to display student details, and a method to check if the student has passed based on a grade threshold. The main method creates two student instances and displays their details along with their pass status.

Uploaded by

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

Object Oriented Programming 1

The document contains a Java class named 'Student' with attributes for name, age, and grade. It includes a constructor for initializing these attributes, a method to display student details, and a method to check if the student has passed based on a grade threshold. The main method creates two student instances and displays their details along with their pass status.

Uploaded by

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

23:19 AAO 3ARI

Student.java X
1 public class Student {
2 private String name;
3 private int age;
4 private double grade;
5 C
1/ Constructor that initializes all attributes
7 public Student (String name, int age, double grade) {
8 ths.name = name;

Home End (

Editor Files Console Terminal


23:19O
Student.java
ri
X
8 this.name = name;
this.age = age;
10 this.grade = grade;
11
12 C
13 1/ Default constructor
14 public Student(O {
15

< Home End ( )

Editor Files Console Terminal


23:19AO
Student.java X
17 1/ Method to display student details
18 public void displayDetails() {
19 System.out.println("Name: + name);
20 System.out.printin("Age: "
+ age)i
21 "
System.out.println("Grade: + grade);
22
23
24 1/ Method to check if the student has passed
Home End (

Editor Files Console Terminal


23:20 AD

Student.java
ri
X ee

25 public boolean hasPassed() {


26 return grade >= 50.0; //passing grade is 50
27 }
28
29 public static void main(String[] args) { C
30 Student student1 = new Student("ola othman", 20, 75.5);
31 student1.displayDetails();
32 Svstem. out.orintln("Has Passed: "
+ student1.hasPassed()):
Home End ( )

Editor Files Console Terminal


23:20FO
Student.java X
32 System.out.println("Has Passed: + student1.hasPassed());
33
34 Student student2 = new Studernt("malak othman", 19, 45.0);
35 student2.displayDetails():
36 System.out.println("Has Passed: "
+ student2.hasPassed()); C
37 }
38 }
39
Home End ( )

Editor Files Console Terminal


23:20FO
Console ee

Name: ola othman


Age: 20
Grade: 75.5
Has Passed: true
Name: malak othman
Age: 19
Grade: 45.0

Editor Files Console Terminal


23:20FO
Console ee

Grade: 75.5
Has Passed: true
Name: malak othman
Age: 19
Grade: 45.0
Has Passed: false

Editor Files Console Terminal

You might also like