Student Example
Student Example
//data members
//Constructors
public Student() {
this.name = "";
this.age = 0;
this.name = name;
this.age = age;
return name;
return age;
this.name = name;
}
public void setAge(int age) {
this.age = age;
@Override
package studentp;
import java.util.Scanner;
public Menu()
int choice;
do
System.out.println("---Menu------");
System.out.println("4/Sort by name");
System.out.println("6/Quit");
System.out.println("---------------------");
System.out.print("Choose function:");
choice = Integer.parseInt(sc.nextLine());
switch(choice)
case 2: st.ListAll();break;
Student x = st.Search(name);
if (x == null)
System.out.print("not found");
else
st.View(x);
break;
case 4: st.SortByName();
st.ListAll();
break;
case 5: st.SaveData();break;
case 6: break;
package studentp;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.io.*;
import java.util.Collections;
//Methods
System.out.print("Enter name:");
System.out.print("Enter age:");
list.add(new Student(name,age));
{
String name;
int age;
try
name = value[0];
age = Integer.parseInt(value[1]);
list.add(new Student(name,age));
br.close();
catch(Exception e)
System.out.println(e.getMessage());
try
writer.close();
}catch(Exception e){
System.out.println(e.getMessage());
System.out.println(x.toString());
for(Student x: list)
if (x.getName().contains(name))
return x;
}
return null;
System.out.print(x.toString());
package studentp;
import java.util.Comparator;
return s1.getName().compareTo(S2.getName());
package studentp;