I have two parallel arrays. one is type String and the other, type int. I want to sort them in ascending order while maintaining data consistency, keeping them parallel, to get the entry with the greatest int value and the entry with the int lowest value.
package sortparallelarray;
import javax.swing.JOptionPane;
public class SortParallelArray {
static String product[] = {"chips", "sweets", "juice", "cookies", "ice cream", "chocolate"};
static int price[] = {5, 3, 7, 6, 9, 8};
public static void main(String[] args) {
// the elements are displayed in the order they were hard coded, unsorted.
displayArrays(formatDisplay());
}
public static void displayArrays(String displayable) {
JOptionPane.showMessageDialog(null,displayable);
}
public static String formatDisplay() {
String result="";
for (int i = 0; i < price.length; i++) {
result += "Product : "+product[i] +" Price : R" +price[i]+"\n";
}
return result;
}
public static void sortArraysInAscendingNumericalOrder() {
}
public static String getGreatestElementInPriceArray(){
String greatestElement = "Most expensive product\n\n";
sortArraysInAscendingNumericalOrder();
return greatestElement;}
public static String getSmallestElementInPriceArray(){
String SmallestElement = "Cheapest pruduct\n\n";
return SmallestElement;}
}
}
}
}