Results 1 to 2 of 2
Thread: Converting an array in an object
- 01-31-2011, 04:08 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 4
- Rep Power
- 0
Converting an array in an object
Hey i got myself confused with how to change this.damages = strArr[2]; to a double as i need to be able to mutiply the values within it.
Any help would be great
Java 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; String damages; String earlierRelief; String severity; String allottedReliefPersonnel; public Australia(String[] strArr) { this.cityName = strArr[0]; this.population = strArr[1]; this.damages = strArr[2]; this.earlierRelief = strArr[3]; this.severity = 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); }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); } }
- 01-31-2011, 04:18 PM #2
Member
- Join Date
- Oct 2010
- Posts
- 63
- Rep Power
- 0
Similar Threads
-
Converting value of array to log
By monika in forum New To JavaReplies: 4Last Post: 05-14-2010, 08:10 AM -
Need help converting int to a 4 byte array
By kook04 in forum Advanced JavaReplies: 5Last Post: 02-26-2010, 08:59 PM -
stumpt. converting an object to a long int.
By root_demon in forum New To JavaReplies: 7Last Post: 10-31-2008, 05:32 AM -
Converting object to string
By Preethi in forum New To JavaReplies: 4Last Post: 06-14-2008, 03:29 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks