Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java 1 Objective: Write a Java program that will perform calculations on histori

ID: 3861183 • Letter: J

Question

Java 1

Objective: Write a Java program that will perform calculations on historic weather data stored in arrays.

1. Before You Begin

Follow this with the name of the program: guiHighLowTemp.

Use good comments.

Think about the problem and decide what type each of the input numbers should be. Also, think about the calculations and decide what type the variables should be that will hold the results of the calculations.

Use camel casing for variable names, and use descriptive variable names. Do not use general variable names like "tax" or "total."

Use a drop-down box loaded with the yearTemp array to allow the user to select a year so that the program can look up the high and low temperatures for January of the selected year.

Below the user-selected year and the high and low for January of that year, display the average high and the average low for all years combined. Since this will not change with the users selection, you have options as to when you will do this calculation. You might even do this calculation before the user selects the year. You decide.

Once the user selects the year and triggers an event, the logic would be as follows:

The year the user selected would need to be looked up in the yearTemp array.

The matching index for the high and low temperatures would be accessed from the highLowTemp array.

The average daily temperature will be calculated from the high and low temperature.

The average daily temperature will be displayed along with the average for all years of high and low temperatures.

2.2. The Arrays

Answer must be in GUI format, but the layout is up to you.


The data will be stored in two arrays, one will contain all of the years (string data), and the other will be a two dimensional array containing the high and low temperatures for the month of January for each of the years listed above.

Explanation / Answer

Here is the code segment of given criteria, please go through it thoroughly:-

import java.util.InputMismatchException;

import java.util.Scanner;

import java.util.Stack;

public class UndirectedConnectivityDfs

{

private Stack<Integer> stack;

public UndirectedConnectivityDfs()

{

stack=new Stack<Integer>();

}

public void dfs(int adjacency_matrix[][], int source)

{

int number_Of_Nodes = adjacency_matrix[source].length - 1;

int visited[] = new int[number_Of_Nodes + 1];

int element = source;

int i = source;

visited[source] = 1;

stack.push(source);

while (!stack.isEmpty())

{

element = stack.peek();

i = element;

while (i <= number_Of_Nodes)

{

if (adjacency_matrix[element][i] == 1 && visited[i] == 0)

{

stack.push(i);

visited[i] = 1;   

element = i;

i = 1;

continue;   

}

i++;

}

stack.pop();

}

boolean connected = false;

for(int vertex = 1; vertex<= number_Of_Nodes; vertex++ )

{

if(visited[vertex] == 1)

{

connected = true;

} else

{

connected = false;

break;

}

}

if(connected)

{

System.out.println("Graph is connected");

} else

{

System.out.println("Graph is disconnected");

}

}

public static void main(String... arg)

{

int number_of_nodes, source;

Scanner scanner = null;

try

{

System.out.println("Enter the number of nodes in the graph");

scanner = new Scanner(System.in);

number_of_nodes = scanner.nextInt();

int adjacency_matrix[][] = new int[number_of_nodes + 1][number_of_nodes + 1];

System.out.println("Enter the adjacency matrix");

for (int i = 1; i <= number_of_nodes; i++)

for (int j = 1; j <= number_of_nodes; j++)

adjacency_matrix[i][j] = scanner.nextInt();

for (int i = 1; i <= number_of_nodes; i++)

{

for (int j = 1; j <= number_of_nodes; j++)

{

if (adjacency_matrix[i][j] == 1 && adjacency_matrix[j][i] == 0)

{

adjacency_matrix[j][i] = 1;

}

}

}

System.out.println("Enter the source for the graph");

source = scanner.nextInt();

UndirectedConnectivityDfs UndirectedConnectivity = new UndirectedConnectivityDfs();

UndirectedConnectivity.dfs(adjacency_matrix,source);

} catch (InputMismatchException inputMismatch)

{

System.out.println("Wrong Input format");

}

scanner.close();

}

}

Please run these codes into your window and check out the output.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote