Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.

Commit

Permalink
Classwork from February 12, 2019
Browse files Browse the repository at this point in the history
  • Loading branch information
neilbalch committed Feb 12, 2019
1 parent 1eba198 commit aef129f
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 147 deletions.
1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

278 changes: 131 additions & 147 deletions .idea/workspace.xml

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions Q3/02122019/02122019.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
11 changes: 11 additions & 0 deletions Q3/02122019/Card.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Card {
private int value;

public Card(int value) {
this.value = value;
}

public int getValue() { return value; }

public String toString() { return value + ""; }
}
117 changes: 117 additions & 0 deletions Q3/02122019/Practice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import java.util.ArrayList;

public class Practice {
public String getDomain(String email) { return email.substring(email.indexOf('@')); }

public void print(Card[] cards) {
for(Card c : cards) {
System.out.print(c + ", ");
}
System.out.println();
}

public void print(ArrayList<Card> cards) {
for(Card c : cards) {
System.out.print(c + ", ");
}
System.out.println();
}

public int getLargest(Card[] cards) {
int max = cards[0].getValue();
for(Card c : cards) {
if(c.getValue() > max) max = c.getValue();
}

return max;
}

public int getLargest(ArrayList<Card> cards) {
int max = cards.get(0).getValue();
for(Card c : cards) {
if(c.getValue() > max) max = c.getValue();
}

return max;
}

public int getSmallest(Card[] cards) {
int min = cards[0].getValue();
for(Card c : cards) {
if(c.getValue() < min) min = c.getValue();
}

return min;
}

public int getSmallest(ArrayList<Card> cards) {
int min = cards.get(0).getValue();
for(Card c : cards) {
if(c.getValue() < min) min = c.getValue();
}

return min;
}

public void scramble(Card[] cards) {
for(int i = 0; i < cards.length; i++) {
int index = (int)(cards.length * Math.random());

Card temp = cards[i];
cards[i] = cards[index];
cards[index] = temp;
}
}

public void scramble(ArrayList<Card> cards) {
for(int i = 0; i < cards.size(); i++) {
int index = (int)(cards.size()* Math.random());

Card temp = cards.get(i);
cards.set(i, cards.get(index));
cards.set(index, temp);
}
}

public void sort(Card[] cards) {
for(int i = 0; i < cards.length; i++) {
for(int j = 0; j < cards.length; j++) {
if(cards[j].getValue() > cards[i].getValue()) {
Card temp = cards[i];
cards[i] = cards[j];
cards[j] = temp;
}
}
}
}

public void sort(ArrayList<Card> cards) {
for(int i = 0; i < cards.size(); i++) {
for(int j = 0; j < cards.size(); j++) {
if(cards.get(j).getValue() > cards.get(i).getValue()) {
Card temp = cards.get(i);
cards.set(i, cards.get(j));
cards.set(j, temp);
}
}
}
}

public void searchReplace(int val, Card[] cards) {
for(int i = 0; i < cards.length; i++) {
if(cards[i].getValue() == 1) cards[i] = new Card(val);
}
}

public void searchReplace(int val, ArrayList<Card> cards) {
for(int i = 0; i < cards.size(); i++) {
if(cards.get(i).getValue() == 1) cards.set(i, new Card(val));
}
}

public void searchDelete(int val, ArrayList<Card> cards) {
for(int i = 0; i < cards.size(); i++) {
if(cards.get(i).getValue() == val) cards.remove(i);
}
}
}
20 changes: 20 additions & 0 deletions Q3/02122019/Runner1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public class Runner1 {
public static void main(String[] args) {
Practice pr = new Practice();
System.out.println(pr.getDomain("[email protected]"));

Card[] cards = new Card[10];
for(int i = 0; i < cards.length; i++) {
cards[i] = new Card((int)(5 * Math.random() + 1));
}

pr.print(cards);
System.out.println(pr.getLargest(cards));
pr.scramble(cards);
pr.print(cards);
pr.sort(cards);
pr.print(cards);
pr.searchReplace(2, cards);
pr.print(cards);
}
}
23 changes: 23 additions & 0 deletions Q3/02122019/Runner2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.util.ArrayList;

public class Runner2 {
public static void main(String[] args) {
Practice pr = new Practice();

ArrayList<Card> cards = new ArrayList<Card>();
for(int i = 0; i < 5; i++) {
cards.add(new Card((int)(5 * Math.random() + 1)));
}

pr.print(cards);
System.out.println(pr.getLargest(cards));
pr.scramble(cards);
pr.print(cards);
pr.sort(cards);
pr.print(cards);
pr.searchReplace(1, cards);
pr.print(cards);
pr.searchDelete(5, cards);
pr.print(cards);
}
}

0 comments on commit aef129f

Please sign in to comment.