Commit bc2c042d authored by Eky's avatar Eky

Week 4 work!

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>week4</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=14
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=14
module week4 {
requires java.desktop;
}
\ No newline at end of file
Procedure FREQ
{
array; //instantiate array
mostFreq = array[0]; //initial value of most frequent element set to first element
tempValue = 0; //temporary variable used to compare elements
freqCount = 1; //frequency of previous element checked
tempCount; //temporary variable to track frequency of current element
for(i=0 to i < array.length)
{
tempValue = array[i]; //set tempValue to current element in loop for comparison
tempCount = 0; //set tempCount (and reset to 0 between loops)
for(j=0 to j<array.length)
{
if(tempValue = array[j] //whenever there is a match in elements, increment tempCount
{
tempCount = tempCount + 1;
}
}
if(tempCount > freqCount) //compare previous loop's result with current stored freqCount, if greater then:
{
mostFreq = tempValue; //set the most frequent value to that of the element being analysed
freqCount = tempCount; //set number of times element in question appears to that of tempCount
}
}
return mostFreq;
}
[Using coins, one can place a paper clip under the first in the sequence for every other coin in the sequence of the same value
(including the first), this sets the first 'count' for the number of coins of this value. This can then be repeated with the
next coin in the sequence; remove the smallest pile of paper clips each time this is done. Once one reaches the end of the
sequence, the most frequently occurring value will simply be the coin with paper clips beneath it (as all others will have been
removed)]
\ No newline at end of file
package week4;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
public class Week4Class
{
public static void main(String[] args)
{
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
String[] options = {"Exercise 1", "Exercise 2","Exercise 3", "Exercise 4","Exercise 5", "Exercise 6","Exercise 7", "Exercise 8",
"Exercise 9", "Exercise 10","Exercise 11", "Exercise 12","Exercise 13", "Exercise 14","Mini Project 1", "Mini Project 2",};
JFrame frame = new JFrame("Week 4 Exercises");
JComboBox<String> excercises = new JComboBox<>(options);
excercises.setSelectedIndex(15);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(excercises, BorderLayout.NORTH);
frame.setSize(new Dimension(400, 200));
frame.setVisible(true);
frame.setLocation(dim.width/2-frame.getSize().width/2, dim.height/2-frame.getSize().height/2);
excercises.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent event)
{
@SuppressWarnings("unchecked")
JComboBox<String> combo = (JComboBox<String>) event.getSource();
String select = (String) combo.getSelectedItem();
if (select.equals("Exercise 1"))
{
System.out.println("Exercise 1: ");
exOne();
}
else if (select.equals("Exercise 2"))
{
System.out.println("Exercise 2: ");
exTwo();
}
else if (select.equals("Exercise 3"))
{
System.out.println("Exercise 3: ");
exThree();
}
else if (select.equals("Exercise 4"))
{
System.out.println("Exercise 4: ");
exFour();
}
else if (select.equals("Exercise 5"))
{
System.out.println("Exercise 5: ");
exFive();
}
else if (select.equals("Exercise 6"))
{
System.out.println("Exercise 6: ");
exSix();
}
else if (select.equals("Exercise 7"))
{
System.out.println("Exercise 7: ");
exSeven();
}
else if (select.equals("Exercise 8"))
{
System.out.println("Exercise 8: ");
exEight();
}
else if (select.equals("Exercise 9"))
{
System.out.println("Exercise 9: ");
exNine();
}
else if (select.equals("Exercise 10"))
{
System.out.println("Exercise 10: ");
exTen();
}
else if (select.equals("Exercise 11"))
{
System.out.println("Exercise 11: ");
exEleven();
}
else if (select.equals("Exercise 12"))
{
System.out.println("Exercise 12: ");
exTwelve();
}
else if (select.equals("Exercise 13"))
{
System.out.println("Exercise 13: ");
exThirteen();
}
else if (select.equals("Exercise 14"))
{
System.out.println("Exercise 14: ");
exFourteen();
}
else if (select.equals("Mini Project 1"))
{
System.out.println("Mini Project 1: ");
miniP1();
}
else if (select.equals("Mini Project 2"))
{
System.out.println("Mini Project 2: ");
miniP2();
}
System.out.println("\n");
}
});
}
public static void exOne()
{
int[] arr = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 0 };
int a = 0;
for (int i = 0; i < 10; i++) {
a = a + arr[i]; }
int b = 0;
for (int i = 0; i < 10; i = i + 2) {
b = b + arr[i]; }
int c = 0;
for (int i = 1; i < 10; i = i + 2) {
c = c + arr[i]; }
int d = 0;
for (int i = 2; i < 10; i++) {
d = d + arr[i]; }
int e = 0;
for (int i = 1; i < 10; i = 2 * i) {
e = e + arr[i]; }
int f = 0;
for (int i = 9; i >= 0; i--) {
f = f + arr[i]; }
int g = 0;
for (int i = 9; i >= 0; i = i - 2) {
g = g + arr[i]; }
int h = 0;
for (int i = 0; i < 10; i++) {
h = arr[i] - h; }
System.out.println("Totals:" + "\n" + "a = " + a + ", b = " + b + ", c = " + c + ", d = " + d + ", e = " + e + ", f = " + f
+ ", g = " + g + ", h = " + h);
}
public static void exTwo()
{
System.out.println("Code segment A throws an index out of bounds, segment B's 'values' variable hasn't been properly initialised,"
+"\n"+ " segment C has an array of size 0 and segment D again has 'values' as not properly initialised.");
}
public static void exThree()
{
int[][] table = new int[ 5 ][ 5 ];
for ( int x = 0; x < table.length; x++ )
{
for ( int y = 0; y < table[ x ].length; y++ )
{
table[ x ][ y ] = x + y;
System.out.print(table[x][y]);
}
System.out.println();
}
}
public static void exFour()
{
String[] a = {"1","2","3","4","5","6","7","10","8","9"};
int n = a.length;
System.out.println("array in order = " + Arrays.toString(a));
for (int i = 0; i < n/2; i++)
{
String temp = a[n-i-1];
a[n-i-1] = a[i];
a[i] = temp;
}
System.out.println("array reversed order = " + Arrays.toString(a));
}
public static void exFive()
{
int[] arr1 = {1,2,3,4,5};
int[] arr2 = {1,4,9,16,25,234234,234,1212,5656};
System.out.println("first array = " + Arrays.toString(arr1) + "\n" + "second array = " + Arrays.toString(arr2));
int first = arr1[0], last = arr1[arr1.length-1];
arr1[0] = last;
arr1[arr1.length-1] = first;
int temp1 = arr2[0], temp2 = arr2[1], end = arr2[arr2.length-1];
for(int i=1;i<arr2.length;i++)
{
arr2[i] = temp1;
temp1 = temp2;
if(i<arr2.length-1)
{
temp2 = arr2[i+1];
}
else
{
arr2[0] = end;
break;
}
}
System.out.println("first array after swap = " + Arrays.toString(arr1) + "\n" + "second array after shift = " + Arrays.toString(arr2));
}
public static void exSix()
{
int[] a = {1,4,9,16,9,7,4,9,11};
int n = a.length;
System.out.println("input = " + Arrays.toString(a));
for (int i = 0; i < n/2; i++)
{
int temp = a[n-i-1];
a[n-i-1] = a[i];
a[i] = temp;
}
System.out.println("output = " + Arrays.toString(a));
}
public static void exSeven()
{
List<Integer> inputs = new ArrayList<Integer>();
@SuppressWarnings("resource")
Scanner scan = new Scanner(System.in);
System.out.println("Add to sequence (-1 to end): ");
while (true)
{
int line = Integer.parseInt(scan.nextLine());
if(line == -1)
{
break;
}
else
{
inputs.add(line);
}
}
System.out.println("Initial sequence = " + inputs);
int max = 0;
for(int i=0;i<inputs.size();i++)
{
if(inputs.get(i) > max)
{
max = inputs.get(i);
}
}
System.out.println("Max = " + max);
int[] percentages = new int[inputs.size()];
for(int i=0;i<inputs.size();i++)
{
percentages[i] = 40*inputs.get(i)/max;
System.out.println("Percent = " + percentages[i]);
}
for(int i=0;i<inputs.size();i++)
{
for(int j=0;j<percentages[i];j++)
{
System.out.print("*");
}
System.out.println();
}
}
public static void exEight()
{
int[] arr = {13,17,100,95,47,88,86,92,75,89,81,70,7,55,80};
int[] output = new int[11];
System.out.println("Input: " + Arrays.toString(arr));
for(int i=0;i<arr.length;i++)
{
int input = (int)Math.floor(arr[i]/10);
output[input]++;
}
System.out.println("Output:" + Arrays.toString(output));
System.out.print("00-09 |");
rangeLoops(output[0]);
System.out.println();
System.out.print("10-19 |");
rangeLoops(output[1]);
System.out.println();
System.out.print("20-29 |");
rangeLoops(output[2]);
System.out.println();
System.out.print("30-39 |");
rangeLoops(output[3]);
System.out.println();
System.out.print("40-49 |");
rangeLoops(output[4]);
System.out.println();
System.out.print("50-59 |");
rangeLoops(output[5]);
System.out.println();
System.out.print("60-69 |");
rangeLoops(output[6]);
System.out.println();
System.out.print("70-79 |");
rangeLoops(output[7]);
System.out.println();
System.out.print("80-89 |");
rangeLoops(output[8]);
System.out.println();
System.out.print("90-99 |");
rangeLoops(output[9]);
System.out.println();
System.out.print(" 100 |");
rangeLoops(output[10]);
}
public static void rangeLoops(int output)
{
for(int j=0;j<output;j++)
{
System.out.print("*");
}
}
public static void exNine()
{
Random r = new Random();
@SuppressWarnings("resource")
Scanner scan = new Scanner(System.in);
int[][] theatre = new int[4][26];
for(int i=0;i<theatre.length;i++)
{
for(int j=0;j<theatre[0].length;j++)
{
int rando = (r.nextInt(5)+1)*10;
theatre[i][j] = rando;
}
}
while(true)
{
System.out.println(Arrays.deepToString(theatre));
System.out.println("There are 4 rows available with 26 seats each; " +
"choose a seat (press 1) or a price (press 2) to be assigned a place, (-1) to exit");
int input = scan.nextInt();
if(input == 1)
{
System.out.println("Enter row:");
int row = scan.nextInt();
System.out.println("Enter column:");
int column = scan.nextInt();
chosenSeat(row-1, column-1, theatre);
}
else if(input == 2)
{
System.out.println("Choose a price (10,20,30,40,50)");
int price = scan.nextInt();
switch(price)
{
case 10:randomSeat(10, theatre);
break;
case 20:randomSeat(20, theatre);
break;
case 30:randomSeat(30, theatre);
break;
case 40:randomSeat(40, theatre);
break;
case 50:randomSeat(50, theatre);
break;
}
}
else if(input == -1)
{
break;
}
}
}
public static int[][] chosenSeat(int row, int column, int[][] seats)
{
int[][] theatre = seats;
if(theatre[row][column] != 0)
{
System.out.println("your seat is row " + (row+1) + " column " + (column+1) + " and will cost " + theatre[row][column]);
theatre[row][column] = 0;
}
else
{
System.out.println("this seat is unavailable!");
}
return theatre;
}
public static int[][] randomSeat(int input, int[][] seats)
{
int[][] theatre = seats;
outerloop:
for(int i=0;i<theatre.length;i++)
{
for(int j=0;j<theatre[0].length;j++)
{
if(theatre[i][j]==input)
{
System.out.println("your seat is row " + (i+1) + " column " + (j+1) + " and will cost " + theatre[i][j]);
theatre[i][j] = 0;
break outerloop;
}
else if(theatre[i][j] != input && i == theatre.length-1 && j == theatre[0].length-1)
{
System.out.println("there are no more seats available!");
}
}
}
return theatre;
}
public static void exTen()
{
int[] arr = {0,1,2,3,4,5,4,3,2,1,0,6,17,0,0};
System.out.println("For array: " + Arrays.toString(arr));
System.out.println("Enter a number to find pairs of elements in array whose sum equals said number.");
@SuppressWarnings("resource")
Scanner scan = new Scanner(System.in);
int secondLargest = 0, secondSmallest = 0, temp;
int n = scan.nextInt();
//sorting
for(int i = 0; i<arr.length; i++ )
{
for(int j = i+1; j<arr.length; j++)
{
if(arr[i]>arr[j]){
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
for(int i=arr.length-1;i>0;i--)
{
if(arr[i]<arr[arr.length-1])
{
secondLargest = arr[i];
break;
}
}
for(int i=0;i<arr.length;i++)
{
if(arr[i]>arr[0])
{
secondSmallest = arr[i];
break;
}
}
for(int i=0;i<arr.length;i++)
{
for(int j=i+1;j<arr.length;j++)
{
if(arr[i] + arr[j] == n)
{
System.out.println(arr[i] + " + " + arr[j] + " = " + n);
break;
}
}
}
System.out.println("Duplicate values in this array (number of times duplicated is the total occurences of the number in question) = ");
ArrayList<String> dup = new ArrayList<String>();
for(int i=0;i<arr.length;i++)
{
for(int j=i+1;j<arr.length;j++)
{
if(arr[i] == arr[j])
{
dup.add(Integer.toString(arr[i]));
break;
}
}
}
System.out.println(dup);
System.out.println("The second largest element is = " + secondLargest);
System.out.println("The second smallest element is = " + secondSmallest);
}
public static void exEleven()
{
@SuppressWarnings("resource")
Scanner scan = new Scanner(System.in);
double[] pounds = new double[5];
double[] dollars = new double[5];
double exchange;
double round;
for(int i=0;i<pounds.length;i++)
{
System.out.println("Please enter product price ()");
pounds[i] = scan.nextDouble();
}
System.out.println("Product prices in sterling: " + Arrays.toString(pounds));
System.out.println("Please enter exchange rate from pounds to dollars");
exchange = scan.nextDouble();
for(int i=0;i<pounds.length;i++)
{
round = Math.ceil(pounds[i] * exchange * 100)/100;
dollars[i] = round;
}
System.out.println("Product prices in dollars: " + Arrays.toString(dollars));
}
public static void exTwelve()
{
@SuppressWarnings("resource")
Scanner scan = new Scanner(System.in);
double exchange;
double round;
double totalPounds = 0, totalDollars = 0;
System.out.println("Please enter number of products to buy");
int num = scan.nextInt();
double[] pounds = new double[num];
double[] dollars = new double[num];
for(int i=0;i<num;i++)
{
System.out.println("Please enter product price ()");
pounds[i] = scan.nextDouble();
totalPounds = totalPounds+pounds[i];
}
System.out.println("Product prices in sterling: " + Arrays.toString(pounds));
System.out.println("Please enter exchange rate from pounds to dollars");
exchange = scan.nextDouble();
for(int i=0;i<num;i++)
{
round = Math.ceil(pounds[i] * exchange * 100)/100;
dollars[i] = round;
totalDollars = totalDollars+dollars[i];
}
System.out.println("Product prices in dollars: " + Arrays.toString(dollars));
System.out.println("Total cost in sterling: " + totalPounds + "\n" + "Total cost in dollars: $" + totalDollars);
}
public static void exThirteen()
{
int[] arr = {1,2,5,5,5,1,1,1,10,1,20,1,20,1,1,1,50,50,10,10,10};
int size = arr.length;
int frequent = arr[0], temp = 0, freqCount = 1, tempCount;
for(int i=0;i<size;i++)
{
temp = arr[i];
tempCount = 0;
for(int j=0;j<size;j++)
{
if(temp == arr[j])
{
tempCount++;
}
}
if(tempCount > freqCount)
{
frequent = temp;
freqCount = tempCount;
}
}
System.out.println("For array: " + Arrays.toString(arr));
System.out.println("Most frequent element is: " + frequent);
}
public static void exFourteen()
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter matrix size");
int size = scan.nextInt();
int[][] magic = new int[size][size];
int tempRow, tempColumn, currentRow = 0, currentColumn = 0;
boolean magical = true;
for(int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
{
System.out.println("Declare value of array element at = " + i + "," + j);
magic[i][j] = scan.nextInt();
}
}
outerloop:
for(int i=0;i<size;i++)
{
tempRow = 0;
tempColumn = 0;
for(int j=0;j<size;j++)
{
tempRow = tempRow + magic[i][j];
tempColumn = tempColumn + magic[j][i];
}
if(tempRow != tempColumn && currentRow != currentColumn)
{
System.out.println("For array = " + Arrays.deepToString(magic));
System.out.println("It's not magical!");
magical = false;
break outerloop;
}
currentRow = tempRow;
currentColumn = tempColumn;
}
if(magical == true)
{
System.out.println("For array = " + Arrays.deepToString(magic));
System.out.println("Magical!");
}
}
public static void miniP1()
{
boolean a = false;
boolean[] seats = {a,a,a,a,a,a,a,a,a,a};
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
JFrame frame = new JFrame("Airline Reservations System");
JTextArea input = new JTextArea();
JTextArea output = new JTextArea();
JButton button = new JButton("OK");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(input, BorderLayout.NORTH);
frame.getContentPane().add(button, BorderLayout.CENTER);
frame.getContentPane().add(output, BorderLayout.SOUTH);
frame.setSize(new Dimension(400, 200));
frame.setVisible(true);
frame.setLocation(dim.width/2-frame.getSize().width/2, dim.height/2-frame.getSize().height/2);
output.setText("Please type 1 for First Class" + "\n" + "Please type 2 for Economy");
button.addActionListener(new ActionListener()
{
int numberInput;
@Override
public void actionPerformed(ActionEvent event)
{
numberInput = Integer.parseInt(input.getText());
if(numberInput == 1 && seats[seats.length/2 -1] == false)
{
for(int i=0;i<seats.length/2;i++)
{
if(seats[i] == false)
{
seats[i] = true;
output.setText("Your seat number is: " + (i+1) + " First Class");
System.out.println(Arrays.toString(seats));
break;
}
}
}
else if(numberInput == 1 && seats[seats.length/2 -1] == true)
{
output.setText("First Class is full, would you like an Economy seat instead? (y=3/n=4)");
}
else if(numberInput == 2 && seats[seats.length -1] == false)
{
for(int i=seats.length/2;i<seats.length;i++)
{
if(seats[i] == false)
{
seats[i] = true;
output.setText("Your seat number is: " + (i+1) + " Economy");
System.out.println(Arrays.toString(seats));
break;
}
}
}
else if(numberInput == 2 && seats[seats.length -1] == true)
{
output.setText("Economy is full, would you like a First Class seat instead? (y=3/n=4)");
}
else if(numberInput == 3)
{
checkAllSeats(seats, numberInput, output);
System.out.println(Arrays.toString(seats));
}
else if(numberInput == 4)
{
output.setText("Next flight leaves in 3 hours.");
}
}
});
System.out.println(Arrays.toString(seats));
}
public static boolean[] checkAllSeats(boolean[] arr, int input, JTextArea output)
{
for(int i=0;i<arr.length;i++)
{
if(arr[i] == false && i>=arr.length/2)
{
arr[i] = true;
output.setText("Your seat number is: " + (i+1) + " Economy");
break;
}
if(arr[i] == false && i<arr.length/2)
{
arr[i] = true;
output.setText("Your seat number is: " + (i+1) + " First Class");
break;
}
else
{
output.setText("No more seats available! The next flight leaves in 3 hours.");
}
}
return arr;
}
public static void miniP2()
{
String[] arr = {"Domestic Politics","Economics","Environment","War","Europe"};
String[] columns = {"","1","2","3","4","5","6","7","8","9","10","Average"};
int[][] results = new int[5][10];
String[][] end = new String[6][12];
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
JFrame frame = new JFrame("Polling System");
JTextArea input = new JTextArea();
JTextArea output = new JTextArea();
JButton button = new JButton("Add Rating");
JButton buttonTwo = new JButton("Show Results");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(input, BorderLayout.NORTH);
frame.getContentPane().add(button, BorderLayout.WEST);
frame.getContentPane().add(buttonTwo, BorderLayout.EAST);
frame.getContentPane().add(output, BorderLayout.CENTER);
frame.setSize(new Dimension(400, 200));
frame.setVisible(true);
frame.setLocation(dim.width/2-frame.getSize().width/2, dim.height/2-frame.getSize().height/2);
for(int i=0;i<5;i++)
{
for(int j=0;j<10;j++)
{
results[i][j] = 0;
}
}
output.setText("Please rate the importance of Domestic Politics (1-10)");
button.addActionListener(new ActionListener()
{
int num = 0;
int rating;
@Override
public void actionPerformed(ActionEvent event)
{
System.out.println(num);
rating = Integer.parseInt(input.getText());
results[num][rating-1] = results[num][rating-1] + 1;
num++;
if(num == 5){num = 0;}
switch(num)
{
case 0: output.setText("Please rate the importance of " + arr[0] + " (1-10)");break;
case 1: output.setText("Please rate the importance of " + arr[1] + " (1-10)");break;
case 2: output.setText("Please rate the importance of " + arr[2] + " (1-10)");break;
case 3: output.setText("Please rate the importance of " + arr[3] + " (1-10)");break;
case 4: output.setText("Please rate the importance of " + arr[4] + " (1-10)");break;
}
System.out.println(Arrays.deepToString(results));
}
});
buttonTwo.addActionListener(new ActionListener()
{
int average, divisor, temp, tempTwo, highest, lowest, iPosHigh, iPosLow;
int[] totals = new int[5];
int[] otherTotals = new int[5];
@Override
public void actionPerformed(ActionEvent eventTwo)
{
for(int i=0;i<5;i++)
{
end[i][0] = arr[i];
}
for(int i=0;i<5;i++)
{
average = 0;
divisor = 0;
for(int j=0;j<10;j++)
{
end[i][j+1] = Integer.toString(results[i][j]);
temp = temp + results[i][j]*(j+1);
for(int k=0;k<results[i][j];k++)
{
average = average + j + 1;
divisor = divisor + 1;
}
}
totals[i] = temp;
otherTotals[i] = temp;
temp = 0;
if(divisor == 0)
{
average = 0;
}
else{average = average/divisor;}
end[i][11] = Integer.toString(average);
}
for(int i = 0; i<totals.length; i++ )
{
for(int j = i+1; j<totals.length; j++)
{
if(totals[i]>totals[j]){
tempTwo = totals[i];
totals[i] = totals[j];
totals[j] = tempTwo;
}
}
}
lowest = totals[0];
highest = totals[4];
for(int i=0;i<totals.length;i++)
{
if(otherTotals[i] == lowest)
{
iPosLow = i;
}
if(otherTotals[i] == highest)
{
iPosHigh = i;
}
}
System.out.println(Arrays.toString(totals));
System.out.println(Arrays.toString(otherTotals));
JTable table = new JTable(end,columns);
JTextArea highLow = new JTextArea();
JFrame resultFrame = new JFrame();
JScrollPane scroll = new JScrollPane(table);
highLow.setText("The highest point total was " + arr[iPosHigh] + " at " + highest + " points." + "\n" +
"The lowest point total was " + arr[iPosLow] + " at " + lowest + " points.");
resultFrame.setTitle("Results");
resultFrame.add(scroll);
resultFrame.getContentPane().add(highLow, BorderLayout.SOUTH);
resultFrame.setSize(500, 200);
resultFrame.setVisible(true);
}
});
System.out.println(Arrays.deepToString(results));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment