Skip to content

Instantly share code, notes, and snippets.

@gitaficionado
gitaficionado / AOCPuzzle.java
Last active December 9, 2020 19:21
Fetches file from res folder. Thanks to TurkeyDev for the code.
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public abstract class AOCPuzzle
{
@gitaficionado
gitaficionado / .java
Created December 9, 2020 19:17
Main file for Advent of code. Thanks to TurkeyDev for sharing this
public class AoC2020Core
{
public static void main(String[] args)
{
//new Day1();
//new Day2();
//new Day3();
//new Day4();
//new Day5();
@gitaficionado
gitaficionado / airplane.java
Last active November 16, 2020 04:21
To be used with Assingment2.java file. The assinment2.class is the runner file.
package edhesive.assignment2;
public class Airplane{
private double distance;
private int direction;
private int altitude;
private String callSign;
public Airplane(String cs, double dist, int dir, int alt){
distance = Math.abs(dist);
@gitaficionado
gitaficionado / Assignment2_Demo.java
Created November 6, 2020 14:01
The Control Tower assignment requires students to write a short program in Java to determine the positions of airplanes relative after changes have been made to their initial starting positions.
/* Assignment 2 - Control Tower */
/* Class name - must be "Assignment2" in order to run*/
import java.util.Scanner;
//import edhesive.assignment2.Airplane;
public class Assignment2
{
public static void main(String[] args)
{
// Create Scanner and Airplane 1
@gitaficionado
gitaficionado / SportsEvent.java
Created January 10, 2020 14:12
Write a program which allows eight scores to be entered, discards the lowest and highest scores, then computes an average score for the contestant. Your program should display the eight entered scores, the average score, and the two discarded scores.
import java.util.*;
public class SportsEvent
{
// instance variables
private double[] scores = new double[8];
private Scanner keyboard = new Scanner(System.in);
/* This method prompts the user to enter in 8 scores and stores
* them in the array scores.
@gitaficionado
gitaficionado / ChanceAtWinningGraps_06_32.java
Created November 29, 2019 21:28
(Game: chance of winning at craps) Revise Exercise 6.30 to run it 10,000 times and display the number of winning games
public class ChanceAtWinningGraps_06_32 {
public static void main(String[] args) {
int winCount = __;
for (int i = ___; i < 10000; i++) {
int dice = _________();
if (dice == ____ || dice == ___) {
_________________++;
}
else if (dice == 2 || dice == 3 || dice == 12) {
@gitaficionado
gitaficionado / Craps_06_30 .java
Created November 29, 2019 21:05
Write a program to play a variation of the game. See the documentation in the program for more information.
/**Game: craps) Craps is a popular dice game played in casinos.
*Write a program to play a variation of the game, as follows:Roll two dice.
*Each die has six faces representing values 1, 2, ..., and 6, respec-tively.
*Check the sum of the two dice. If the sum is 2, 3, or 12 (called craps),
*you lose; if the sum is 7 or 11 (called natural), you win; if the sum is
*another value (i.e., 4, 5, 6, 8, 9, or 10), a point is established.
*Continue to roll the dice until either a 7 or the same point value is rolled.
*If 7 is rolled, you lose. Otherwise, you win.Your program acts as a single player
*See page 222 in the Liang textbook for more information.
*/
@gitaficionado
gitaficionado / ConversionsBtwFeetMetersExercise_06_09.java
Created November 29, 2019 20:31
(Conversions between feet and meters) Write a class that contains the following two methods:/** Convert from feet to meters */public static double footToMeter(double foot)/** Convert from meters to feet */public static double meterToFoot(double meter) See page 217 in the Liang text for more informaiton.
/**
*(Conversions between Celsius and Fahrenheit) Write a class that
*contains the fol-lowing two methods:
*Convert from Celsius to Fahrenheit
*public static double celsiusToFahrenheit(double celsius)
*Convert from Fahrenheit to Celsius
*public static double fahrenheitToCelsius(double fahrenheit)
*The formula for the conversion is:
*fahrenheit = (9.0 / 5) * celsius + 32
*celsius = (5.0 / 9) * (fahrenheit – 32)
@gitaficionado
gitaficionado / ConversionsBTWCelsiusFahrenheit_06_08.java
Created November 29, 2019 20:12
Conversions between Celsius and Fahrenheit) Write a class that contains the fol-lowing two methods:/** Convert from Celsius to Fahrenheit */public static double celsiusToFahrenheit(double celsius)/** Convert from Fahrenheit to Celsius */public static double fahrenheitToCelsius(double fahrenheit)
/**
*(Conversions between Celsius and Fahrenheit) Write a class that contains
*the fol-lowing two methods:/** Convert from Celsius to Fahrenheit
*/public static double celsiusToFahrenheit(double celsius)/**
*Convert from Fahrenheit to Celsius
*/public static double fahrenheitToCelsius(double fahrenheit)
*The formula for the conversion is:
*fahrenheit = (9.0 / 5)
* celsius + 32celsius = (5.0 / 9) * (fahrenheit – 32)
*Write a test program that invokes these methods to display the following tables
@gitaficionado
gitaficionado / DisplayPatterns_06_06.java
Created November 29, 2019 19:59
Write a method to display a pattern similar that on page 216 in the Liang textbook. The method header ispublic static void displayPattern(int n)
/**
*(Display patterns) Write a method to display a pattern as follows:
*1
*2 1
*3 2 1
*...
*n n-1 ... 3 2 1
*The method header is
*public static void displayPattern(int n)
*/