Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help in converting this into pseudo-code Student.java public class Student implements Comparable { private String name, major, status; private int rank; public Student()

I need help in converting this into pseudo-code

Student.java

public class Student implements Comparable{ private String name, major, status; private int rank; public Student() { this.name = this.major = this.status = ""; this.rank = 0; } public Student(String name, String major, String status) { this.name = name; this.major = major; this.status = status; }

public String getName() { return name; }

public String getMajor() { return major; }

public String getStatus() { return status; } public int getRank() { return this.rank; } public void setRank(int rank) { this.rank = rank; } @Override public String toString() { return("Name: " + this.name + ", Major: " + this.major + ", Status: " + this.status); }

@Override public int compareTo(Student o) { if(this.rank < o.getRank()) return -1; else if(this.rank == o.getRank()) return 0; else return 1; } }

RankIndividuals.java

import java.util.ArrayList; import java.util.Collections;

public class RankIndividuals { private ArrayList students; private ArrayList ranks; public RankIndividuals() { this.students = new ArrayList<>(); this.ranks = new ArrayList<>(); } public void addStudents(Student student) { this.students.add(student); } public void giveRank() { for(int i = 0; i < students.size(); i++) { if(students.get(i).getStatus().equalsIgnoreCase("Excellent")) students.get(i).setRank(1); if(students.get(i).getStatus().equalsIgnoreCase("Very Good")) students.get(i).setRank(2); if(students.get(i).getStatus().equalsIgnoreCase("Good")) students.get(i).setRank(3); if(students.get(i).getStatus().equalsIgnoreCase("Average")) students.get(i).setRank(4); if(students.get(i).getStatus().equalsIgnoreCase("Bad")) students.get(i).setRank(5); } Collections.sort(this.students); } public void displayAllStudents() { for(Student st : this.students) { System.out.println(st); } } }

RankerApp.java (Main class)

public class RankerApp { public static void main(String[] args) { RankIndividuals individuals = new RankIndividuals(); individuals.addStudents(new Student("John", "Computer Science", "Good")); individuals.addStudents(new Student("Alice", "Geography", "Excellent")); individuals.addStudents(new Student("Henry", "Physics", "Average")); individuals.addStudents(new Student("Maxx", "English", "Bad")); individuals.addStudents(new Student("Joseph", "Chemistry", "Average")); individuals.addStudents(new Student("Nuke", "Mathematics", "Very Good")); System.out.println("STUDENTS BEFORE RANKING: ------------------------"); individuals.displayAllStudents(); individuals.giveRank(); System.out.println(" STUDENTS AFTER RANKING: -----------------------"); individuals.displayAllStudents(); } }

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

DB2 9 For Linux UNIX And Windows Advanced Database Administration Certification Certification Study Guide

Authors: Roger E. Sanders, Dwaine R Snow

1st Edition

1583470808, 978-1583470800

More Books

Students also viewed these Databases questions