package myja; import java.awt.GridLayout; import java.io.*; import java.util.*; import javax.swing.*; class Student { String Name; int RollNo; int Marks; public Student() { Name = ""; RollNo = 0; Marks = 0; } public Student(String Name, int RollNo, int Marks) { this.Name = Name; this.RollNo = RollNo; this.Marks = Marks; } Student(String string, int parseInt, int parseInt0, int parseInt1) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } public String getName() { return Name; } public void setName(String Name) { this.Name = Name; } public int getRollNo() { return RollNo; } public void setRollNo(int RollNo) { this.RollNo = RollNo; } public int getMarks() { return Marks; } public void setMarks(int Marks) { this.Marks = Marks; } } public class myja { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here JFrame frame = new JFrame(); GridLayout layout = new GridLayout(0,3); frame.setLayout(layout); try{ FileReader fr = null; BufferedReader br = null; fr = new FileReader("D:/waq/input.txt"); br = new BufferedReader(fr); String line = br.readLine(); String [] data = null; frame.add(new JLabel("Name")); frame.add(new JLabel("Roll #")); frame.add(new JLabel("Marks")); List<Student> list = new ArrayList(); while(line != null){ //data = line.split("\t"); data = line.split(" "); list.add(new Student(data[0],Integer.parseInt(data[1]),Integer.parseInt(data[2]))); line = br.readLine(); } fr.close(); int total =0; for (Student student : list) { System.out.println("Name: "+student.getName() + " Roll # : "+ student.getRollNo()+ " Marks : "+ student.getMarks()); frame.add(new JLabel(student.getName())); frame.add(new JLabel(String.valueOf(student.getRollNo()))); frame.add(new JLabel(String.valueOf(student.getMarks()))); total += student.getMarks(); } frame.add(new JLabel("Average Marks : " +(total/list.size()))); System.out.println("Average: " + (total/list.size())); } catch(IOException e){ System.out.println("File Not Found"); } frame.setSize(400, 200); frame.setVisible(true); } }
data = line.split(" "); list.add(new Student(data[0],Integer.parseInt(data[1]),Integer.parseInt(data[2])));
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)