NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import java.util.Scanner;

import java.io.Serializable;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;

public class Student implements Serializable {
private int id;
private String name;
private float developmentScore;
private float operationScore;
private float mathScore;
private String status;

public static String FILE_NAME = "student_list.txt";

public Student() {
this.id = 0;
this.name = "";
this.developmentScore = 0;
this.operationScore = 0;
this.mathScore = 0;
this.status = "unknown";
}

public Student(int id, String name, float developmentScore, float operationScore, float mathScore, String status)
{
this.id = id;
this.name = name;
this.developmentScore = developmentScore;
this.operationScore = operationScore;
this.mathScore = mathScore;
this.status = status;
}

public void printInfo()
{
System.out.println("ID: " + this.id);
System.out.println("Name: " + this.name);
System.out.println("Development Score: " + this.developmentScore);
System.out.println("Operation Score: " + this.operationScore);
System.out.println("Match Score: " + this.mathScore);
System.out.println("Status: " + this.status);
}

public void inputId()
{
Scanner sc = new Scanner(System.in);

do {
System.out.println("Input your id: ");
while (!sc.hasNextInt()) {
System.out.println("Wrong data! Please input right your id: ");
sc.next();
}
this.id = sc.nextInt();
} while (this.id <= 0);
}

public void inputName()
{
System.out.println("Input your name: ");
Scanner sc = new Scanner(System.in);
while(sc.hasNextLine()) {
this.name = sc.nextLine();
}
}

public void inputDevelopmentScore()
{
System.out.println("Input your development score: ");
Scanner sc = new Scanner(System.in);
while(sc.hasNextFloat()) {
this.developmentScore = sc.nextFloat();
}
}

public void inputOperationScore()
{
System.out.println("Input your operation score: ");
Scanner sc = new Scanner(System.in);
while(sc.hasNextFloat()) {
this.developmentScore = sc.nextFloat();
}
}

public void inputMathScore()
{
System.out.println("Input your math score: ");
Scanner sc = new Scanner(System.in);
while(sc.hasNextFloat()) {
this.developmentScore = sc.nextFloat();
}
}

public void inputStatus()
{
System.out.println("Input your status: ");
Scanner sc = new Scanner(System.in);
while(sc.hasNextLine()) {
this.status = sc.nextLine();
}
}

public void inputAllInfo()
{
this.inputId();
this.inputName();
this.inputDevelopmentScore();
this.inputOperationScore();
this.inputMathScore();
this.inputStatus();
}

public boolean isExists()
{
List<Student> listStudent = readListFromFile();

if (listStudent == null) {
return true;
}

for(Student student: listStudent) {
if (this.id == student.id) {
return false;
}
}

return true;
}

public static boolean writeListToFile(Student student) throws IOException
{
try {

FileOutputStream f = new FileOutputStream(new File(FILE_NAME));
ObjectOutputStream o = new ObjectOutputStream(f);

ArrayList<Student> listStudent = new ArrayList<Student>();
listStudent.add(student);
// Write objects to file
o.writeObject(listStudent);

o.close();
f.close();

return true;
} catch (FileNotFoundException e) {
System.out.println("File not found");
} catch (IOException e) {
System.out.println("Error initializing stream");
}

return false;
}

public static List<Student> readListFromFile()
{
try {
FileInputStream f = new FileInputStream(new File(FILE_NAME));
ObjectInputStream o = new ObjectInputStream(f);

// Read objects
ArrayList<Student> result = (ArrayList<Student>) o.readObject();

o.close();
f.close();

return result;
} catch (FileNotFoundException e) {
System.out.println("File not found");
} catch (IOException e) {
System.out.println("Error initializing stream");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return null;
}

public static Student readLatestFromFile()
{
List<Student> listStudent = readListFromFile();

if (listStudent == null) {
return null;
}

return listStudent.get(listStudent.size() - 1);
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.