Multiplying specific data within a arraylist
Hey, I'm currently stuck trying to figure out how to multiply the data in the, this.severity = Double.parseDouble(strArr[4]);, and this.damages = Double.parseDouble(strArr[2]);. The multiplying would take place under the ChangeListener .Any help would be grateful I'm guessing its something simple I'm just over looking.
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.util.Scanner;
import javax.swing.JOptionPane;
import javax.swing.plaf.ColorUIResource;
import java.lang.*;
import java.util.Collections;
public class guiFinal extends JFrame {
private JButton Load = new JButton("Load");
private JButton Reset = new JButton("Reset");
private JButton Change = new JButton("Change");
private JButton quitButton = new JButton("Quit");
Scanner reader = new Scanner(System.in);
String input1 = "";//input from first dialog box
public class Australia {
String cityName;
String population;
double damages;
String earlierRelief;
double severity;
String allottedReliefPersonnel;
public Australia(String[] strArr) {
this.cityName = strArr[0];
this.population = strArr[1];
this.damages = Double.parseDouble(strArr[2]);
this.earlierRelief = strArr[3];
this.severity = Double.parseDouble(strArr[4]);
this.allottedReliefPersonnel = strArr[5];
}
public String toString() {
return "City name: " + cityName + ", Population: " + population + ", Damages: " + damages + ", Earlier Relief: " + earlierRelief + ", Severity: " + severity+ ", Allotted Relief Personnel: " + allottedReliefPersonnel ;
}
}
public void experiment() {
}
public guiFinal(){
JPanel centerPanel = new JPanel(new GridLayout(4, 1));
JPanel northPanel = new JPanel(new GridLayout(1, 3));
JPanel westPanel = new JPanel(new GridLayout(8, 1));
JPanel eastPanel = new JPanel(new GridLayout(4, 1));
JPanel southPanel = new JPanel(new GridLayout(1, 4));
Container container = getContentPane();
container.add(westPanel, BorderLayout.WEST);
container.add(northPanel, BorderLayout.NORTH);
container.add(southPanel, BorderLayout.SOUTH);
container.add(eastPanel, BorderLayout.CENTER);
eastPanel.add(Load);
eastPanel.add(Reset);
eastPanel.add(Change);
eastPanel.add(quitButton);
Load.addActionListener(new LoadListener());
Reset.addActionListener(new ResetListener());
Change.addActionListener(new ChangeListener());
quitButton.addActionListener(new exitListener());
}
public class LoadListener implements ActionListener{
public void actionPerformed(ActionEvent e){
ArrayList<Australia> damageReports = new ArrayList<Australia>();
File x = new File(
"C:/Users/James/Documents/JCreator LE/MyProjects/Final/src/something.txt");
try {
BufferedReader in = new BufferedReader(new FileReader(x));
String line;
while ((line = in.readLine())!= null) {
String[] listgrab = line.split(",");
Australia p = new Australia(listgrab);
damageReports.add(p);
System.out.println(p.toString());
}
in.close();
}
catch (Exception fe)
{
System.out.print("Wrong data has been inputed into the program, Please do not do that again");
}
}
}
private class ChangeListener implements ActionListener{
public void actionPerformed(ActionEvent e){
try{
input1 = JOptionPane.showInputDialog
( "What percentage would you like to increase the damage by?" );
double input2 = Double.parseDouble(input1);// retriving the number to change the percentage by
}catch(Exception asdf){
javax.swing.JOptionPane.showMessageDialog(null,"Please use numbers only");
}
}
}
private class ResetListener implements ActionListener{
public void actionPerformed(ActionEvent e){
try{
input1 = JOptionPane.showInputDialog
( "Lists have been cleared" );
}catch(Exception asdf){
javax.swing.JOptionPane.showMessageDialog(null,"Please use numbers only");
}
}
}
private class exitListener implements ActionListener{
public void actionPerformed(ActionEvent e){
System.exit(0);
}
}
public static void main (String [] args){
guiFinal theGUI = new guiFinal();
theGUI.setTitle("James Tiitson");
theGUI.setSize(500, 350);
theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
theGUI.setVisible(true);
}
}