IN JAVA
Write a program that uses a two-dimensional array to store daily minutes walked and carb intake for a week. Prompt the user for 7 days of minutes walked and carb intake; store in the array. Write a sort ( your choice which sort ) to report out the sorted minute values -lowest to highest. Write another to report out the sorted carb intake - highest to lowest. These methods MUST be your original code. Your program should output all the values in the array and then output the 2 sorted outputs. You must use an array to receive credit for this assignment.
Your code MUST be your own work and should not be copied from another student, website or any other source. You will be required to complete a sort of an array (or two) in your final lab - making this lab very important to get correct. Make sure you write all the methods listed above for full credit.
If you have any problem with the code feel free to comment.
Program
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);// for taking console input
int[][] ar = new int[7][2];
//taking use input
for(int i=0; i<ar.length; i++)
{
System.out.print("Enter minutes walked: ");
ar[i][0] =
sc.nextInt();
System.out.print("Enter carbs: ");
ar[i][1] =
sc.nextInt();
System.out.println();
}
System.out.println("Sorting by
Minutes Walked");
sortByWalkingMinutes(ar);
display(ar);
System.out.println();
System.out.println("Sorting by
Carbs");
sortByCarbs(ar);
display(ar);
sc.close();
}
/*using selection sort*/
public static void sortByWalkingMinutes(int[][] ar)
{
for (int i = 0; i < ar.length;
i++) {
int min =
i;
for (int j = i;
j < ar.length; j++) {
if (ar[min][0] > ar[j][0])
min = j;
}
//swpaing
values
int temp =
ar[min][0];
int temp2 =
ar[min][1];
ar[min][0] =
ar[i][0];
ar[min][1] =
ar[i][1];
ar[i][0] =
temp;
ar[i][1] =
temp2;
}
}
//sorting in reverse order
public static void sortByCarbs(int[][] ar) {
for (int i = 0; i < ar.length;
i++) {
int min =
i;
for (int j = i;
j < ar.length; j++) {
if (ar[min][1] < ar[j][1])
min = j;
}
//swaping
values
int temp =
ar[min][1];
int temp2 =
ar[min][0];
ar[min][1] =
ar[i][1];
ar[min][0] =
ar[i][0];
ar[i][1] =
temp;
ar[i][0] =
temp2;
}
}
//displaying 2d array
public static void display(int[][] ar) {
System.out.println("Minutes
Walked\tCarbs");
for(int i=0; i<ar.length; i++)
{
for(int j=0;
j<ar[0].length; j++) {
System.out.print(ar[i][j]+" \t\t");
}
System.out.println();
}
}
}
Output
![<terminated> Test (1) [Java Application] C:\Program FilesJava\jre1.8.0_211\bin\javaw.exe (12-Nov-2019, 2:07:39 pm) LIILC NaIN](http://img.homeworklib.com/questions/0e59ad70-12ad-11ec-9d11-436935bb7a6a.png?x-oss-process=image/resize,w_560)
IN JAVA Write a program that uses a two-dimensional array to store daily minutes walked and...
Write a program that uses a two-dimensional array to store daily minutes walked and protein intake for a week. Prompt the user for 7 days of minutes exercise and protein intake; store in the array. Write a bubble sort to report out the sorted minutes walked values -lowest to highest. Write another to report out the sorted protein intake - highest to lowest. Your program should output all the values stored in the array and then output the 2 sorted...
In JAVA Create a program with an array with the following data: 50 12 31 76 5 23 15 Use a text file (.txt created in notepad) to read the data into the array. Write a sort method (your choice of sorting algorithm) to sort the array values values - highest to lowest. Write a method to determine the minimum value. Your program should call the sort and minimum methods. Output the sorted array and minimum value.
Create a JAVA program with an array with the following data: 50 12 31 76 5 23 15 Use a text file (.txt created in notepad) to read the data into the array. Write a sort method (your choice of sorting algorithm) to sort the array values values - FROM HIGHEST TO LOWEST. Write a method to determine the minimum value. Your program should call the sort and minimum methods. Output the sorted array and minimum value.
Please write a Java program that does the following: Create an array of 100 integers. Store 100 random integers (between 1 and 100) in the array. Print out the elements of the array. Sort the array in ascending order. Print out the sorted array. Prompt the user to enter a number between 1 and 100. Search the array for that number and then display "Found" or "Not Found" message. Display each number from 1 to 100 and the number of...
java pseudocode and source code help?
Write a program that uses an array of high temperatures for your hometown from last week (Sunday - Saturday). Write methods to calculate and return the lowest high temperature (minimum) and a method to calculate and return the highest high temperature (maximum) in the array. You must write YOUR ORIGINAL methods for minimum and maximum. You MAY NOT use Math class methods or other library methods. Write an additional method that accepts the array...
Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year. Your program must consist of the following functions 1. Function getData: This function reads and stores data in the two- dimensional array. 2. Function averageHigh: This function calculates and returns the aver- age high temperature for the year. 3. Function averageLow:...
Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. You should also have a parallel array to store the names of the 12 months. The program should read the Month's names, and the temperatures from a given input file called temperature.txt. The program should output the highest and lowest temperatures for the year, and the months that correspond to those temperatures. The program must use the following functions:...
********** PLEASE PROVIDE IN JAVA & NEW SET OF ALGORITHM For this lab use the program at the bottom to sort an array using selection sort. Write a selection sort to report out the sorted low values: lowest to highest. Write another to report out the sorted high values – highest to lowest. Last but not least, the program should output all the values in the array AND then output the 2 requested sorted outputs. -----> MY OLD PROGRAM BELOW...
Write a JAVA Program: Compare the performance of bubble sort and selection sort over several arrays. - Write two methods that sort arrays of doubles. One method should use selection sort, and the other should use bubble sort. - In each of the sort methods, add code that counts the total number of comparisons and total number of swaps performed while sorting the entire array (be careful; don't count each pass through the array separately) - Each time an array...
Write a C++ program that uses a two dimensional array to display a table of probabilities for a pair of rolling dice. Your custom assigned range of values of each die are: 5 up to and including 10. Section 1 of Program - Specifications: The top row of the table, left to right, and the left column of the array, top to bottom, must contain the assigned range of values displayed on each of the die in ascending order populated...