Created
January 18, 2021 13:18
-
-
Save kshitijvarshne1/126c36bcc2e3452e52af5389166126a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Created by IntelliJ IDEA. | |
* Author: Kshitij Varshney (kshitijvarshne1) | |
* Date: 18-Jan-21 | |
* Time: 10:26 AM | |
* File: Student.java | |
*/ | |
package jan18_21_NK.one; | |
public class Student { | |
private static String universityName; | |
private static String nameOfStream; | |
static { | |
universityName = "GLA"; | |
nameOfStream = "B.Tech"; | |
} | |
private int id; | |
private int marks; | |
private String studentName; | |
public Student(int id, int marks, String studentName) { | |
this.id = id; | |
this.marks = marks; | |
this.studentName = studentName; | |
} | |
public String getUniversityName() { | |
return universityName; | |
} | |
public void setUniversityName(String universityName) { | |
Student.universityName = universityName; | |
} | |
public String getNameOfStream() { | |
return nameOfStream; | |
} | |
public void setNameOfStream(String nameOfStream) { | |
Student.nameOfStream = nameOfStream; | |
} | |
public int getId() { | |
return id; | |
} | |
public void setId(int id) { | |
this.id = id; | |
} | |
public int getMarks() { | |
return marks; | |
} | |
public void setMarks(int marks) { | |
this.marks = marks; | |
} | |
public String getStudentName() { | |
return studentName; | |
} | |
public void setStudentName(String studentName) { | |
this.studentName = studentName; | |
} | |
} | |
//instance :- memory allocate at the time of object creation :---- Heap Area | |
//statoc variable : - memory allocate at the time of loading of load file :---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Created by IntelliJ IDEA. | |
* Author: Kshitij Varshney (kshitijvarshne1) | |
* Date: 18-Jan-21 | |
* Time: 10:29 AM | |
* File: StudentMain.java | |
*/ | |
package jan18_21_NK.one; | |
import java.util.InputMismatchException; | |
import java.util.Scanner; | |
public class StudentMain { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
int limit = sc.nextInt(); | |
int id = 0; | |
int marks = 0; | |
String studentName = null; | |
Student[] studentArray = new Student[limit]; | |
for (int i = 0; i < limit; i++) { | |
try { | |
id = sc.nextInt(); | |
marks = sc.nextInt(); | |
sc.nextLine(); | |
studentName = sc.nextLine(); | |
} catch (InputMismatchException a) { | |
System.out.println("Stop the program and again provide the value for object"); | |
a.printStackTrace(); | |
} | |
Student obj = new Student(id, marks, studentName); | |
studentArray[i] = obj; | |
} | |
sc.close(); | |
int sum = 0; | |
for (int i = 0; i < limit; i++) { | |
sum += studentArray[i].getMarks(); | |
} | |
float average = sum / limit; | |
System.out.println("Average :- " + average); | |
} | |
} | |
// for line no 28 | |
/* | |
catch(NumberFormatException a){ | |
sout("Any message"); | |
a.printStackTrace(); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment