Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming: Requirements: 1. Reuse your Country class from Project 1 (correct it if necessary) 2. Create a class named Stack that will implement a

Java Programming: Requirements: 1. Reuse your Country class from Project 1 (correct it if necessary) 2. Create a class named Stack that will implement a stack of country objects using an array. Support the following methods. a. Constructor that creates the stack array based on a size provided. b. A push method to push a country on the stack. c. A pop method to pop a country off the stack and return it. d. A printStack method to print the stack from top down to bottom of it. e. An isEmpty method that returns true if the stack is empty, false otherwise f. An isFull method that returns true if the stack is full, false otherwise 3. Create a class named Priority that implements a priority queue of country objects using a sorted array, based on GDP per capita, the higher the GDP per capita, the higher the priority. Support the following methods: a. Constructor that creates the stack array based on a size provided. b. An insert method to insert a country into the queue. (This should be an O(N) method.) c. A remove method to remove a country from the front of the queue and return it. (This should be an O(1) method.) d. A printQueue method to print the queue in priority order. e. An isEmpty method that returns true if the priority queue is empty, false otherwise f. An isFull method that returns true if the priority queue is full, false otherwise 4. Create a class named Project2 that will: a. Let us define five groups of countries based on GDP per capita: POOR countries as those with GDP per capita <1 thousand, FAIR no less than 1 thousand but <5 thousand, GOOD no less than 5 thousand but <20 thousand, VGOOD no less than 20 thousand but <50 thousand, and EXCELLENT no less than 50 thousand. b. Create five priority queues, one for each group. c. Read the csv file (Countries2.csv) and insert country objects into the corresponding priority queues based on the defined groups. d. Print the five priority queues in the order of POOR, FAIR, GOOD, VGOOD and EXCELLENT. e. Create one stack. f. Remove items from the POOR priority queue, one at a time, and push them on the stack. g. Remove items from the FAIR priority queue, one at a time, and push them on the stack. h. Remove items from the GOOD priority queue, one at a time, and push them on the stack. i. Remove items from the VGOOD priority queue, one at a time, and push them on the stack. j. Remove items from the EXCELLENT priority queue, one at a time, and push them on the stack. k. Print the stack, then exit the program.

Here is the country class:

class Country { private String name; private String code; private String capitol; private int population; private double GDP; private int happinessRank; //data fields public Country() { } public Country(String name, String code, String capitol, int population, double GDP, int happinessRank) { //constructor this.name = name; this.code = code; this.capitol = capitol; this.population = population; this.GDP = GDP; this.happinessRank = happinessRank; } public String getName() { return name; //return new name string from setString; } public void setName(String name) { this.name = name; //sets name to object parameter } public String getCode() { return code; // returns new code integer obtained from setCode } public void setCode (String code) { this.code = code; //sets code to code passed from object parameter } public String getCapitol() { return capitol; } public void setCapitol (String capitol) { this.capitol = capitol; //same task as other set methods } public int getPopulation() { return population; } public void setPopulation(int population) { this.population = population; } public double getGDP() { return GDP; } public void setGDP(double GDP) { this.GDP = GDP; } public int getHappinessRank() { return happinessRank; } public void setHappinessRank(int happinessRank) { this.happinessRank = happinessRank; } public void display() { System.out.println("Country Name: " + name); System.out.println("Code: " + code); System.out.println("Capital: " + capitol); System.out.println("Population: " + population); System.out.println("GDP: " + GDP); System.out.println("Happiness: " + happinessRank); }

@Override public String toString() { return name + " " + code + " " + capitol + " " + population + " " + GDP + " " + happinessRank; } //compares two class objects public int compareTo(Country otherCountry) { return this.getName().compareTo(otherCountry.getName()); } }

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

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

Identify the steps that lead to forming a bargaining unit.

Answered: 1 week ago