Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions CalculationController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.countries;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

// localhost:8080/calc/salary?id=1&raise=0.5
@RestController
@RequestMapping("/calc")
public class CalculationController
{
@RequestMapping("/salary")
public Country checkRaise(@RequestParam(value = "name") String name,
@RequestParam(value = "population") int population)
{
Country tempCountry = new Country(CountriesApplication.ourCountryList.findCountry(c -> (c.getName().equals(name))));
tempCountry.setPopulation(tempCountry.getPopulation() * (1 + population));
return tempCountry;
}



}
6 changes: 6 additions & 0 deletions CheckCountry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.countries;

public interface CheckCountry
{
boolean test(Country c);
}
18 changes: 18 additions & 0 deletions CountriesApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.countries;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CountriesApplication {

static CountryList ourCountryList;
public static void main(String[] args)
{
ourCountryList = new CountryList();
SpringApplication.run(CountriesApplication.class, args);

}
}


56 changes: 56 additions & 0 deletions Country.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.example.countries;

public class Country
{
private String name;
private int population;
private double landMass;
private int medianAge;

public Country(String name, int population, double landMass, int medianAge) {
this.name = name;
this.population = population;
this.landMass = landMass;
this.medianAge = medianAge;
}

public Country(Country toClone)
{
this.name = toClone.getName();
this.population = toClone.getPopulation();
this.landMass = toClone.getLandMass();
this.medianAge = toClone.getMedianAge();
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getPopulation() {
return population;
}

public void setPopulation(int population) {
this.population = population;
}

public double getLandMass() {
return landMass;
}

public void setLandMass(double landMass) {
this.landMass = landMass;
}

public int getMedianAge() {
return medianAge;
}

public void setMedianAge(int medianAge) {
this.medianAge = medianAge;
}
}
131 changes: 131 additions & 0 deletions CountryController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package com.example.countries;
//localhost:8080/data/allCountries

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
public class CountryController
{
// return the names of all the countries alphabetically
@RequestMapping("/names/allCountries")
public ArrayList<String> getAllCountries()
{
ArrayList<String> newList = new ArrayList<>();
for (Country c : CountriesApplication.ourCountryList.countryList)
newList.add(c.getName());
newList.sort((c1, c2) -> c1.compareToIgnoreCase(c2));
return newList;
}

// return the countries alphabetically that begin with the given letter
@RequestMapping("/names/begin")
public ArrayList<Country> getCountryDetail(@RequestParam(value = "letter") char letter)
{
ArrayList<Country> newList = new ArrayList<>();
for (Country c : CountriesApplication.ourCountryList.countryList)
if (c.getName().charAt(0) == Character.toUpperCase(letter))
newList.add(c);
newList.sort((c1, c2) -> c1.getName().compareToIgnoreCase(c2.getName()));
return newList;
}

// return the countries alphabetically that have a name equal to or longer than the given length
@RequestMapping("/names/size")
public ArrayList<Country> getCountrySize(@RequestParam(value = "letters") int letters)
{
ArrayList<Country> newList = new ArrayList<>();
for (Country c : CountriesApplication.ourCountryList.countryList)
if (c.getName().length() == letters)
newList.add(c);
newList.sort((c1, c2) -> c1.getName().compareToIgnoreCase(c2.getName()));
return newList;
}

// return the countries that have a population equal to or greater than the given population
@RequestMapping("/population/size")
public ArrayList<Country> getPopulationSize(@RequestParam(value = "people") int people)
{
ArrayList<Country> newList = new ArrayList<>();
for (Country c : CountriesApplication.ourCountryList.countryList)
if (c.getPopulation() >= people)
newList.add(c);
newList.sort((c1, c2) -> c1.getName().compareToIgnoreCase(c2.getName()));
return newList;
}

// return the country with the smallest population
@RequestMapping("/population/min")
public Country getMinPopulation()
{
int min = 1000000000;
Country minCountry = new Country("NA", 0, 0, 0);
for (Country c : CountriesApplication.ourCountryList.countryList) {
if (c.getPopulation() <= min) {
min = c.getPopulation();
minCountry = c;
}
}
return minCountry;
}

// return the country with the largest population
@RequestMapping("/population/max")
public Country getMaxPopulation()
{
int max = 0;
Country maxCountry = new Country("NA", 0, 0, 0);
for (Country c : CountriesApplication.ourCountryList.countryList) {
if (c.getPopulation() >= max) {
max = c.getPopulation();
maxCountry = c;
}
}
return maxCountry;
}

// return the countries that have a median age equal to or greater than the given age
@RequestMapping("/age/age")
public ArrayList<Country> getByAge(@RequestParam(value = "age") int age)
{
ArrayList<Country> newList = new ArrayList<>();
for (Country c : CountriesApplication.ourCountryList.countryList)
if (c.getMedianAge() == age)
newList.add(c);
newList.sort((c1, c2) -> c1.getName().compareToIgnoreCase(c2.getName()));
return newList;
}

// return the country with the smallest population
@RequestMapping("/age/min")
public Country getMinAge()
{
int min = 1000;
Country minCountry = new Country("NA", 0, 0, 0);
for (Country c : CountriesApplication.ourCountryList.countryList) {
if (c.getMedianAge() <= min) {
min = c.getMedianAge();
minCountry = c;
}
}
return minCountry;
}

// return the country with the largest population
@RequestMapping("/age/max")
public Country getMaxAge()
{
int max = 0;
Country maxCountry = new Country("NA", 0, 0, 0);
for (Country c : CountriesApplication.ourCountryList.countryList) {
if (c.getMedianAge() >= max) {
max = c.getMedianAge();
maxCountry = c;
}
}
return maxCountry;
}
}
Loading