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
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...
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...
java ASAP Assume that you have tracked daily minutes of you work out for a week. Save the following data into a text file in a notepad. 50 10 36 11 47 30 Write a java program that reads the minutes for a week from the text file that you created. Read the minutes from the input file into the array in one execution of the program.write a java method to find out the maximum and minimum values. Your program...
this is advance java Monster ARray Summary: Write a program that shows the path of an imaginary monster moving through a two dimensional array trying to "eat" the highest values in the array. As the monster goes, it leaves a trail behind it. Imagine a 40x40 array, displayed like this, where Os are printed as periods (dots), and non-zero valués are printed as normal. Then, place the values 2 through 9 randomly on the array. The rest of the document...
Write a complete Java program which has two methods, one to enter values for an array and another one to sort it using Bubble Sort method. Draw DIAGRAMS for memory allocation, AR and ARI for the program.