Skip to content

Instantly share code, notes, and snippets.

View speters33w's full-sized avatar

Stephan Peters speters33w

  • Greene, Pennsylvania, USA
  • 08:45 (UTC -05:00)
  • LinkedIn in/speters33w
View GitHub Profile
@speters33w
speters33w / GradesAndPoints.java
Last active April 5, 2022 20:58
Grades and Points exercise from University of Helsinki Java Programming 1
// A different approach to the Grades and Points exercize from University of Helsinki’s Java Programming I
// https://java-programming.mooc.fi/part-1/6-conditional-statements
//Programming exercise:
// Grades and Points
// Points
// 1/1
//
// The table below describes how the grade for a particular course is determined.
// Write a program that gives a course grade according to the provided table.
@speters33w
speters33w / ByteShortLong.java
Created April 3, 2022 19:41
Min and max values of Java Primitives
public class ByteShortIntLong {
public static void main(String[] args) {
byte myMinByteValue = Byte.MIN_VALUE;
byte myMaxByteValue = Byte.MAX_VALUE;
System.out.println("8 Bit Byte Minimum Value = " + myMinByteValue);
System.out.println("8 Bit Byte Maximum Value = " + myMaxByteValue);
short myMinShortValue = Short.MIN_VALUE;
@speters33w
speters33w / JavaLoopsII.java
Last active April 5, 2022 20:38
Mockup for Hacker Rank Java Loops II Challenge
/*
We use the integers a, b, and n to create the following series:
(a + 2⁰ · b),(a + 2⁰ · b + 2¹ · b),...,(a + 2⁰ · b + 2¹ · b +...+2⁽ⁿ⁻¹⁾ · b)
You are given q queries in the form of a, b, and n. For each query, print the series corresponding to the given a, b, and n values as a single line of n space-separated integers.
Input Format
The first line contains an integer, q, denoting the number of queries.
Each line i of the q subsequent lines contains three space-separated integers describing the respective a, b, and n values for that query.
Constraints
• 0 ≤ q ≤ 500
• 0 ≤ a,b ≤ 50
@speters33w
speters33w / FeetAndInchesToCentimeters.java
Created April 5, 2022 20:37
Feet and Inches to Centimeters Java Method Overloading Sample
public class FeetAndInchesToCentimeters {
//This is a sample of Java Method overloading.
//My solution to a challenge from Udemy Java Programming Masterclass covering Java 11 & Java 17
//by Tim Buchalka Lecture 58.
public static void main(String[] args) {
System.out.println(FeetAndInchesToCentimeters.calcFeetAndInchesToCentimeters(5,10));
System.out.println(FeetAndInchesToCentimeters.calcFeetAndInchesToCentimeters(4,10));
System.out.println(FeetAndInchesToCentimeters.calcFeetAndInchesToCentimeters(70));
@speters33w
speters33w / PerimeterAssignmentRunner.java
Created April 12, 2022 00:03
Coursera Duke PerimeterAssignmentRunner
import edu.duke.DirectoryResource;
import edu.duke.FileResource;
import edu.duke.Point;
import edu.duke.Shape;
import java.io.File;
/* example input file:
example.txt
2, 2
@speters33w
speters33w / PlayingCat.java
Last active April 19, 2022 02:20
Playing Cat Coding Exercise from Udemy Java Programming Masterclass
//Udemy
// Java Programming Masterclass covering Java 11 & Java 17
// Playing Cat
//
// The cats spend most of the day playing. In particular, they play if the temperature is between 25 and 35 (inclusive).
// Unless it is summer, then the upper limit is 45 (inclusive) instead of 35.
//
// Write a method isCatPlaying that has 2 parameters.
// Method needs to return true if the cat is playing, otherwise return false
// 1st parameter should be of type boolean and be named summer it represents if it is summer.
@speters33w
speters33w / SecondsAndMinutesChallenge.java
Created April 19, 2022 02:51
Udemy Java Programming Masterclass Seconds and Minutes Challenge
//Udemy
//Java Programming Masterclass covering Java 11 & Java 17
//SecondsAndMinutesChallenge
//Create a method called getDurationString with two parameters, first parameter minutes and 2nd parameter seconds.
//You should validate that the first parameter minutes is >= 0.
//You should validate that the 2nd parameter seconds is >= 0 and <= 59.
//The method should return "Invalid value" in the method if either of the above are not true.
//If the parameters are valid then calculate how many hours minutes and seconds equal the minutes and seconds passed
//to this method and return that value as string in format "XXh YYm ZZs" where XX represents a number of hours,
@speters33w
speters33w / SwitchStatementChallenge.java
Last active April 19, 2022 15:20
Udemy Java Masterclass Switch Statement Challenge
//Udemy
//Java Programming Masterclass covering Java 11 & Java 17
//Switch Statement Challenge
//
//Create a new switch statement using char
//Create a new char variable
//Create a switch statement testing for
//A, B, C, D, E
//Display a message if any of these are found and break
//Add a default which displays a message saying not found
@speters33w
speters33w / PrintDayOfTheWeek.java
Last active April 19, 2022 17:02
Udemy Java Programming Masterclass Day of the Week Challenge and Bonus Challenge
//Udemy
//Java Programming Masterclass covering Java 11 & Java 17
//Day of the Week Challenge
//
//Write a method with the name printDayOfTheWeek that has one parameter of type int and name it day.
//
//The method should not return any value (hint: void)
//
//Using a switch statement print "Sunday", "Monday", ... ,"Saturday" if the int parameter "day" is 0, 1, ... , 6 respectively,
//otherwise it should print "Invalid day".
@speters33w
speters33w / NumberInWord.java
Created April 19, 2022 17:57
Udemy Java Programming Masterclass Number in Word Challenge
//Udemy
// Java Programming Masterclass covering Java 11 & Java 17
// Number In Word
//
// Write a method called printNumberInWord.
// The method has one parameter number which is the whole number.
// The method needs to print "ZERO", "ONE", "TWO", ... "NINE", "OTHER"
// if the int parameter number is 0, 1, 2, .... 9 or other for any other number including negative numbers.
// You can use if-else statement or switch statement whatever is easier for you.
//