Skip to content

Instantly share code, notes, and snippets.

View jonathansager's full-sized avatar

jonathansager

View GitHub Profile
@jonathansager
jonathansager / rockpaperscissors.java
Created March 1, 2017 21:08
Rock paper scissors java game
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);
var compare = function (choice1, choice2) {
@jonathansager
jonathansager / race.java
Created March 1, 2017 18:21
Choose your own adventure java game
// Check if the user is ready to play!
confirm("Are you ready to play?");
var age = prompt("How old are you?");
if (age < 13)
{
console.log("You are not allowed to play!");
}
else
@jonathansager
jonathansager / battleship.py
Last active February 25, 2017 20:54
Battleship for python
from random import randint
board = []
for x in range(5):
board.append(["O"] * 5)
def print_board(board):
for row in board:
print " ".join(row)
import java.util.HashMap;
public class Library {
public Library(){
}
public void getFinishedBooks(HashMap<String, Boolean> library){
if (library.size() < 1){
System.out.println("The size is empty");
}
import java.util.ArrayList;
public class GradeAnalyzer{
public GradeAnalyzer(){
}
public int getAverage(ArrayList<Integer> grades){
if (grades.size() < 1){
System.out.println("Array List is empty");
print ("what is your name?")
user_input = gets.chomp
user_input.downcase!
if user_input.include? "s"
user_input.gsub!(/s/,"th")
puts ("Your name includes is #{user_input}")
else
print ("Your name does not include an s")
end
@jonathansager
jonathansager / name.rb
Created February 16, 2017 14:54
ruby
print "What's your first name?"
first_name = gets.chomp
first_name.capitalize!
print "What's your last name?"
last_name = gets.chomp
last_name.capitalize!
print "What city are you from?"
city = gets.chomp
public class Calculator {
int t;
int u;
int total;
int sub;
int mult;
int d;
int mod;
public class Continents {
public static void main(String[] args) {
//returns Africa case
int continent= '4';
switch (continent) {
case '1':
System.out.println("North America: Mexico City, Mexico");
break;
case '2':
System.out.println("South America:Sao Paulo, Brazil");
public class CarLoan {
public static void main(String[] args) {
int carLoan= 10000;
int loanLength =3;
int interestRate=5;
int downPayment=2000;
if (loanLength <=0 || interestRate <= 0){
System.out.println("This is not a valid car loan. Check your interest rate and/or loan length.");