import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import org.json.JSONObject; public class Myclass { public static void main(String[] args) throws Exception { try { URL url = new URL("https://parseapi.back4app.com/classes/City?count=1&limit=10&keys=name,population"); HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection(); urlConnection.setRequestProperty("X-Parse-Application-Id", "mxsebv4KoWIGkRntXwyzg6c6DhKWQuit8Ry9sHja"); // This is the fake app's application id urlConnection.setRequestProperty("X-Parse-Master-Key", "TpO0j3lG2PmEVMXlKYQACoOXKQrL3lwM0HwR9dbH"); // This is the fake app's readonly master key try { BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); StringBuilder stringBuilder = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { stringBuilder.append(line); } JSONObject data = new JSONObject(stringBuilder.toString()); // Here you have the data that you need System.out.println(data.toString(2)); } finally { urlConnection.disconnect(); } } catch (Exception e) { System.out.println("Error: " + e.toString()); } } } --------------------------------------------- This is the code I have so far for part 2. Am I doing this correctly? public class city { private String name; private int population; public City (String cityName, int cityPop) { name = cityName; population = cityPop; } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.net.HttpURLConnection;

import java.net.URL;

import java.net.URLEncoder;

 

import org.json.JSONObject;

 

public class Myclass {

    public static void main(String[] args) throws Exception {

        try {

            URL url = new URL("https://parseapi.back4app.com/classes/City?count=1&limit=10&keys=name,population");

            HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();

            urlConnection.setRequestProperty("X-Parse-Application-Id", "mxsebv4KoWIGkRntXwyzg6c6DhKWQuit8Ry9sHja"); // This is the fake app's application id

            urlConnection.setRequestProperty("X-Parse-Master-Key", "TpO0j3lG2PmEVMXlKYQACoOXKQrL3lwM0HwR9dbH"); // This is the fake app's readonly master key

            try {

                BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));

                StringBuilder stringBuilder = new StringBuilder();

                String line;

                while ((line = reader.readLine()) != null) {

                    stringBuilder.append(line);

                }

                JSONObject data = new JSONObject(stringBuilder.toString()); // Here you have the data that you need

                System.out.println(data.toString(2));

            } finally {

                urlConnection.disconnect();

            }

        } catch (Exception e) {

            System.out.println("Error: " + e.toString());

        }

    }

}

---------------------------------------------

This is the code I have so far for part 2. Am I doing this correctly?

public class city

 

{

 

     private String name;

 

     private int population;

 

     public City (String cityName, int cityPop)

 

     {

 

          name = cityName;

 

          population = cityPop;

 

        

 

     }

}

 

Part 2. Access all city population data from this API. Write a Java program to find cities in top 50% -
55% in terms of population.
• Must create city as Class / object, which contains: String name, and int population.
• To implement comparable interface at city Class, so that two cities can use compareTo( )
method based on population.
It's recommended to use Java library container, such as ArrayList. in your program. Refer to
Chapter 3. Also read generic type at assigned reading section in Chapter 1.
Transcribed Image Text:Part 2. Access all city population data from this API. Write a Java program to find cities in top 50% - 55% in terms of population. • Must create city as Class / object, which contains: String name, and int population. • To implement comparable interface at city Class, so that two cities can use compareTo( ) method based on population. It's recommended to use Java library container, such as ArrayList. in your program. Refer to Chapter 3. Also read generic type at assigned reading section in Chapter 1.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Files and Directory
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education