Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bin/IntroToArrayLists/GuestBook.class
Binary file not shown.
Binary file modified bin/IntroToArrayLists/IntroToArrayLists.class
Binary file not shown.
Binary file modified bin/IntroToHashMaps/IntroToHashMaps.class
Binary file not shown.
Binary file modified bin/IntroToHashMaps/LogSearch.class
Binary file not shown.
Binary file modified bin/IntroToStacks/IntroToStack.class
Binary file not shown.
Binary file modified bin/IntroToStacks/TextUndoRedo.class
Binary file not shown.
63 changes: 62 additions & 1 deletion src/IntroToArrayLists/GuestBook.java
Original file line number Diff line number Diff line change
@@ -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<String> names = new ArrayList<String>();
// 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
Expand All @@ -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 );
}
}



}
59 changes: 44 additions & 15 deletions src/IntroToArrayLists/IntroToArrayLists.java
Original file line number Diff line number Diff line change
@@ -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<String> strings = new ArrayList<String>();
// 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);

}
}
22 changes: 17 additions & 5 deletions src/IntroToHashMaps/IntroToHashMaps.java
Original file line number Diff line number Diff line change
@@ -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<Integer, Double> 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<Integer, Double>();
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
}

}
103 changes: 79 additions & 24 deletions src/IntroToHashMaps/LogSearch.java
Original file line number Diff line number Diff line change
@@ -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<Integer, String> 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<Integer, String>();
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);

}
}

}
8 changes: 7 additions & 1 deletion src/IntroToStacks/IntroToStack.java
Original file line number Diff line number Diff line change
@@ -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<Double> 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.
Expand All @@ -26,4 +30,6 @@ public static void main(String[] args) {
// 66.47984807
// 74.12121224
}

}

65 changes: 63 additions & 2 deletions src/IntroToStacks/TextUndoRedo.java
Original file line number Diff line number Diff line change
@@ -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<String> back;

public static void main(String[] args) {
TextUndoRedo main = new TextUndoRedo();
main.activate();
}

/*
* Create a JFrame with a JPanel and a JLabel.
*
Expand All @@ -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<String>();
}

@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

}
}