Please follow the comments and please do exactly according to the comments. import java.util.Scanner; public class SortTemps { public static final int MAX_TEMPS = 1000; // As specified in the directions.    public static void main(String[] args) { // Temporary arrays to store all the incoming data. int[] temperature = new int[MAX_TEMPS]; String[] city = new String[MAX_TEMPS]; int longestCityLength = 0; // Needed to make temperatures line up int count = 0; // Counts actual number of pairs    Scanner inScanner = new Scanner(System.in);    System.out.println("Enter temperature & city pairs:");    while (inScanner.hasNextInt()) { temperature[count] = inScanner.nextInt(); city[count] = inScanner.nextLine().trim(); if (city[count].length() > longestCityLength) { longestCityLength = city[count].length(); } count += 1; }    // RIGHT AFTER THIS COMMENT declare an instantiate cityTempPairArray // to be an array of length count, holding objects that store the // city/temperature pairs. // HINT: you will have to create a class declaration (in another // .java file) for a new type of class that holds a city // and temperature pair.          for (int i = 0; i < count; i += 1) { // REPLACE the following two lines with code that // constructs a new object holding city[i] and temperature[i], // and store that new object in cityTempPairArray[i]. String padding = " ".repeat(longestCityLength - city[i].length() + 1); System.out.println(city[i] + padding + temperature[i]);    }    // Insert code to bubble sort cityTempPairArray, putting the // object with the highest temperature at slot 0.    System.out.println("The data sorted by temperature--highest first:");    // Insert code to print the contents of cityTempPairArray to output. // Use the strategy I used in the first for loop above // to line the temperatures up in columns.       }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please follow the comments and please do exactly according to the comments.


import java.util.Scanner;

public class SortTemps
{
public static final int MAX_TEMPS = 1000;
// As specified in the directions.
  
public static void main(String[] args)
{
// Temporary arrays to store all the incoming data.
int[] temperature = new int[MAX_TEMPS];
String[] city = new String[MAX_TEMPS];

int longestCityLength = 0; // Needed to make temperatures line up
int count = 0; // Counts actual number of pairs
  
Scanner inScanner = new Scanner(System.in);
  
System.out.println("Enter temperature & city pairs:");
  
while (inScanner.hasNextInt())
{
temperature[count] = inScanner.nextInt();
city[count] = inScanner.nextLine().trim();
if (city[count].length() > longestCityLength)
{
longestCityLength = city[count].length();
}
count += 1;
}
  
// RIGHT AFTER THIS COMMENT declare an instantiate cityTempPairArray
// to be an array of length count, holding objects that store the
// city/temperature pairs.
// HINT: you will have to create a class declaration (in another
// .java file) for a new type of class that holds a city
// and temperature pair.
  
  
  
for (int i = 0; i < count; i += 1)
{
// REPLACE the following two lines with code that
// constructs a new object holding city[i] and temperature[i],
// and store that new object in cityTempPairArray[i].
String padding = " ".repeat(longestCityLength - city[i].length() + 1);
System.out.println(city[i] + padding + temperature[i]);   
}
  
// Insert code to bubble sort cityTempPairArray, putting the
// object with the highest temperature at slot 0.
  
System.out.println("The data sorted by temperature--highest first:");
  
// Insert code to print the contents of cityTempPairArray to output.
// Use the strategy I used in the first for loop above
// to line the temperatures up in columns.
  
   }
  
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY