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
Empty file added .metadata/.lock
Empty file.
1,098 changes: 1,098 additions & 0 deletions .metadata/.log

Large diffs are not rendered by default.

Binary file added .metadata/.mylyn/.taskListIndex/segments_1
Binary file not shown.
Empty file.
Binary file added .metadata/.mylyn/.tasks.xml.zip
Binary file not shown.
Binary file added .metadata/.mylyn/repositories.xml.zip
Binary file not shown.
Binary file added .metadata/.mylyn/tasks.xml.zip
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import java.util.Scanner;

public class PigLatin {

public static void main(String[] args) {
// User's string
String stringEntered;

Scanner reader = new Scanner(System.in);

System.out.println("Hello, this is your Pig Latin translator:");

System.out.println();

// Get user's string from input
System.out.println("Enter your string: ");
stringEntered = reader.next();

// Make player's play uppercase
stringEntered = stringEntered.toUpperCase();
reader.close();

writeUserString(stringEntered);
translateString(stringEntered);

}

public static void writeUserString(String stringEntered) {

// Print Player's play
System.out.println("Your string is: " + stringEntered);
}

public static void translateString(String stringEntered) {

// int indexChar = 0;
char firstChar = stringEntered.charAt(0);
// char nextChar = stringEntered.charAt(1);

// If a word starts with a vowel, add "yay" to the end. (elephant ->
// elephantyay)
// If a word starts with a consonant, and has a vowel in the word, move all the
// letters before the initial vowel to the end, then add "ay". (pig -> igpay)
// If a word does not have any vowels, then add "ay". (tsktsk -> tsktskay)

if ((firstChar == ('A')) || (firstChar == ('E')) || (firstChar == ('I')) || (firstChar == ('O'))
|| (firstChar == ('U'))) {
System.out.println("Pig Latin translation is: " + stringEntered + "YAY");
} else {
// System.out.println("String starts with a consonant.");
// for (int i = 1; i < stringEntered.length(); i++) {
// System.out.println("Value of i:" + i);
// if ((nextChar == ('A')) || (nextChar == ('E')) || (nextChar == ('I')) || (nextChar == ('O'))
// || (nextChar == ('U')))
// indexChar = i;
// System.out.println("Value of indexChar:" + i);
// System.out.println("Pig Latin translation is: " + stringEntered.substring(indexChar) + stringEntered.substring(0, indexChar) + "AY");
// }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

import java.util.Scanner;
import java.util.Random;

public class RockPaperScissors {

public static void main(String[] args) {

//User's play -- "R", "P", or "S"
String personPlay;

//Computer's play -- "R", "P", or "S"
String computerPlay = "";

//Randomly generated number used to determine computer's play
int computerInt;

Scanner reader = new Scanner(System.in);
Random randNumGenerator = new Random();

System.out.println("Hello, let's play Rock, Paper, Scissors!\n" +
"Please enter a move.\n" + "Rock = R, Paper= P, and Scissors = S.");

System.out.println();

//Generate computer's play (0,1,2)
computerInt = randNumGenerator.nextInt(3)+1;

//Translate computer's randomly generated play to
//string using if //statements

if (computerInt == 1)
computerPlay = "R";
else if (computerInt == 2)
computerPlay = "P";
else if (computerInt == 3)
computerPlay = "S";

//Get player's play from input-- note that this is
// stored as a string
System.out.println("Enter your play: ");
personPlay = reader.next();

//Make player's play uppercase for ease of comparison
personPlay = personPlay.toUpperCase();
reader.close();

writePersonPlay(personPlay);
writeComputerPlay(computerPlay);
checkForWin(personPlay, computerPlay);

}

public static void writePersonPlay(String personPlay) {

//Print Player's play
System.out.println("Your play is: " + personPlay);
}

public static void writeComputerPlay(String computerPlay) {

//Print computer's play
System.out.println("Computer play is: " + computerPlay);

}

public static void checkForWin(String personPlay, String computerPlay) {

//See who won. Use nested ifs

if (personPlay.equals(computerPlay))
System.out.println("It's a tie!");
else if ((personPlay.equals("R")) && (computerPlay.equals("S")))
System.out.println("Rock crushes scissors. You win!!");
else if ((personPlay.equals("R")) && (computerPlay.equals("P")))
System.out.println("Paper eats rock. You lose!!");
else if ((personPlay.equals("P")) && (computerPlay.equals("S")))
System.out.println("Scissor cuts paper. You lose!!");
else if ((personPlay.equals("P")) && (computerPlay.equals("R")))
System.out.println("Paper eats rock. You win!!");
else if ((personPlay.equals("S")) && (computerPlay.equals("P")))
System.out.println("Scissor cuts paper. You win!!");
else if ((personPlay.equals("S")) && (computerPlay.equals("R")))
System.out.println("Rock breaks scissors. You lose!!");
else
System.out.println("Invalid user input.");

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import java.util.Scanner;

public class PigLatin {

public static void main(String[] args) {
// User's string
String stringEntered;

Scanner reader = new Scanner(System.in);

System.out.println("Hello, this is your Pig Latin translator:");

System.out.println();

// Get user's string from input
System.out.println("Enter your string: ");
stringEntered = reader.next();

// Make player's play uppercase
stringEntered = stringEntered.toUpperCase();
reader.close();

writeUserString(stringEntered);
translateString(stringEntered);

}

public static void writeUserString(String stringEntered) {

// Print Player's play
System.out.println("Your string is: " + stringEntered);
}

public static void translateString(String stringEntered) {

int indexChar = -1;
char firstChar = stringEntered.charAt(0);
char nextChar = stringEntered.charAt(1);
boolean nextVowelFound = false;

// If a word starts with a vowel, add "yay" to the end. (elephant ->
// elephantyay)
// If a word starts with a consonant, and has a vowel in the word, move all the
// letters before the initial vowel to the end, then add "ay". (pig -> igpay)
// If a word does not have any vowels, then add "ay". (tsktsk -> tsktskay)

if ((firstChar == ('A')) || (firstChar == ('E')) || (firstChar == ('I')) || (firstChar == ('O'))
|| (firstChar == ('U')))
System.out.println("Pig Latin translation is: " + stringEntered + "YAY");

else
// if (nextVowelFound != true) {
for (int i = 1; i < stringEntered.length(); i++) {
System.out.println("Value of i:" + i);
if ((nextChar == ('A')) || (nextChar == ('E')) || (nextChar == ('I')) || (nextChar == ('O'))
|| (nextChar == ('U')))
indexChar = i;
System.out.println("Value of indexChar:" + i);
System.out.println("String starts with a consonant.");
System.out.println("Pig Latin translation is: " + stringEntered.substring(indexChar) + stringEntered.substring(0, indexChar) + "AY");
}
nextVowelFound = true;
// }

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

import java.util.Scanner;
import java.util.Random;

public class RockPaperScissors {

public static void main(String[] args) {

//User's play -- "R", "P", or "S"
String personPlay;

//Computer's play -- "R", "P", or "S"
String computerPlay = "";

//Randomly generated number used to determine computer's play
int computerInt;

Scanner reader = new Scanner(System.in);
Random randNumGenerator = new Random();

System.out.println("Hey, let's play Rock, Paper, Scissors!\n" +
"Please enter a move.\n" + "Rock = R, Paper= P, and Scissors = S.");

System.out.println();

//Generate computer's play (0,1,2)
computerInt = randNumGenerator.nextInt(3)+1;

//Translate computer's randomly generated play to
//string using if //statements

if (computerInt == 1)
computerPlay = "R";
else if (computerInt == 2)
computerPlay = "P";
else if (computerInt == 3)
computerPlay = "S";

//Get player's play from input-- note that this is
// stored as a string
System.out.println("Enter your play: ");
personPlay = reader.next();

//Make player's play uppercase for ease of comparison
personPlay = personPlay.toUpperCase();
reader.close();

writePersonPlay(personPlay);
writeComputerPlay(computerInt);




//Print computer's play
System.out.println("Computer play is: " + computerPlay);

//See who won. Use nested ifs

if (personPlay.equals(computerPlay))
System.out.println("It's a tie!");
else if (personPlay.equals("R"))
if (computerPlay.equals("S"))
System.out.println("Rock crushes scissors. You win!!");
else if (computerPlay.equals("P"))
System.out.println("Paper eats rock. You lose!!");
else if (personPlay.equals("P"))
if (computerPlay.equals("S"))
System.out.println("Scissor cuts paper. You lose!!");
else if (computerPlay.equals("R"))
System.out.println("Paper eats rock. You win!!");
else if (personPlay.equals("S"))
if (computerPlay.equals("P"))
System.out.println("Scissor cuts paper. You win!!");
else if (computerPlay.equals("R"))
System.out.println("Rock breaks scissors. You lose!!");
else
System.out.println("Invalid user input.");
}

public static void writePersonPlay(String personPlay) {
System.out.println("Your play is: " + personPlay);
}

public static void writeComputerPlay(int computerInt) {


}


}
Loading