Skip to content

Instantly share code, notes, and snippets.

@rohangho
Created May 14, 2019 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rohangho/2598d29f7cfcd99b8e18d370fa2fa65f to your computer and use it in GitHub Desktop.
Save rohangho/2598d29f7cfcd99b8e18d370fa2fa65f to your computer and use it in GitHub Desktop.
public class Accountant {
int id;
String name;
public Accountant(int id, String name) {
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class Student {
int id;
String name;
int feeDue;
public Student(int id, String name, int feeDue) {
this.id = id;
this.name = name;
this.feeDue = feeDue;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getFeeDue() {
return feeDue;
}
public void setFeeDue(int feeDue) {
this.feeDue = feeDue;
}
}
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
static ArrayList<Accountant> listOfAccountant = new ArrayList<Accountant>();
static ArrayList<Student> listOfStudent = new ArrayList<Student>();
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("Enter admin/accountant to enter or exit to get out of the system");
String position = sc.next();
if (position.equals("exit"))
break;
if (position.equals("admin")) {
while (true) {
System.out.println("1-add");
System.out.println("2-view");
System.out.println("3-edit");
System.out.println("4-delete");
System.out.println("5-exit");
int input = sc.nextInt();
if (input == 1) {
System.out.println("Enter id of accountant");
int a = sc.nextInt();
System.out.println("Enter name of Accountant");
String b = sc.next();
Accountant accountant = new Accountant(a, b);
listOfAccountant.add(accountant);
} else if (input == 2) {
for (int i = 0; i < listOfAccountant.size(); i++) {
if (listOfAccountant.get(i) != null)
System.out.println(listOfAccountant.get(i).getId() + " " + listOfAccountant.get(i).getName());
}
} else if (input == 4) {
System.out.println("Enter the id od the accountant you want to delete");
int a = sc.nextInt();
for (int i = 0; i < listOfAccountant.size(); i++) {
if (a == listOfAccountant.get(i).getId())
listOfAccountant.set(i, null);
}
}
if (input == 3) {
System.out.println("Enter the id of the accountant you want to edit");
int a = sc.nextInt();
int positionOfEdit = -1;
for (int i = 0; i < listOfAccountant.size(); i++) {
if (a == listOfAccountant.get(i).getId()) {
positionOfEdit = i;
break;
}
}
System.out.println("Enter the edited id of the person");
int b = sc.nextInt();
System.out.println("Enter the edited new name of the person");
String c = sc.next();
Accountant accountant = new Accountant(b, c);
listOfAccountant.set(positionOfEdit, accountant);
}
if (input == 5)
break;
}
}
if (position.equals("accountant")) {
while (true) {
System.out.println("Enter your id");
int a = sc.nextInt();
int found = -1;
if (listOfAccountant.size() == 0) {
System.out.println("The admin hasn't add any accountant yet contact the admin");
break;
}
for (int i = 0; i < listOfAccountant.size(); i++) {
if (a == listOfAccountant.get(i).getId())
found = 1;
}
if (found == 1) {
System.out.println("1-Add");
System.out.println("2-View");
System.out.println("3-Edit");
System.out.println("4-Delete");
System.out.println("5-Check Dues");
System.out.println("6-LogOut");
int k = sc.nextInt();
if (k == 1) {
System.out.println("Enter id of student");
int b = sc.nextInt();
System.out.println("Enter name of the student");
String name = sc.next();
System.out.println("Enter amount due");
int due = sc.nextInt();
Student student = new Student(b, name, due);
listOfStudent.add(student);
}
if (k == 2 || k == 5) {
for (int i = 0; i < listOfStudent.size(); i++) {
if (listOfStudent.get(i) != null)
System.out.println(listOfStudent.get(i).id + " " + listOfStudent.get(i).getName() + " " + listOfStudent.get(i).getFeeDue());
}
}
if (k == 3) {
System.out.println("Enter the id of student to edit");
int id = sc.nextInt();
int positioToFound = -1;
for (int i = 0; i < listOfStudent.size(); i++) {
if (id == listOfStudent.get(0).getId()) {
positioToFound = i;
break;
}
}
System.out.println("eNTER THE EDITED ID");
int v = sc.nextInt();
System.out.println("Enter the edited name");
String s = sc.next();
System.out.println("Enter the edited due amount");
int d = sc.nextInt();
Student student = new Student(v, s, d);
listOfStudent.set(positioToFound, student);
}
if (k == 4) {
System.out.println("Enter the id of student to delete");
int idToDelete = sc.nextInt();
for (int i = 0; i < listOfStudent.size(); i++) {
if (listOfStudent.get(0).getId() == idToDelete) {
listOfStudent.set(i, null);
break;
}
}
}
if (k == 6)
break;
} else {
System.out.println("Your ID seems Invalid we are logging you out");
break;
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment