diff --git a/bin/IntroToArrayLists/GuestBook.class b/bin/IntroToArrayLists/GuestBook.class index 07daef5..d5bdbe5 100644 Binary files a/bin/IntroToArrayLists/GuestBook.class and b/bin/IntroToArrayLists/GuestBook.class differ diff --git a/bin/IntroToArrayLists/IntroToArrayLists.class b/bin/IntroToArrayLists/IntroToArrayLists.class index 0fc2b88..8d6f298 100644 Binary files a/bin/IntroToArrayLists/IntroToArrayLists.class and b/bin/IntroToArrayLists/IntroToArrayLists.class differ diff --git a/bin/IntroToHashMaps/IntroToHashMaps.class b/bin/IntroToHashMaps/IntroToHashMaps.class index 2a8da29..d3be531 100644 Binary files a/bin/IntroToHashMaps/IntroToHashMaps.class and b/bin/IntroToHashMaps/IntroToHashMaps.class differ diff --git a/bin/IntroToHashMaps/LogSearch.class b/bin/IntroToHashMaps/LogSearch.class index 66817f4..09dfd12 100644 Binary files a/bin/IntroToHashMaps/LogSearch.class and b/bin/IntroToHashMaps/LogSearch.class differ diff --git a/bin/IntroToStacks/IntroToStack.class b/bin/IntroToStacks/IntroToStack.class index 026ae9e..3042e92 100644 Binary files a/bin/IntroToStacks/IntroToStack.class and b/bin/IntroToStacks/IntroToStack.class differ diff --git a/bin/IntroToStacks/TextUndoRedo.class b/bin/IntroToStacks/TextUndoRedo.class index 5a758e7..72c370c 100644 Binary files a/bin/IntroToStacks/TextUndoRedo.class and b/bin/IntroToStacks/TextUndoRedo.class differ diff --git a/src/IntroToArrayLists/GuestBook.java b/src/IntroToArrayLists/GuestBook.java index a192b10..d591e34 100644 --- a/src/IntroToArrayLists/GuestBook.java +++ b/src/IntroToArrayLists/GuestBook.java @@ -1,6 +1,22 @@ package IntroToArrayLists; -public class GuestBook { +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JPanel; + + +public class GuestBook implements ActionListener { + JFrame a; + JPanel pan; + JButton add; + JButton view; + String viewNames; + ArrayList names = new ArrayList(); // Create a GUI with two buttons. One button reads "Add Name" and the other button reads "View Names". // When the add name button is clicked, display an input dialog that asks the user to enter a name. Add // that name to an ArrayList. When the "View Names" button is clicked, display a message dialog that displays @@ -9,4 +25,49 @@ public class GuestBook { // Guest #2: Sandy Summers // Guest #3: Greg Ganders // Guest #4: Donny Doners +public static void main(String[] args) { + GuestBook a = new GuestBook(); + a.activate(); +} +public void activate() { + names.add("Bob Banders"); + names.add("Sandy Summers"); + names.add("Greg Ganders"); + names.add("Donny Doners"); + a = new JFrame(); + a.setVisible(true); + pan = new JPanel(); + add = new JButton(); + view = new JButton(); + a.add(pan); + pan.add(add); + pan.add(view); + + add.setText("Add Name"); + view.setText("View Names"); + add.addActionListener(this); + view.addActionListener(this); + + + + a.pack(); +} +@Override +public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + if(e.getSource() == add) { + String name = JOptionPane.showInputDialog("Enter a name"); + names.add(name); + } + if(e.getSource() ==view ) { + for(String s : names) { + if(s != null) + viewNames = viewNames + s + "\n"; + + }JOptionPane.showMessageDialog(null, viewNames ); + } +} + + + } diff --git a/src/IntroToArrayLists/IntroToArrayLists.java b/src/IntroToArrayLists/IntroToArrayLists.java index 4c006e4..1c55a69 100644 --- a/src/IntroToArrayLists/IntroToArrayLists.java +++ b/src/IntroToArrayLists/IntroToArrayLists.java @@ -1,20 +1,49 @@ package IntroToArrayLists; +import java.util.ArrayList; + public class IntroToArrayLists { + public static void main(String[] args) { - //1. Create an array list of Strings - // Don't forget to import the ArrayList class - - //2. Add five Strings to your list - - //3. Print all the Strings using a standard for-loop - - //4. Print all the Strings using a for-each loop - - //5. Print only the even numbered elements in the list. - - //6. Print all the Strings in reverse order. - - //7. Print only the Strings that have the letter 'e' in them. - } + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + // 1. Create an array list of Strings + ArrayList strings = new ArrayList(); + // Don't forget to import the ArrayList class + + // 2. Add five Strings to your list + strings.add(a); + strings.add(b); + strings.add(c); + strings.add(d); + strings.add(e); + // 3. Print all the Strings using a standard for-loop + for (int i = 0; i < 5; i++) { + System.out.println(strings.get(i)); + + } + + // 4. Print all the Strings using a for-each loop + for (String i : strings) { + System.out.println(i); + + } + // 5. Print only the even numbered elements in the list. + for (int i = 0; i < 5; i++) { + if (i % 2 == 0) { + System.out.println(strings.get(i)); + + } + } // 6. Print all the Strings in reverse order. + for (int i = 4; i >= 0; i--) { + System.out.println(strings.get(i)); + + } + // 7. Print only the Strings that have the letter 'e' in them. + System.out.println(e); + + } } diff --git a/src/IntroToHashMaps/IntroToHashMaps.java b/src/IntroToHashMaps/IntroToHashMaps.java index 18978ea..c9920a9 100644 --- a/src/IntroToHashMaps/IntroToHashMaps.java +++ b/src/IntroToHashMaps/IntroToHashMaps.java @@ -1,16 +1,28 @@ package IntroToHashMaps; +import java.util.HashMap; + +import org.omg.IOP.CodecPackage.FormatMismatch; + public class IntroToHashMaps { - //1. Create a HashMap called roots with Integers for the keys and Doubles for the values. - + static //1. Create a HashMap called roots with Integers for the keys and Doubles for the values. + HashMap roots; //2. Using a for-loop, add 500 entries to your HashMap. The key entry will be the // current iteration of the loop (i). The value entry will be the square root of i. - - //3. Iterate through all the entries in your HashMap displaying the keys with their respective + public static void main(String[] args) { + roots = new HashMap(); + for(int i = 0;i < 500 ; i++) { + roots.put(i, Math.sqrt(i) ); + System.out.println("The square Root of " + i + " is " + roots.get(i)); + } + + } + //3. Iterate through all the entries in your HashMap displaying the keys with their respective // square roots (values). Use the following format. // The square Root of 0 is 0.0 // The square Root of 1 is 1.0 // The square Root of 2 is 1.4142135623730951 // The square Root of 3 is 1.7320508075688772 -} + +} \ No newline at end of file diff --git a/src/IntroToHashMaps/LogSearch.java b/src/IntroToHashMaps/LogSearch.java index 4a671ac..036aa21 100644 --- a/src/IntroToHashMaps/LogSearch.java +++ b/src/IntroToHashMaps/LogSearch.java @@ -1,31 +1,86 @@ package IntroToHashMaps; -public class LogSearch { - /* - * Crate a HashMap of Integers for the keys and Strings for the values. - * Create a GUI with three buttons. - * Button 1: Add Entry - * When this button is clicked, use an input dialog to ask the user to enter an ID number. - * After an ID is entered, use another input dialog to ask the user to enter a name. - * Add this information as a new entry to your HashMap. +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.HashMap; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JPanel; + +public class LogSearch implements ActionListener { + JFrame fram = new JFrame(); + JPanel pan = new JPanel(); + JButton add = new JButton(); + JButton view = new JButton(); + JButton search = new JButton(); + HashMap values; + String list; + /* + * Crate a HashMap of Integers for the keys and Strings for the values. Create a + * GUI with three buttons. Button 1: Add Entry When this button is clicked, use + * an input dialog to ask the user to enter an ID number. After an ID is + * entered, use another input dialog to ask the user to enter a name. Add this + * information as a new entry to your HashMap. * - * Button 2: Search by ID - * When this button is clicked, use an input dialog to ask the user to enter an ID number. - * If that ID exists, display that name to the user. - * Otherwise, tell the user that that entry does not exist. + * Button 2: Search by ID When this button is clicked, use an input dialog to + * ask the user to enter an ID number. If that ID exists, display that name to + * the user. Otherwise, tell the user that that entry does not exist. * - * Button 3: View List - * When this button is clicked, display the entire list in a message dialog in the following format: - * ID: 123 Name: Harry Howard - * ID: 245 Name: Polly Powers - * ID: 433 Name: Oliver Ortega - * etc... + * Button 3: View List When this button is clicked, display the entire list in a + * message dialog in the following format: ID: 123 Name: Harry Howard ID: 245 + * Name: Polly Powers ID: 433 Name: Oliver Ortega etc... * - * When this is complete, add a fourth button to your window. - * Button 4: Remove Entry - * When this button is clicked, prompt the user to enter an ID using an input dialog. - * If this ID exists in the HashMap, remove it. Otherwise, notify the user that the ID - * is not in the list. + * When this is complete, add a fourth button to your window. Button 4: Remove + * Entry When this button is clicked, prompt the user to enter an ID using an + * input dialog. If this ID exists in the HashMap, remove it. Otherwise, notify + * the user that the ID is not in the list. * - * */ + */ + public static void main(String[] args) { + LogSearch a = new LogSearch(); + a.activate(); + + } + + void activate() { + values = new HashMap(); + fram.add(pan); + pan.add(add); + pan.add(search); + pan.add(view); + add.addActionListener(this); + view.addActionListener(this); + search.addActionListener(this); + fram.setVisible(true); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (e.getSource() == add) { + String id = JOptionPane.showInputDialog("Enter an ID"); + String entry = JOptionPane.showInputDialog("Enter a name"); + values.put(Integer.parseInt(id), entry); + } + if (e.getSource() == search) { + String ifin = JOptionPane.showInputDialog("What is your Id"); + if (values.containsKey(Integer.parseInt(ifin))) { + JOptionPane.showMessageDialog(null, values.get(Integer.parseInt(ifin))); + + } else { + JOptionPane.showMessageDialog(null, "The value is not in the system"); + } + } + if (e.getSource() == view) { + list = ""; + for(int x: values.keySet()) { + list= "ID: " + x + "Name: " + values.get(x) ; + + } + JOptionPane.showMessageDialog(null, list); + + } + } + } diff --git a/src/IntroToStacks/IntroToStack.java b/src/IntroToStacks/IntroToStack.java index d4a4c65..f3c603f 100644 --- a/src/IntroToStacks/IntroToStack.java +++ b/src/IntroToStacks/IntroToStack.java @@ -1,10 +1,14 @@ package IntroToStacks; +import java.util.Stack; + public class IntroToStack { public static void main(String[] args) { + IntroToStack a = new IntroToStack(); + //1. Create a Stack of Doubles // Don't forget to import the Stack class - + Stack values; //2. Use a loop to push 100 random doubles between 0 and 100 to the Stack. //3. Ask the user to enter in two numbers between 0 and 100, inclusive. @@ -26,4 +30,6 @@ public static void main(String[] args) { // 66.47984807 // 74.12121224 } + } + diff --git a/src/IntroToStacks/TextUndoRedo.java b/src/IntroToStacks/TextUndoRedo.java index 3c961df..cd90029 100644 --- a/src/IntroToStacks/TextUndoRedo.java +++ b/src/IntroToStacks/TextUndoRedo.java @@ -1,6 +1,25 @@ package IntroToStacks; -public class TextUndoRedo { +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.nio.charset.Charset; +import java.util.Stack; + +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; + +public class TextUndoRedo implements KeyListener{ + JFrame a; + JPanel b; + JLabel main; + Stack back; + + public static void main(String[] args) { + TextUndoRedo main = new TextUndoRedo(); + main.activate(); + } + /* * Create a JFrame with a JPanel and a JLabel. * @@ -13,5 +32,47 @@ public class TextUndoRedo { * off the Stack and added back to the JLabel. * * */ - + void activate() { + a = new JFrame(); + b = new JPanel(); + main = new JLabel(); + a.add(b); + b.add(main); + a.setVisible(true); + a.pack(); + a.addKeyListener(this); + back = new Stack(); + } + + @Override + public void keyTyped(KeyEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void keyPressed(KeyEvent e) { + // TODO Auto-generated method stub + char a = e.getKeyChar(); + + if(e.getKeyCode() == KeyEvent.VK_0) { + System.out.println("should Pop"); + System.out.println(back.pop()); + main.setText(main.getText() + back.pop()); + } + if(a != KeyEvent.VK_0) main.setText(main.getText() + a); + if(e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { + String s = main.getText(); + System.out.println("should Delete"); + back.push(s.substring(s.length()-2)); + main.setText(s.substring(0, s.length()-2)); + + } + } + + @Override + public void keyReleased(KeyEvent e) { + // TODO Auto-generated method stub + + } }