Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java: Create a Graduate class derived from Student. A graduate has an attribute (a String) called degree, which is either Masters or Doctorate, and

In Java:

Create a Graduate class derived from Student. A graduate has an attribute (a String) called degree, which is either "Masters" or "Doctorate", and a boolean called thesis (meaning whether they have completed their thesis and initially set to false). Write all methods .

Sort students, undergrads and grads according to ID. Sort Faculty according to Department and Staff according to Salary.

undergrad.inDownload undergrad.in

graduate.inDownload graduate.in

staff.inDownload staff.in

faculty.in

import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner;

public class H9 {

public static void main(String[] args) { /******************************* * UNDERGRADUATES * ***************************/ File inFile = new File("undergrad.in"); Scanner fileInput = null; try { fileInput = new Scanner(inFile); } catch (FileNotFoundException ex) { //Logger.getLogger(Lab10.class.getName()).log(Level.SEVERE, null, ex); } //create an arrayList ArrayList myList = new ArrayList(); //input into the ArrayList while(fileInput.hasNext()) { int id=fileInput.nextInt(); int lev=fileInput.nextInt(); String name=fileInput.nextLine(); Undergraduate s=new Undergraduate(name, id, lev); myList.add(s); } //sort the arrayList Collections.sort(myList); //Output the sorted list System.out.println("*************************************"); System.out.println("The undergrads sorted according to ID"); System.out.println("*************************************"); for(int i=0; i myList2 = new ArrayList(); //input into the ArrayList while(fileInput.hasNext()) { int id=fileInput.nextInt(); String lev=fileInput.next(); String thesis=fileInput.next(); boolean t; if(thesis.equals("yes")) t=true; else t=false; String name=fileInput.nextLine(); Graduate s=new Graduate(name, id, lev, t); myList2.add(s); } //sort the arrayList Collections.sort(myList2); //Output the sorted list System.out.println("*************************************"); System.out.println("The grads sorted according to ID"); System.out.println("*************************************"); for(int i=0; i myList3 = new ArrayList(); //input into the ArrayList while(fileInput.hasNext()) { double salary =fileInput.nextDouble(); int year=fileInput.nextInt(); int ID = fileInput.nextInt(); String dept=fileInput.next(); String title=fileInput.next(); String name=fileInput.nextLine(); Faculty s=new Faculty(title, name, salary, year,ID, dept); myList3.add(s); } //sort the arrayList Collections.sort(myList3); //Output the sorted list System.out.println("*************************************"); System.out.println("The faculty sorted according to department"); System.out.println("*************************************"); for(int i=0; i myList4 = new ArrayList(); //input into the ArrayList while(fileInput.hasNext()) { double salary =fileInput.nextDouble(); int year=fileInput.nextInt(); int ID = fileInput.nextInt(); String dept=fileInput.next(); int PG=fileInput.nextInt(); String name=fileInput.nextLine(); Staff s=new Staff(PG, name, salary, year,ID, dept); myList4.add(s); } //sort the arrayList Collections.sort(myList4); //Output the sorted list System.out.println("*************************************"); System.out.println("The staff sorted according to salary"); System.out.println("*************************************"); for(int i=0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions

Question

What are some global issues confronting women?

Answered: 1 week ago