diff options
author | msglm <msglm@techchud.xyz> | 2023-01-14 05:31:48 -0600 |
---|---|---|
committer | msglm <msglm@techchud.xyz> | 2023-01-14 05:31:48 -0600 |
commit | 9d53d8857eaa1c9405894a88ca75bc4657e42f35 (patch) | |
tree | eb1efc1d028b949dd83bb710c68be8eff58f26e7 /Java | |
download | school-code-9d53d8857eaa1c9405894a88ca75bc4657e42f35.tar.gz school-code-9d53d8857eaa1c9405894a88ca75bc4657e42f35.tar.bz2 school-code-9d53d8857eaa1c9405894a88ca75bc4657e42f35.zip |
Diffstat (limited to 'Java')
59 files changed, 2076 insertions, 0 deletions
diff --git a/Java/AddingUpInt.java b/Java/AddingUpInt.java new file mode 100644 index 0000000..2f32f61 --- /dev/null +++ b/Java/AddingUpInt.java @@ -0,0 +1,25 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class AddingUpInt { + public static void main(String[] args) throws java.io.IOException { + int iterations,enteredint; + int addable = 0; + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + BufferedReader input2 = new BufferedReader(new InputStreamReader(System.in)); + System.out.println("How many ints will be added"); + iterations = Integer.parseInt(input.readLine()); + + + for(iterations=iterations;iterations>0;iterations--){ + System.out.println("Enter an Int"); + enteredint = Integer.parseInt(input2.readLine()); + addable = addable+enteredint; + } + System.out.println("The sum is: " + addable); + + } + + +} +//By msglm; Licensed under the AGPL v3 diff --git a/Java/AddingupSquaresandCubes.java b/Java/AddingupSquaresandCubes.java new file mode 100644 index 0000000..957f276 --- /dev/null +++ b/Java/AddingupSquaresandCubes.java @@ -0,0 +1,28 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class AddingupSquaresandCubes { + public static void main(String[] args) throws java.io.IOException { + int iterations; + double Squares = 0.0; + double Cubes = 0.0; + double computable = 0.0; + double timesran = 0.0; + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + BufferedReader input2 = new BufferedReader(new InputStreamReader(System.in)); + System.out.println("Upper Limit:"); + iterations = Integer.parseInt(input.readLine()); + + + for(iterations=iterations;iterations>0;iterations--){ + timesran++; + Squares = Squares + Math.pow(iterations,2); + Cubes = Cubes + Math.pow(iterations,3); + } + System.out.println("The sum of Squares is " + Squares); + System.out.println("The sum of Cubes is " + Cubes); + } + + +} +//By msglm; Licensed under the AGPL v3 diff --git a/Java/Average.java b/Java/Average.java new file mode 100644 index 0000000..0affee8 --- /dev/null +++ b/Java/Average.java @@ -0,0 +1,22 @@ +//BufferedReader is faster than scanner as it doesn't parse the text. Iterated over 1000 times, it saves 30 seconds in total. +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class Average { + public static void main(String[] args) throws java.io.IOException { + int a, b; + + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + BufferedReader input2 = new BufferedReader(new InputStreamReader(System.in)); + a = Integer.parseInt(input.readLine()); + b = Integer.parseInt(input2.readLine()); + int s = a + b; + System.out.println("Average is: " + s/2); + + + + + + } +} + diff --git a/Java/AverageDemo.java b/Java/AverageDemo.java new file mode 100644 index 0000000..70168a4 --- /dev/null +++ b/Java/AverageDemo.java @@ -0,0 +1,25 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.lang.Math; +class AverageDemo { + static float average(float a, float b){ + return (a+b)/2; + } + + public static void main(String[] args) throws java.io.IOException{ + float a, b; + System.out.println("input two numbers"); + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + a = Float.parseFloat(input.readLine()); + b = Float.parseFloat(input.readLine()); + System.out.println("output:"); + System.out.println(average(a, b)); + + + + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/BlackJack/Black Jack Part 1.pdf b/Java/BlackJack/Black Jack Part 1.pdf Binary files differnew file mode 100644 index 0000000..77f8e4f --- /dev/null +++ b/Java/BlackJack/Black Jack Part 1.pdf diff --git a/Java/BlackJack/Black Jack Part 2.pdf b/Java/BlackJack/Black Jack Part 2.pdf Binary files differnew file mode 100644 index 0000000..6421d17 --- /dev/null +++ b/Java/BlackJack/Black Jack Part 2.pdf diff --git a/Java/BlackJack/Black Jack Part 3.pdf b/Java/BlackJack/Black Jack Part 3.pdf Binary files differnew file mode 100644 index 0000000..fd4e56c --- /dev/null +++ b/Java/BlackJack/Black Jack Part 3.pdf diff --git a/Java/BlackJack/Black Jack Part 4.pdf b/Java/BlackJack/Black Jack Part 4.pdf Binary files differnew file mode 100644 index 0000000..25f4c2b --- /dev/null +++ b/Java/BlackJack/Black Jack Part 4.pdf diff --git a/Java/BlackJack/Blackjack.java b/Java/BlackJack/Blackjack.java new file mode 100644 index 0000000..ff06b78 --- /dev/null +++ b/Java/BlackJack/Blackjack.java @@ -0,0 +1,185 @@ +//TODO + +import java.util.Random; //for randomness +//import java.io.BufferedReader; +//import java.io.InputStreamReader; +import java.io.*; + +class Blackjack { + public static void main(String [] args) throws java.io.IOException { + System.out.println("Welcome To Blackjack!"); + System.out.println("Copyright (C) 2021 msglm."); + System.out.println("License AGPLv3+: GNU Affero GPL version 3 Only"); + System.out.println("<http://www.gnu.org/licenses/agpl.html>."); + System.out.println("This is free software: you are free to change and redistribute it."); + System.out.println("There is NO WARRANTY, to the extent permitted by law. \n"); + + //first is for card value, second is for card type + int[] dealerFaceValues = new int[21]; + int[] dealerSuitValues = new int[21]; + int[] playerFaceValues = new int[21]; + int[] playerSuitValues = new int[21]; + + int dealerDeltCards = 0; + int playerDeltCards = 0; + + int dealerScore = 0; + int playerScore = 0; + int dealerScoreSuit = 0; + int playerScoreSuit = 0; + + int roundnum=0; + + boolean stood = false; + boolean gameEnd = false; + boolean playerHit = true; + boolean dealerHit = true; + Random random = new Random(); + + dealerFaceValues[0] = random.nextInt(9+1)+1; + dealerSuitValues[0] = random.nextInt(1+1)+1; + + playerFaceValues[0] = random.nextInt(9+1)+1; + playerSuitValues[0] = random.nextInt(1+1)+1; + + + //TODO: SWITCH STATEMENT THAT ASSIGNES A NAME TO EACH CARD + + System.out.println("Dealer's Hand:"); + for(int i=0;i<21;i++){ + int curcar = i + 1; + if(dealerFaceValues[i] != 0 || dealerSuitValues[i] != 0){ + System.out.println("Card " + curcar + " has a Face of " + dealerFaceValues[i] + " and a Suit of " + dealerSuitValues[i]); + } + } + + + System.out.println("Player's Hand:"); + for(int i=0;i<21;i++){ + int curcar = i + 1; + if(playerFaceValues[i] != 0 || playerSuitValues[i] != 0){ + System.out.println("Card " + curcar + " has a Face of " + playerFaceValues[i] + " and a Suit of " + playerSuitValues[i]); + } + } + while(!gameEnd){ + roundnum++; + System.out.println("Would you like a card? Y/n"); + + BufferedReader cardWantInput = new BufferedReader(new InputStreamReader(System.in)); + String tempString = cardWantInput.readLine(); + char cardWant = tempString.charAt(0); + System.out.println("===ROUND " + roundnum + " ==="); + if(cardWant == 'y' || cardWant == 'Y'){ + playerHit = true; + playerDeltCards++; + playerFaceValues[playerDeltCards] = random.nextInt(9+1)+1; + playerSuitValues[playerDeltCards] = random.nextInt(1+1)+1; + } else { + stood = true; + playerHit = false; + } + System.out.println(""); + System.out.println("Dealer's Hand:"); + for(int i=0;i<21;i++){ + int curcar = i + 1; + if(dealerFaceValues[i] != 0 || dealerSuitValues[i] != 0){ + if(curcar == 1){ + System.out.println("Card " + curcar + " has a Face of " + dealerFaceValues[i] + " and a Suit of " + dealerSuitValues[i]); + } else { + System.out.println ("The Dealer has another card..."); + } + } + } + System.out.println(""); + System.out.println("Player's Hand:"); + for(int i=0;i<21;i++){ + int curcar = i + 1; + if(playerFaceValues[i] != 0 || playerSuitValues[i] != 0){ + System.out.println("Card " + curcar + " has a Face of " + playerFaceValues[i] + " and a Suit of " + playerSuitValues[i]); + } + } + System.out.println(""); + + + //Find each one's score + for (int i=0;i<21;i++){ + playerScore = playerScore + playerFaceValues[i]; + } + + for (int i=0;i<21;i++){ + dealerScore = dealerScore + dealerFaceValues[i]; + } + + for (int i=0;i<21;i++){ + playerScoreSuit = playerScoreSuit + playerSuitValues[i]; + } + + for (int i=0;i<21;i++){ + dealerScoreSuit = dealerScoreSuit + dealerSuitValues[i]; + } + + if(dealerScore < 17){ + dealerHit = true; + dealerDeltCards++; + dealerFaceValues[dealerDeltCards] = random.nextInt(9+1)+1; + dealerSuitValues[dealerDeltCards] = random.nextInt(1+1)+1; + } else { + dealerHit = false; + } + + + System.out.println("Status:"); + if(playerHit){ + System.out.println("You took a Hit!"); + } else { + System.out.println("You decided to stand..."); + } + + + if(dealerHit){ + System.out.println("The dealer has taken a hit!"); + } else { + System.out.println("The dealer has decided to stand..."); + } + + if(dealerScore > 21) { + System.out.println("DEALER BUSTED!!! YOU WIN!"); + gameEnd = true; + } + if(playerScore > 21){ + System.out.println("YOU BUSTED!!! YOU LOSE"); + gameEnd = true; + + } + + //probably should clean this up with swich statments. This looks horrible. + if (stood == true && gameEnd == false) { + if(dealerScore > playerScore){ + System.out.println("DEALER HAS THE HIGHER CARDS!!! YOU LOSE!"); + gameEnd = true; + } else if (playerScore > dealerScore){ + System.out.println("YOU HAVE THE HIGHER CARDS!!! YOU WIN!"); + gameEnd = true; + } else { + System.out.println("YOU HAVE THE SAME VALUES. WE MUST LOOK AT THE SUITS TO DETERMINE WHO WON"); + if(dealerScore + dealerScoreSuit > playerScore + playerScoreSuit){ + System.out.println("DEALER HAS THE HIGHER CARDS!!! YOU LOSE!"); + gameEnd = true; + } else if (playerScore + playerScoreSuit > dealerScore + dealerScoreSuit){ + System.out.println("YOU HAVE THE HIGHER CARDS!!! YOU WIN!"); + gameEnd = true; + } else { + System.out.println("THE VALUES ARE STILL THE SAME! A COIN FLIP TO DECIDE WHO WON!"); + if(random.nextInt(1) == 1){ + System.out.println("YOU HAVE WON BY PURE LUCK!"); + gameEnd = true; + } else { + System.out.println("YOU HAVE LOST BY PURE LUCK!"); + gameEnd = true; + }}}} + //reset the score counted for next round + playerScoreSuit=0; + dealerScoreSuit=0; + dealerScore=0; + playerScore=0; + }}} diff --git a/Java/BlackJack/Card.java b/Java/BlackJack/Card.java new file mode 100644 index 0000000..f4b2df4 --- /dev/null +++ b/Java/BlackJack/Card.java @@ -0,0 +1,250 @@ +public class Card {
+
+ // data member
+ private int facePointValue;
+ private String faceValue;
+ private int points;
+ private String suit;
+ private int suitPointValue;
+
+
+
+ // Constructors
+ //accepts suit and face
+ public Card (String inFace, String inSuit) {
+
+ switch(inFace){ //Reasoning for the switch is that working with strings as values in a comparision game will only casue problems, it must be converted to a sensable value
+ case "King": //all face cards are 10. 10 is also 10 (for obvious reasons)
+ case "king":
+ case "Joker":
+ case "joker":
+ case "Queen":
+ case "queen":
+ case "Jack":
+ case "jack":
+ case "10":
+ case "ten":
+ case "Ten":
+ facePointValue = 10;
+ break;
+ //these comparisions are the worst, but its the best way I could figure out accounting for all reasonable inputs without using regex
+ case "9":
+ case "nine":
+ case "Nine":
+ facePointValue = 9;
+ break;
+
+ case "8":
+ case "eight":
+ case "Eight":
+ facePointValue = 8;
+ break;
+
+ case "7":
+ case "seven":
+ case "Seven":
+ facePointValue = 7;
+ break;
+
+ case "6":
+ case "six":
+ case "Six":
+ facePointValue = 6;
+ break;
+
+ case "5":
+ case "five":
+ case "Five":
+ facePointValue = 5;
+ break;
+
+ case "4":
+ case "four":
+ case "Four":
+ facePointValue = 4;
+ break;
+
+ case "3":
+ case "three":
+ case "Three":
+ facePointValue = 3;
+ break;
+ case "2":
+ case "two":
+ case "Two":
+ facePointValue = 2;
+ break;
+
+ case "1":
+ case "one":
+ case "One":
+ case "Ace":
+ case "ace":
+ facePointValue = 1;
+ break;
+ default:
+ System.out.println("User Input was Invalid! " + inFace + " Is not a valad card!");
+ System.exit(1);
+
+ }
+
+ faceValue = inFace; //since all of the above is just for value finding and will crash if breaks, might as well just get inFace as the value.
+ switch(inSuit){
+ case "heart":
+ case "hearts":
+ case "Heart":
+ case "Hearts":
+ suitPointValue = 4;
+ break;
+ case "club":
+ case "clover":
+ case "Club":
+ case "Clover":
+ suitPointValue = 3;
+ break;
+ case "Diamond":
+ case "diamond":
+ suitPointValue = 2;
+ break;
+ case "spade":
+ case "spear":
+ case "shovel":
+ case "Spade":
+ case "Spear":
+ case "Shovel":
+ suitPointValue = 1;
+ break;
+ default:
+ System.out.println("User Input was Invalid! " + inSuit + " Is not a valad card!");
+
+ System.exit(1);
+ }
+ suit = inSuit; //ditto reasoning of last comment
+
+ }
+//no suit or face? assume 4 of clovers
+ public Card() {
+ suitPointValue = 3;
+ facePointValue = 4;
+ suit = "Clover";
+ faceValue = "4";
+ }
+
+// set & return
+// set
+
+//return
+public String getFaceValue(){
+return figureName(facePointValue);
+}
+
+public String getFaceSuit(){
+return figureSuit(suitPointValue);
+}
+
+public int getFaceNumericValue(){
+return facePointValue;
+}
+
+public int getSuitNumericValue(){
+return suitPointValue;
+}
+
+
+ public String figureName(int input) {
+ switch(input){
+
+ case 1:
+ return "One";
+
+
+ case 2:
+ return "Two";
+
+
+ case 3:
+ return "Three";
+
+
+ case 4:
+ return "Four";
+
+ case 5:
+ return "Five";
+
+ case 6:
+ return "Six";
+
+ case 7:
+ return "Seven";
+
+ case 8:
+ return "Eight";
+
+ case 9:
+ return "Nine";
+
+ case 10:
+ return "Ten";
+
+ case 11:
+ return "Jack";
+
+ case 12:
+ return "Queen";
+
+ case 13:
+ return "King";
+
+ case 14:
+ return "Joker";
+
+ default:
+ System.out.println("figureName does not take " + input + "as a valid input!");
+ return null;
+ }
+
+ }
+
+ public String figureSuit(int input) {
+ switch(input){
+ case 1:
+ return "Hearts";
+
+ case 2:
+ return "Clovers";
+
+ case 3:
+ return "Diamonds";
+
+ case 4:
+ return "Spade";
+ default:
+ System.out.println("figureSuit does not take" + input + "as a valid input!");
+ return null;
+
+
+ }
+ }
+
+ public String compareCardValue(String card1Name, int card1Face, int card1Suit, String card2Name, int card2Face, int card2Suit) {
+
+ if(card1Face == card2Face){
+ if(card1Suit > card2Suit){
+ return card1Name;
+ } else {
+ return card2Name;
+ }
+
+ }
+
+ if (card1Face > card2Face) {
+ return card1Name;
+ } else {
+ return card2Name;
+ }
+ }
+
+}
+
+
diff --git a/Java/BlackJack/CardTester.java b/Java/BlackJack/CardTester.java new file mode 100644 index 0000000..5655ea2 --- /dev/null +++ b/Java/BlackJack/CardTester.java @@ -0,0 +1,30 @@ +/* CardTester.java +Name: Nancy Reddig, Academy Instructor +Date: 5/15/03 +Modified by: +Carl Frank, 08/29/07 +Modifications were to not allow access to instance variables of Card. +The assumptions are that these will be private. +Use this class to test your Card Class +Program that tests the Card Class*/ +// Java packages +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; // program uses JOptionPane +public class CardTester { +// main method begins execution of Java application +public static void main( String args[] ) { + +Card card1= new Card("King", "Hearts"); +// allow the user to think that they are dealing a random card + +JOptionPane.showMessageDialog(null, "Deal a Card", +"Card", JOptionPane.INFORMATION_MESSAGE ); +//display the card +JOptionPane.showMessageDialog( null, "The card is the " + card1.getFaceValue() + " of " //copying code from a pdf and having to debug it? Now this is a new low + + card1.getSuit(), + "Your Card", JOptionPane.PLAIN_MESSAGE ); + +System.exit(0); +} +} diff --git a/Java/BlackJack/Deck.java b/Java/BlackJack/Deck.java new file mode 100644 index 0000000..a828e52 --- /dev/null +++ b/Java/BlackJack/Deck.java @@ -0,0 +1,38 @@ +import java.util.Random; //for randomness
+public class Deck {
+
+ // data member
+ private int[] deckFace = new int[20];
+ private int[] deckSuit = new int[20];
+
+
+
+ // Constructors
+ //accepts suit and face
+ public Deck() {
+ for(int i=0;i<20;i++){
+ Random random = new Random();
+ deckFace[i] = random.nextInt(14); //1-10 are as expected, 11 is Jack, 12 is Queen, 13 is King, 14 is Joker
+ deckSuit[i] = random.nextInt(4); //Card order is highest to lowest. 1 is hearts 4 is spades.
+ }
+ }
+
+ void printDeck(){
+
+ for(int i=0;i<20;i++){
+ System.out.println("Card " + i + " has a Face of " + deckFace[i] + " and a Suit of " + deckSuit[i]);
+ }
+
+ }
+
+ void shuffle(){
+
+ for(int i=0;i<20;i++){
+ Random random = new Random();
+ deckFace[i] = random.nextInt(14); //1-10 are as expected, 11 is Jack, 12 is Queen, 13 is King, 14 is Joker
+ deckSuit[i] = random.nextInt(4); //Card order is highest to lowest. 1 is hearts 4 is spades.
+
+ }
+
+ }
+}
diff --git a/Java/BlackJack/DeckDriver.java b/Java/BlackJack/DeckDriver.java new file mode 100644 index 0000000..28a8ff4 --- /dev/null +++ b/Java/BlackJack/DeckDriver.java @@ -0,0 +1,8 @@ +class DeckDriver { +public static void main(String [] args) { +Deck myDeck = new Deck(); +myDeck.printDeck(); +myDeck.shuffle(); +System.out.println("\n\nSorted Order"); +myDeck.printDeck(); +}} diff --git a/Java/BlackJack/Hand.java b/Java/BlackJack/Hand.java new file mode 100644 index 0000000..a9fb174 --- /dev/null +++ b/Java/BlackJack/Hand.java @@ -0,0 +1,51 @@ +public class Hand {
+
+ // data member
+ private int[] cardsInHandFace= new int[22]; //the maximum possible hands size is 22, if you draw 22 aces you'll bust. Values as expected
+ private int[] cardsInHandSuit= new int[22]; //usual values
+ private int numCardsInHand;
+
+ // Constructors
+ //accepts suit and face
+ public Hand (int firstFace, int firstSuit, int secondFace, int secondSuit) {
+ cardsInHandFace[1] = firstFace;
+ cardsInHandSuit[1] = firstSuit;
+ cardsInHandFace[2] = secondFace;
+ cardsInHandSuit[2] = secondSuit;
+ //for some reason it wanted this, so I gave it. This code is total spaghetti and garbage. These assignments don't feel like they were ment to work with one another.
+ }
+
+// set & return
+// set
+
+//return
+public int calculateHandValue(){
+
+int value = 0;
+
+for(int i=0; i < cardsInHandFace.length;i++){
+value = value + cardsInHandFace[i];
+}
+return value;
+}
+
+public void showAllCards(){ //there is absolutely no reason this should return something. These constraints are bad and don't teach OOP well. None of this need be OOP at all as it just overcomplicates this to a maximal degree. A much better teaching for OOP would be making some small farming game in where you had animals to take care of. OOP would be useful there as you could easily generate personalities, needs, types, colors, etc for each animal as to make good use of OOP and its capabilities. Blackjack doesn't need nor have variation like that and thus does not need OOP. Due to the fact that each class has a private value to it, there is great redundancy in the amonut of values stored, therefore causing the application to use more RAM than it needs to. This is also difficult to keep track of because some of these methods (such as card name and value finding) are redundant and cannot easily work with one another due to the strange constraints in what methods we must use.
+
+ for(int i=1; i < cardsInHandFace.length + 1;i++){
+ System.out.print("Card Number " + i + "'s face is " + this.cardsInHandFace[i] + " and its suit is " + this.cardsInHandSuit[i]);
+ }
+
+}
+
+
+public void showOneCard(int input) { //fix to return something
+System.out.print("Card Number " + input + "'s face is " + this.cardsInHandFace[input] + " and its suit is " + this.cardsInHandSuit[input]);
+}
+
+public void hit(Card c) { //fix to return something
+ for(int i=0; i < cardsInHandFace.length;i++){
+ if(cardsInHandFace[i] == 0) {
+ cardsInHandFace[i] = c.getFaceNumericValue();
+ cardsInHandSuit[i] = c.getSuitNumericValue();
+ }}}
+}
diff --git a/Java/CapitalC.java b/Java/CapitalC.java new file mode 100644 index 0000000..de1d6a4 --- /dev/null +++ b/Java/CapitalC.java @@ -0,0 +1,21 @@ +import java.util.ArrayList; +class CapitalC { +public static void main (String str[]) { + ArrayList<String> book = new ArrayList<>(); + + //book titles + book.add("test"); + book.add("Capital"); + book.add("test2"); + book.add("Carmex"); + book.add("LaTeXC"); + book.add("C++"); + book.add("East"); + + for (String b: book){ + if(b.charAt(0) == 'C'){ + System.out.println(b); + } +}}} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/CoinTest.java b/Java/CoinTest.java new file mode 100644 index 0000000..45979d2 --- /dev/null +++ b/Java/CoinTest.java @@ -0,0 +1,8 @@ +import java.util.ArrayList; +class CoinTester { +public static void main (String str[]) { + coin quarter = new coin(); + System.out.println(quarter); +} +} +//By msglm; Licensed under the AGPL v3 diff --git a/Java/Computation.java b/Java/Computation.java new file mode 100644 index 0000000..289fec9 --- /dev/null +++ b/Java/Computation.java @@ -0,0 +1,25 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class Computation { + public static void main(String[] args) throws java.io.IOException { + int iterations,numbertodivby; + double computable = 0.0; + double timesran = 0.0; + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + BufferedReader input2 = new BufferedReader(new InputStreamReader(System.in)); + System.out.println("How many layers down will you go?"); + iterations = Integer.parseInt(input.readLine()); + + + for(iterations=iterations;iterations>0;iterations--){ + timesran++; + computable = (computable)+(1.0/timesran); + } + System.out.println("The sum is: " + computable); + + } + + +} +//By msglm; Licensed under the AGPL v3 diff --git a/Java/CorrectChange.java b/Java/CorrectChange.java new file mode 100644 index 0000000..ea163a6 --- /dev/null +++ b/Java/CorrectChange.java @@ -0,0 +1,25 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class CorrectChange { + public static void main(String[] args) throws java.io.IOException { + int dollars, cents,quarters,dimes,nickels,pennies; + + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + dollars = Integer.parseInt(input.readLine()); + cents = dollars%100; + dollars = (dollars-cents)/100; + quarters = cents/25; + dimes = (cents%25)/10; + nickels = (cents%10)/5; + pennies = (cents%5)/1; + System.out.println("Your change is: " + dollars + " dollar(s), " + quarters + " quarters " + dimes + " dimes, " + nickels + " nickels, " + pennies + ", pennies"); + + + + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/Cup/Cup.java b/Java/Cup/Cup.java new file mode 100644 index 0000000..c313c07 --- /dev/null +++ b/Java/Cup/Cup.java @@ -0,0 +1,55 @@ +public class Cup {
+
+ // data member
+ private double capacity;
+ private double holding;
+ private String color;
+
+
+
+ // Constructors
+ public Cup(double c, String co, double h) {
+ capacity = c;
+ color = co;
+ holding = h;
+ }
+ public Cup() {
+ color = "red";
+ capacity = 16;
+ holding = 0;
+ }
+ // set
+ public void fillCup(double h) {
+ if (h > capacity){
+ capacity = holding;
+ } else {
+ holding = holding + h;
+ }
+ }
+ public void sip() {
+ if(holding - 1 < 1){
+ holding = holding-1;
+ } else {
+ //System.out.println("CUPPER UNDERFLOW DETECTED");
+ }
+ }
+
+ public void gulp() {
+ if(holding-3 > 1){
+ holding = holding-3;
+ } else {
+ //System.out.println("CUPPER UNDERFLOW DETECTED");
+ }
+ }
+ public void emptyCup() {
+ holding = 0;
+ }
+
+ // modify and return
+ public String status() {
+ return capacity + " ounce " + color + " cup that contains " + holding + " ounce[s].";
+ }
+
+}
+
+
diff --git a/Java/Cup/CupDemo.java b/Java/Cup/CupDemo.java new file mode 100644 index 0000000..9c00d94 --- /dev/null +++ b/Java/Cup/CupDemo.java @@ -0,0 +1,33 @@ +public class CupDemo {
+
+ public static void main (String args []) {
+
+ //cup init
+ Cup FirstCup = new Cup();
+ Cup SecondCup = new Cup(20.0, "Blue", 0.0);
+
+//fill both with 20 oz, this breaks the first cup and will default to the maximum possible capacity
+ FirstCup.fillCup(20);
+ SecondCup.fillCup(20);
+ //print red
+ System.out.println(FirstCup.status());
+ //sip and gulp from blue
+ SecondCup.sip();
+ SecondCup.sip();
+ SecondCup.gulp();
+ //Fill by 6
+ SecondCup.fillCup(6);
+ //print blue
+ System.out.println(SecondCup.status());
+ //empty red
+ FirstCup.emptyCup();
+ //fill red with five
+ FirstCup.fillCup(5);
+ //2x gulp first
+ FirstCup.gulp();
+ FirstCup.gulp();
+ //final print
+ System.out.println(FirstCup.status());
+ }
+}
+
diff --git a/Java/Discount.java b/Java/Discount.java new file mode 100644 index 0000000..71a1974 --- /dev/null +++ b/Java/Discount.java @@ -0,0 +1,24 @@ +//BufferedReader is faster than scanner as it doesn't parse the text. Iterated over 1000 times, it saves 30 seconds in total. +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class Discount { + public static void main(String[] args) throws java.io.IOException { + int amount; + System.out.println("input amount:"); + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + amount = Integer.parseInt(input.readLine()); + if (amount > 10){ + System.out.println("Dicounted Price: " + amount*0.9); + } else { + System.out.println("Price: " + amount); + } + + + + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/Dollars.java b/Java/Dollars.java new file mode 100644 index 0000000..faa927c --- /dev/null +++ b/Java/Dollars.java @@ -0,0 +1,21 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class Dollars { + public static void main(String[] args) throws java.io.IOException { + int dollars, cents; + + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + dollars = Integer.parseInt(input.readLine()); + cents = dollars%100; + dollars = (dollars-cents)/100; + System.out.println("this is $" + dollars + " dollars and " + cents + " cents"); + + + + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/DotLeaders.java b/Java/DotLeaders.java new file mode 100644 index 0000000..021c3c7 --- /dev/null +++ b/Java/DotLeaders.java @@ -0,0 +1,27 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class DotLeaders { + public static void main(String[] args) throws java.io.IOException { + int dotnum; + BufferedReader word1I = new BufferedReader(new InputStreamReader(System.in)); + BufferedReader word2I = new BufferedReader(new InputStreamReader(System.in)); + + System.out.println("first Word"); + String word = word1I.readLine(); + System.out.println("second word"); + String word2 = word2I.readLine(); + dotnum = 30-(word.length()+word2.length()); + System.out.print(word); + for(dotnum=dotnum;dotnum>0; dotnum--){ + System.out.print("."); + } + System.out.print(word2); + + + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/DrawDiamond.java b/Java/DrawDiamond.java new file mode 100644 index 0000000..7e744a3 --- /dev/null +++ b/Java/DrawDiamond.java @@ -0,0 +1,48 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +//horrible recursive for loops are not fun +//they aren't a good way to teach something +//why can't we do fizzbuzz? +//or make small games? +//or do data manipulation? +//or solve a problem? +//or something more enjoyable than this? +//maybe CS really should stay a hobbiest, self taught skill +//at least when its a hobby you learn what matters at your own pace +//here its just being given an unrealistic task that, albiet difficult, is not rewarding +//making a diamond like this doesn't teach me good programming +//it teaches me for loops +//and nested for loops are usually not a good way to go about things +//I just want to make command line tools and data parsers for gods sake! +//maybe mom was right, I should just go for law +//sysadmining seems nice though, I could do that +//yeah, law or sysadmin. That seems nice +//or I could write and edit for a living, that doesn't seem too bad +class Diamond { + public static void main(String[] args) throws java.io.IOException { + BufferedReader dmndsizeI = new BufferedReader(new InputStreamReader(System.in)); + + System.out.println("input size"); + int dmndsize = Integer.parseInt(dmndsizeI.readLine()); + + for (int i = 1; i < dmndsize; i += 2) { + for (int j = 0; j < dmndsize -1 - i / 2; j++) + System.out.print(" "); + + for (int j = 0; j < i; j++) + System.out.print("*"); + + System.out.print("\n"); + } + + for (int i = 7; i > 0; i -= 2) { + for (int j = 0; j < 9 - i / 2; j++) + System.out.print(" "); + + for (int j = 0; j < i; j++) + System.out.print("*"); + + System.out.print("\n"); + }}} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/Even20To100.java b/Java/Even20To100.java new file mode 100644 index 0000000..b3a2b33 --- /dev/null +++ b/Java/Even20To100.java @@ -0,0 +1,14 @@ +//BufferedReader is faster than scanner as it doesn't parse the text. Iterated over 1000 times, it saves 30 seconds in total. +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class Even20To100 { + public static void main(String[] args) throws java.io.IOException { + + + for(int i = 0; i <= 100;i++){ + if (i % 2 == 0){ + System.out.print(i + " "); + } + } + }} diff --git a/Java/FantasyGame.java b/Java/FantasyGame.java new file mode 100644 index 0000000..9053749 --- /dev/null +++ b/Java/FantasyGame.java @@ -0,0 +1,45 @@ +//BufferedReader is faster than scanner as it doesn't parse the text. Iterated over 1000 times, it saves 30 seconds in total. +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class FantasyGame { + public static void main(String[] args) throws java.io.IOException { + int Health,Luck,Strength; + System.out.println("Name:"); + BufferedReader NameI = new BufferedReader(new InputStreamReader(System.in)); + String Name = NameI.readLine(); + + System.out.println("Health:"); + BufferedReader HealthI = new BufferedReader(new InputStreamReader(System.in)); + Health = Integer.parseInt(HealthI.readLine()); + + System.out.println("Luck:"); + BufferedReader LuckI = new BufferedReader(new InputStreamReader(System.in)); + Luck = Integer.parseInt(LuckI.readLine()); + + System.out.println("Strength:"); + BufferedReader StrengthI = new BufferedReader(new InputStreamReader(System.in)); + Strength = Integer.parseInt(StrengthI.readLine()); + + if(Health+Luck+Strength > 15){ + + System.out.println("You have given your character too many points! Default values have been assigned"); + System.out.println(Name + ", strength: 5, health: 5, luck: 5"); + } else { + + System.out.println(Name + ", strength: " + Strength + ", health: " + Health + ", luck: " + Luck); + + } + + + + + + + + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/Fever.java b/Java/Fever.java new file mode 100644 index 0000000..ee558fe --- /dev/null +++ b/Java/Fever.java @@ -0,0 +1,24 @@ +//there is absolutely no reason for the input to be a double. No one will be inputting any decimal past the 3, so there is no reason to waste memory on that. Float > Double in this case if you value effective programming. +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class Fever { + public static void main(String[] args) throws java.io.IOException { + float temp; + System.out.println("input temp:"); + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + temp = Float.parseFloat(input.readLine()); + if (temp > 98.6){ + System.out.println("you have a fever."); + } else { + System.out.println("you are not running a fever."); + } + + + + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/HelloWorld.java b/Java/HelloWorld.java new file mode 100644 index 0000000..f5726d7 --- /dev/null +++ b/Java/HelloWorld.java @@ -0,0 +1,7 @@ +//Removed the cancer bloat at the top, why do you need imported packages for a hello world? +class HelloWorld { + public static void main(String[] args) { + System.out.println("Hello World"); + } +} +//By msglm; Licensed under the AGPL v3 diff --git a/Java/HollowBox.java b/Java/HollowBox.java new file mode 100644 index 0000000..64bb43d --- /dev/null +++ b/Java/HollowBox.java @@ -0,0 +1,52 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class HollowBox { + public static void main(String[] args) throws java.io.IOException { + int h,w; + //Buffered readers can improve speed up to 30% as they are less bloated than scanners and don't cause a memory leak when not closed + BufferedReader HeightI = new BufferedReader(new InputStreamReader(System.in)); + BufferedReader WidthI = new BufferedReader(new InputStreamReader(System.in)); + System.out.println("Height"); + h = Integer.parseInt(HeightI.readLine()); + System.out.println("Width"); + w = Integer.parseInt(WidthI.readLine()); + + +//if less than 3, re-enter +if(h<3) { +System.out.println("Invalid height! Re-enter:"); +h = Integer.parseInt(HeightI.readLine()); + +} + +if(w<3) { +System.out.println("Invalid width! Re-enter:"); +w = Integer.parseInt(WidthI.readLine());; +} + + +for(int i=0;i<h;i++) { //loops for height +for(int j=0;j<w;j++) { //loops for width + +if(i==0||i==h-1) { //if i is in the 0th place or height then it will print out * +System.out.print("*"); +}else { +if(j==0||j==w-1) { //if j is in the 0th place or width then it will print out * +System.out.print("*"); +}else { +System.out.print(" "); //if j is in the in between the 0th place and width then it will print out a space +} +} +} + +System.out.println(""); //prints out next line +} + +} + +} + + + +//By msglm; Special thanks to Jude Spikes diff --git a/Java/InternetDelicatessen.java b/Java/InternetDelicatessen.java new file mode 100644 index 0000000..4cf78f9 --- /dev/null +++ b/Java/InternetDelicatessen.java @@ -0,0 +1,41 @@ +//BufferedReader is faster than scanner as it doesn't parse the text. Iterated over 1000 times, it saves 30 seconds in total. +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class InternetDelicatessen { + public static void main(String[] args) throws java.io.IOException { + int amount; + float price; + float shipping = 0; + boolean overnight; + System.out.println("Item Name:"); + BufferedReader itemI = new BufferedReader(new InputStreamReader(System.in)); + String item = itemI.readLine(); + System.out.println("Price"); + BufferedReader priceI = new BufferedReader(new InputStreamReader(System.in)); + price = Float.parseFloat(priceI.readLine()); + System.out.println("Overnight Delivery (true or false):"); + BufferedReader overnightI = new BufferedReader(new InputStreamReader(System.in)); + overnight = Boolean.parseBoolean(overnightI.readLine()); + System.out.println("Invoice: "); + System.out.println(item + " : $" + price); + //Regular Shipping + if (price < 10) { + shipping = shipping + 2; + } else{ + shipping = shipping + 3; + } + + //overnight or naw + if (overnight) { + shipping = shipping + 5; + } + float total = shipping + price; + System.out.println("shipping : $" + shipping); + System.out.println("total : $" + total); + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/Label.java b/Java/Label.java new file mode 100644 index 0000000..740f8e1 --- /dev/null +++ b/Java/Label.java @@ -0,0 +1,35 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; + +public class Label{ +public static void main(String[] arg) throws IOException{ +Scanner user_in = new Scanner(System.in); +System.out.println("Enter input file:"); +String input_filename = user_in.nextLine(); +System.out.println("Enter output file:"); +String output_filename = user_in.nextLine(); + +File inputFile = new File(input_filename); +Scanner file_scanner = new Scanner(inputFile); + +String[] person_data = new String[6]; +for(int i = 0; file_scanner.hasNextLine(); i++){ +person_data[i] = file_scanner.nextLine(); +} + +File outputFile = new File(output_filename); +FileWriter writer = new FileWriter(outputFile); +writer.write(person_data[0] + "\n"); +writer.write(person_data[1] + "\n"); +if(person_data[2].length() > 0){ +writer.write(person_data[2] + "\n"); +} + +writer.write(person_data[3] + ", " + person_data[4] + " " + person_data[5]); +writer.close(); + +} +} diff --git a/Java/Label2.java b/Java/Label2.java new file mode 100644 index 0000000..5a34aee --- /dev/null +++ b/Java/Label2.java @@ -0,0 +1,36 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Scanner; +import java.util.ArrayList; + +public class Label2{ +public static void main(String[] arg) throws IOException{ +Scanner user_in = new Scanner(System.in); + +System.out.println("Enter input file:"); +String input_filename = user_in.nextLine(); +System.out.println("Enter output file:"); +String output_filename = user_in.nextLine(); + +File input_file = new File(input_fname); +Scanner file_in = new Scanner(input_file); + +List<String> people_data = new ArrayList<String>(); +while(file_in.hasNextLine()){ +people_data.add(file_in.nextLine()); +} + +File output_file = new File(output_fname); +FileWriter writer = new FileWriter(output_file); +for (int i = 0; i < people_data.size(); i++) { + String[] datas = people_data.get(i).split(","); + if(datas[j].length() > 0){ + writer.write(datas[j] + "\n"); + } +} +writer.write(datas[3] + ", " + datas[4] + " " + datas[5] + "\n\n"); + +writer.close(); +}} diff --git a/Java/LastChanceGas.java b/Java/LastChanceGas.java new file mode 100644 index 0000000..e43d96f --- /dev/null +++ b/Java/LastChanceGas.java @@ -0,0 +1,34 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class LastChanceGas { + public static void main(String[] args) throws java.io.IOException { + int TankCap,Gage,MPG; + System.out.println("Tank Capacity"); + BufferedReader TankCapin = new BufferedReader(new InputStreamReader(System.in)); + TankCap = Integer.parseInt(TankCapin.readLine()); + + System.out.println("Gage Reading"); + BufferedReader Gagein = new BufferedReader(new InputStreamReader(System.in)); + Gage = Integer.parseInt(Gagein.readLine()); + + System.out.println("MPG"); + BufferedReader MPGin = new BufferedReader(new InputStreamReader(System.in)); + MPG = Integer.parseInt(MPGin.readLine()); + + int ToteGas = (TankCap*(Gage/100))*MPG; + + if (ToteGas < 200) { + System.out.println("Get Gas"); + } else { + System.out.println("safe to travel"); + } + + + + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/Magic.java b/Java/Magic.java new file mode 100644 index 0000000..6633639 --- /dev/null +++ b/Java/Magic.java @@ -0,0 +1,84 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileNotFoundException; +class Magic { + public static void main(String[] args) throws java.io.IOException{ + int epoch = 2; + int prospectingX = 0; + int prospectingY = 0; + boolean notFinished = true; + boolean noneSelected = true; + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + int cords = Integer.parseInt(input.readLine()); + int[][] cordPlane = new int[cords][cords]; + if (cords % 2 == 0){ + System.exit(1); + } + int maxLength = cordPlane.length - 1; + cordPlane[cords/2][0] = 1; //first cord is X second is Y + prospectingX = (cords/2)+1; + prospectingY = -1; + System.out.println("starting..."); + while (epoch <= cords*cords && notFinished){ + while(notFinished){ + + + + System.out.println("Epoch is " + epoch); + + System.out.println("Testing if X-cord " + prospectingX + " is less than 0"); + if(prospectingX < 0){ + prospectingX = prospectingX + cordPlane.length; + } + + System.out.println("Testing if X-cord " + prospectingX + " is greater than " + maxLength); + if(prospectingX > maxLength){ + prospectingX = prospectingX - cordPlane.length; + } + + System.out.println("Testing if Y-cord " + prospectingY + " is less than 0"); + if(prospectingY < 0){ + prospectingY = prospectingY + cordPlane.length; + } + + System.out.println("Testing if Y-cord " + prospectingY + " is greater than " + maxLength); + if(prospectingY > maxLength){ + prospectingY = prospectingY - cordPlane.length; + } + System.out.println("Rerouted everything... Testing now..."); + if( cordPlane[prospectingX][prospectingY] == 0 ){ + System.out.println("Placing cord..."); + cordPlane[prospectingX][prospectingY] = epoch; + prospectingX++; + prospectingY--; + epoch++; + notFinished = false; + for (int k = 0; k < cordPlane.length; k++) { // loop through a multidimensional array + for(int l = 0; l < cordPlane[k].length; l++) { + System.out.print(cordPlane[l][k] + " "); + } + System.out.println(); + } + } else { + prospectingY--; + System.out.println("Reducing Y to " + prospectingY); + } + + } + notFinished = true; + } + for (int k = 0; k < cordPlane.length; k++) { // loop through a multidimensional array + for(int l = 0; l < cordPlane[k].length; l++) { + System.out.print(cordPlane[l][k] + " "); + } + System.out.println(); + } + + } +} + + + +//By msglm; Released into the public domain. diff --git a/Java/MagicSquare/MagicSquare.java b/Java/MagicSquare/MagicSquare.java new file mode 100644 index 0000000..934ade5 --- /dev/null +++ b/Java/MagicSquare/MagicSquare.java @@ -0,0 +1,75 @@ +class MagicSquare{ + +final int maxSize; +int size; +int mSquare [][]; +int row, col; + +public MagicSquare (int s){ +maxSize = 15; +if (s > maxSize) + size = maxSize; +else + size = s; + +mSquare = new int [size][size]; +row = col - 0; +intSquare(); +} + +private void intSquare(){ +int count, mid; + +for (row = 0; row<size; row++) + for (col = 0; col < size; col++) + mSquare [row][col] = 0; + +count = 1; +mid = size/2; +row = 0; +col = mid; + +while (count <= size * size) { + if(mSquare [row][col] != 0) + back(); + mSquare[row][col] = count; + count ++; + forward(); +} +} + +private void forward(){ +row --; +col ++; +check(); +} +private void back(){ +row++; +col--; +check(); +row++; +check(); +} + +private void check(){ +if(row < 0){ +row = size - 1; +} +else { + if(row ==size){ + row = 0; + } +} +if(col < 0){ +col = size - 1; +} +else { + if(col == size){ + col=0; + } +} + +} +} + + diff --git a/Java/MagicSquare/Main.java b/Java/MagicSquare/Main.java new file mode 100644 index 0000000..6fb1f19 --- /dev/null +++ b/Java/MagicSquare/Main.java @@ -0,0 +1,25 @@ +import java.util.Scanner; + +class Main{ + public static void main(String[] args) { + Scanner sc = new Scanner (System.in); + System.out.println("enter size of square, must be odd"); + + int size = sc.nextInt(); + + while(size % 2 == 0){ + System.out.println("not odd"); + size = sc.nextInt(); + } + + MagicSquare mSquare = new MagicSquare(size); + + int[][] sq = mSquare.mSquare; + for (int i = 0; i < sq.length; i++){ + for(int j = 0; j < sq[i].length; j++){ + System.out.print(sq[i][j] + " "); + } + System.out.println(); + } + } + } diff --git a/Java/MaxDemo.java b/Java/MaxDemo.java new file mode 100644 index 0000000..512ef2f --- /dev/null +++ b/Java/MaxDemo.java @@ -0,0 +1,43 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.lang.Math; +class MaxDemo { + static float max(float a, float b){ + if (a > b) { + return a; + } + return b; + } + static float max(float a, float b, float c){ + float max = a; + if (b > a) { + max = b; + } + + if (c > max) { + max = c; + } + return max; + + } + + public static void main(String[] args) throws java.io.IOException{ + float a, b, c; + System.out.println("input three numbers"); + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + a = Float.parseFloat(input.readLine()); + b = Float.parseFloat(input.readLine()); + c = Float.parseFloat(input.readLine()); + System.out.println("output of greater between first 2 numbers"); + System.out.println(max(a, b)); + System.out.println("output of greater between all numbers"); + System.out.println(max(a, b, c)); + + + + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/Method.java b/Java/Method.java new file mode 100644 index 0000000..810dee0 --- /dev/null +++ b/Java/Method.java @@ -0,0 +1,21 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.lang.Math; +class Method { + static void squareIT(double tobesquared){ + System.out.println( Math.pow(tobesquared,2) ); + } + public static void main(String[] args) throws java.io.IOException{ + double squarable; + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + squarable = Double.parseDouble(input.readLine()); + squareIT(squarable); + + + + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/MinMaxAvg.java b/Java/MinMaxAvg.java new file mode 100644 index 0000000..0580f21 --- /dev/null +++ b/Java/MinMaxAvg.java @@ -0,0 +1,65 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileNotFoundException; +class MinMaxAvg { + public static void main(String[] args) throws java.io.IOException{ + int min = 2147483647; //Worst fix I have ever decided to do, but the minimum starts out as the highest number java can read in 32 bits. + int max = 0; + float avg = 0; + int length = 0; + String fileloc; + try{ + //get file location with buffered reader, bad on space, good on time + System.out.println("input file location:"); + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + fileloc = input.readLine(); + + + + File f=new File(fileloc); + FileReader file = new FileReader(f); + BufferedReader readfile = new BufferedReader(new FileReader(fileloc)); + + + String line; + int currentline; + while ((line = readfile.readLine()) != null) { + currentline = Integer.parseInt(line); + length++; + // System.out.println("I am currently reading line " + length + " and it has a value of " + currentline); + if (currentline > max){ + max = currentline; + // System.out.println("Max is currently " + min); + } + + if (currentline < min) { + min = currentline; + // System.out.println("Minimum is currently " + min); + } + + avg = avg + currentline; + // System.out.println("Avg is currently " + avg); + // System.out.println("Epoch " + length + " is complete"); + } + System.out.println("Minimum is: " + min); + System.out.println("Maximum is: " + max); + System.out.println("Average is: " + (avg/length)); + + + + }catch(FileNotFoundException e) { + + System.out.println("No Inputfile Provided"); + + + + + + + + } +} +} +//By msglm; Licensed under the AGPL v3 diff --git a/Java/NoDaisys.java b/Java/NoDaisys.java new file mode 100644 index 0000000..be50ffe --- /dev/null +++ b/Java/NoDaisys.java @@ -0,0 +1,13 @@ +class NoDaisys{ +public static void main (String str[]){ +String movies [] = new String [5]; + +movies [0] = "Creatue from the black lagoon"; +movies [2] = "Dont Eat the dasies"; + +for(int i =0; i < movies.length; i++) +{ +System.out.println(movies[i]); +} +} +} diff --git a/Java/NotBetween.java b/Java/NotBetween.java new file mode 100644 index 0000000..578f485 --- /dev/null +++ b/Java/NotBetween.java @@ -0,0 +1,23 @@ +//BufferedReader is faster than scanner as it doesn't parse the text. Iterated over 1000 times, it saves 30 seconds in total. +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class NotBetween { + public static void main(String[] args) throws java.io.IOException { + int num; + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + num = Integer.parseInt(input.readLine()); + + if (num < 45 || num > 78) { + System.out.println("num is not inbetween"); + } else { + System.out.println("num is inbetween"); + } + + + + + + } +} + diff --git a/Java/Ohm.java b/Java/Ohm.java new file mode 100644 index 0000000..bb61ad7 --- /dev/null +++ b/Java/Ohm.java @@ -0,0 +1,22 @@ +//BufferedReader is faster than scanner as it doesn't parse the text. Iterated over 1000 times, it saves 30 seconds in total. +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class Ohm { + public static void main(String[] args) throws java.io.IOException { + float V, R; + System.out.println("Put in Voltage and then Resistance"); + BufferedReader voltage = new BufferedReader(new InputStreamReader(System.in)); + V = Float.parseFloat(voltage.readLine()); + BufferedReader resist = new BufferedReader(new InputStreamReader(System.in)); + R = Float.parseFloat(resist.readLine()); + System.out.println("Ohms: " + (V + 0.0)/R); + + + + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/OrderChecker.java b/Java/OrderChecker.java new file mode 100644 index 0000000..7c6163d --- /dev/null +++ b/Java/OrderChecker.java @@ -0,0 +1,31 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class OrderChecker { + public static void main(String[] args) throws java.io.IOException { + final int boltPrice = 5,nutPrice = 3, washerPrice = 1; + int bolts,nuts,washers,total; + System.out.println("Bolts?"); + BufferedReader boltsin = new BufferedReader(new InputStreamReader(System.in)); + bolts = Integer.parseInt(boltsin.readLine()); + System.out.println("Nuts?"); + BufferedReader nutsin = new BufferedReader(new InputStreamReader(System.in)); + nuts = Integer.parseInt(nutsin.readLine()); + System.out.println("Washers?"); + BufferedReader washersin = new BufferedReader(new InputStreamReader(System.in)); + washers = Integer.parseInt(washersin.readLine()); + total = (bolts*boltPrice)+(nuts*nutPrice)+(washers*washerPrice); +System.out.println("your total is: " + total); + + + + + + + + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/PeopleData.txt b/Java/PeopleData.txt new file mode 100644 index 0000000..45aaa06 --- /dev/null +++ b/Java/PeopleData.txt @@ -0,0 +1,5 @@ +test1 +test2 +test3 +test4 +test5 diff --git a/Java/PieEatingContest.java b/Java/PieEatingContest.java new file mode 100644 index 0000000..7af0449 --- /dev/null +++ b/Java/PieEatingContest.java @@ -0,0 +1,23 @@ +//BufferedReader is faster than scanner as it doesn't parse the text. Iterated over 1000 times, it saves 30 seconds in total. +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class PieEatingContest { + public static void main(String[] args) throws java.io.IOException { + int weight; + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + weight = Integer.parseInt(input.readLine()); + if (weight >= 220 && weight <= 280){ + System.out.println("You can compete"); + } else { + System.out.println("You cannot compete"); + } + + + + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/PowerCosting.java b/Java/PowerCosting.java new file mode 100644 index 0000000..e4eed8a --- /dev/null +++ b/Java/PowerCosting.java @@ -0,0 +1,22 @@ +//I have no clue what the formula for this is, but I think I got it right +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class Ohm { + public static void main(String[] args) throws java.io.IOException { + float KWPH, USE; + System.out.println("Put in Cost per kilowatt hour and the kilowat hours"); + BufferedReader voltage = new BufferedReader(new InputStreamReader(System.in)); + KWPH = Float.parseFloat(voltage.readLine()); + BufferedReader resist = new BufferedReader(new InputStreamReader(System.in)); + USE = Float.parseFloat(resist.readLine()); + System.out.println("Annual Cost: " + KWPH*USE); + + + + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/PowerOfANumber.java b/Java/PowerOfANumber.java new file mode 100644 index 0000000..18858d1 --- /dev/null +++ b/Java/PowerOfANumber.java @@ -0,0 +1,24 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class PowerofaNumber { + public static void main(String[] args) throws java.io.IOException { + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + BufferedReader input2 = new BufferedReader(new InputStreamReader(System.in)); + System.out.println("Enter X"); + int x = Integer.parseInt(input.readLine()); + System.out.println("Enter N"); + float n = Float.parseFloat(input2.readLine()); + if (n > 0){ + System.out.println(n + " raised to the power of " + x + " is: " + Math.pow(n,x)); + } + else{ + System.out.println("n cannot be negative"); + } + + + } + + +} +//By msglm; Licensed under the AGPL v3 diff --git a/Java/Snack.java b/Java/Snack.java new file mode 100644 index 0000000..e1511c7 --- /dev/null +++ b/Java/Snack.java @@ -0,0 +1,13 @@ +//BufferedReader is faster than scanner as it doesn't parse the text. Iterated over 1000 times, it saves 30 seconds in total. +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class snacks { + public static void main(String[] args) throws java.io.IOException { + BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); + String snack; + System.out.println("Favorite food?"); + snack = read.readLine(); + System.out.println(snack + " sounds delicious!"); + } +} diff --git a/Java/Square/Square.java b/Java/Square/Square.java new file mode 100644 index 0000000..4ea72e9 --- /dev/null +++ b/Java/Square/Square.java @@ -0,0 +1,43 @@ +public class Square {
+
+ // data member
+ private double length;
+
+
+
+ // Constructors
+ //accepts r as length
+ public Square (double l) {
+ length = l;
+ }
+//no r? assume length is 1
+ public Square() {
+ length = 1;
+ }
+//copy's length from another circle
+ public Square (Square s) {
+ length = s.length;
+ }
+
+ // setter & getter
+ // sets length
+ public void setLength(double l) {
+ length = l;
+ }
+//return length
+ public double getLength() {
+ return length;
+ }
+
+ // other methods
+ public double area() {
+ return Math.pow(length,2);
+ }
+
+ public double perimeter() {
+ return length*4;
+ }
+
+}
+
+
diff --git a/Java/Square/SquareDemo.java b/Java/Square/SquareDemo.java new file mode 100644 index 0000000..ab6f0dc --- /dev/null +++ b/Java/Square/SquareDemo.java @@ -0,0 +1,28 @@ +public class SquareDemo {
+
+ public static void main (String args []) {
+
+ double leng = 2.5;
+ double value;
+
+ // create a circle object called mySquare with a lengius of 2.5
+ Square mySquare = new Square(leng);
+
+ // create a circle object called myOtherSquare with a lengius of 10.0
+ Square myOtherSquare = new Square(10);
+
+ // create a circle object called unitSquare with a default lengius of 1.0;
+ Square unitSquare = new Square();
+
+ // create a circle object called myLastSquare that is a copy of the Square mySquare
+ Square myLastSquare = new Square(mySquare);
+
+ // get the area of mySquare
+ value = mySquare.area();
+
+ // print the area of mySquare
+ System.out.println("The area is " + value);
+
+ }
+}
+
diff --git a/Java/StartingAndEnding.java b/Java/StartingAndEnding.java new file mode 100644 index 0000000..d1e315d --- /dev/null +++ b/Java/StartingAndEnding.java @@ -0,0 +1,25 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class StartingAndEnding { + public static void main(String[] args) throws java.io.IOException { + int a, b; + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + BufferedReader input2 = new BufferedReader(new InputStreamReader(System.in)); + System.out.println("Starting"); + a = Integer.parseInt(input.readLine()); + System.out.println("Ending"); + b = Integer.parseInt(input2.readLine()); + System.out.println("\n"); + for(a=a;a<=b; a++){ //for some ungodly reason a for loop needs a declarative statement at the start. I can't find a good fix for this and this is a resource wasting, malformed practice but it works. + System.out.println(a); + } + + + + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/Times2.java b/Java/Times2.java new file mode 100644 index 0000000..ed7731f --- /dev/null +++ b/Java/Times2.java @@ -0,0 +1,27 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.lang.Math; +class Times2 { + static void doubleArray(double[] input){ + for (int i = 0; i < input.length; i++){ + input[i] = input[i] * 2; + } + } + public static void main(String[] args) throws java.io.IOException{ + double[] convertable = {1,2.36,4,6,8,20}; + for(int i = 0; i < convertable.length;i++){ + System.out.println(convertable[i]); + } + doubleArray(convertable); + System.out.println("converted"); + for(int i = 0; i < convertable.length;i++){ + System.out.println(convertable[i]); + } + + + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/TirePressure.java b/Java/TirePressure.java new file mode 100644 index 0000000..5e5826b --- /dev/null +++ b/Java/TirePressure.java @@ -0,0 +1,33 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class TirePressure { + public static void main(String[] args) throws java.io.IOException { + int Tire1,Tire2,Tire3,Tire4; + + + System.out.println("Right Front"); + BufferedReader Tire1I = new BufferedReader(new InputStreamReader(System.in)); + Tire1 = Integer.parseInt(Tire1I.readLine()); + System.out.println("Left Front"); + BufferedReader Tire2I = new BufferedReader(new InputStreamReader(System.in)); + Tire2 = Integer.parseInt(Tire2I.readLine()); + System.out.println("Right Rear"); + BufferedReader Tire3I = new BufferedReader(new InputStreamReader(System.in)); + Tire3 = Integer.parseInt(Tire3I.readLine()); + System.out.println("Left Rear"); + BufferedReader Tire4I = new BufferedReader(new InputStreamReader(System.in)); + Tire4 = Integer.parseInt(Tire4I.readLine()); + + if (Tire1 == Tire2 && Tire3 == Tire4){ + System.out.println("Tire Pressure is OK"); + + } else { + System.out.println("Tire pressure is wrong"); + + } + }} + + + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/Vote.java b/Java/Vote.java new file mode 100644 index 0000000..e0375e7 --- /dev/null +++ b/Java/Vote.java @@ -0,0 +1,24 @@ +import java.io.BufferedReader; + +import java.io.InputStreamReader; + +class Vote { + public static void main(String[] args) throws java.io.IOException { + int age; + System.out.println("input amount:"); + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + age = Integer.parseInt(input.readLine()); + if (age > 18){ + System.out.println("you can vote"); + } else { + System.out.println("you cannot vote"); + } + + + + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/Vowels.java b/Java/Vowels.java new file mode 100644 index 0000000..82da9b1 --- /dev/null +++ b/Java/Vowels.java @@ -0,0 +1,83 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileNotFoundException; +class Vowels { + public static void main(String[] args) throws java.io.IOException{ + int VA = 0; + int VE = 0; + int VI = 0; + int VO = 0; + int VU = 0; + int NV = 0; + + try{ + File f=new File("input.txt"); + FileReader file = new FileReader(f); + BufferedReader input = new BufferedReader(file); //I miss unix pipes, they make life so much nicer + int c = 0; + while((c = input.read()) != -1){ + char character = (char) c; + + + + switch(character){ + + case 'A': + VA++; + break; + case 'a': + VA++; + break; + case 'E': + VE++; + break; + case 'e': + VE++; + break; + case 'I': + VI++; + break; + case 'i': + VI++; + break; + case 'O': + VO++; + break; + case 'o': + VO++; + break; + case 'U': + VU++; + break; + case 'u': + VU++; + break; + default: + NV++; + break; + + + + }} +System.out.println("A " + VA); +System.out.println("E " + VE); +System.out.println("I " + VI); +System.out.println("O " + VO); +System.out.println("U " + VU); +System.out.println("No Vowels " + NV); + }catch(FileNotFoundException e) { + + System.out.println("No Inputfile Provided"); + + + + + + + + } +} +} +//By msglm; Licensed under the AGPL v3 diff --git a/Java/WedgeOfStars.java b/Java/WedgeOfStars.java new file mode 100644 index 0000000..e9c42e2 --- /dev/null +++ b/Java/WedgeOfStars.java @@ -0,0 +1,21 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class WedgeofStars { + public static void main(String[] args) throws java.io.IOException { + int iterations; + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + System.out.println("Number of stars:"); + iterations = Integer.parseInt(input.readLine()); + + + for(iterations=iterations;iterations>0;iterations--){ + System.out.print("\n"); + for(int i=iterations;i>0;i--){ + System.out.print("*"); + } + } + + +}} +//By msglm; Licensed under the AGPL v3 diff --git a/Java/WordLength.java b/Java/WordLength.java new file mode 100644 index 0000000..86d1e09 --- /dev/null +++ b/Java/WordLength.java @@ -0,0 +1,22 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; + +class WordLength { + public static void main(String[] args) throws java.io.IOException { + int charnum; + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + System.out.println("Word"); + String word = input.readLine(); + System.out.println("\n"); + for(charnum=word.length();charnum>0; charnum--){ + System.out.println(word); + } + + + + + + } +} + +//By msglm; Licensed under the AGPL v3 diff --git a/Java/coin.java b/Java/coin.java new file mode 100644 index 0000000..4765812 --- /dev/null +++ b/Java/coin.java @@ -0,0 +1,28 @@ +import java.util.Random; + +public class coin{ + + private boolean status; + +public coin(){ + Random random = new Random(); +if (random.nextInt() % 2 == 1){ + status = true; +} else { + status = false; +} + +} + +public String toString(){ + if(status){ +return "coin is heads"; + } else { +return "coin is tails"; + } +} + +} + + + diff --git a/Java/house.java b/Java/house.java new file mode 100644 index 0000000..582288c --- /dev/null +++ b/Java/house.java @@ -0,0 +1,16 @@ +class house { + public static void main(String[] args) { + System.out.println("\t / \\"); + System.out.println("\t / \\"); + System.out.println("\t/ \\"); + System.out.println("\t| |"); + System.out.println("\t| || |"); + System.out.println("\t| || |"); + System.out.println("This was awful"); + + + + } +} + +//By msglm; Licensed under the AGPL v3 |