This repository was archived by the owner on Aug 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
314 additions
and
147 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + ""; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |