include assignment1
This commit is contained in:
4 files changed
+249
No files matched your search
@@ -0,0 +1,77 @@
|
|||||||
|
package dev.sowinski.comp1510.assignment1.q1;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change calculates bills and coins
|
||||||
|
* required to represent a given dollar
|
||||||
|
* amount.
|
||||||
|
*
|
||||||
|
* @author Braeden Sowinski
|
||||||
|
* @version 1.0.0
|
||||||
|
*/
|
||||||
|
public class Change {
|
||||||
|
|
||||||
|
/** TEN represents ten dollar bill. */
|
||||||
|
static final double TEN = 10.00;
|
||||||
|
|
||||||
|
/** FIVE represents five dollar bill. */
|
||||||
|
static final double FIVE = 5.00;
|
||||||
|
|
||||||
|
/** TOONIE represents 2 dollar coin. */
|
||||||
|
static final double TOONIE = 2.00;
|
||||||
|
|
||||||
|
/** LOONIE represents 1 dollar coin. */
|
||||||
|
static final double LOONIE = 1.00;
|
||||||
|
|
||||||
|
/** QUARTER represents the quarter coin. */
|
||||||
|
static final double QUARTER = 0.25;
|
||||||
|
|
||||||
|
/** DIME represents the dime coin. */
|
||||||
|
static final double DIME = 0.10;
|
||||||
|
|
||||||
|
/** NICKEL represents the nickel coin. */
|
||||||
|
static final double NICKEL = 0.05;
|
||||||
|
|
||||||
|
/** PENNY represents the penny coin. */
|
||||||
|
static final double PENNY = 0.01;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* main program entry.
|
||||||
|
* @param args unused
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
final double magicNumber = 0.001;
|
||||||
|
Scanner scan = new Scanner(System.in);
|
||||||
|
|
||||||
|
System.out.print("Enter dollar amount: ");
|
||||||
|
double dollars = scan.nextDouble();
|
||||||
|
scan.close();
|
||||||
|
|
||||||
|
System.out.println("You will need the following to make $" + dollars);
|
||||||
|
|
||||||
|
System.out.println((int) (dollars / TEN) + " $10 dollar bill(s).");
|
||||||
|
dollars %= TEN;
|
||||||
|
|
||||||
|
System.out.println((int) (dollars / FIVE) + " $5 dollar bill(s).");
|
||||||
|
dollars %= FIVE;
|
||||||
|
|
||||||
|
System.out.println((int) (dollars / TOONIE) + " $2 toonie(s).");
|
||||||
|
dollars %= TOONIE;
|
||||||
|
|
||||||
|
System.out.println((int) (dollars / LOONIE) + " $1 loonie(s).");
|
||||||
|
dollars %= LOONIE;
|
||||||
|
|
||||||
|
System.out.println((int) (dollars / QUARTER) + " $0.25 quarter(s).");
|
||||||
|
dollars %= QUARTER;
|
||||||
|
dollars += magicNumber;
|
||||||
|
|
||||||
|
System.out.println((int) (dollars / DIME) + " $0.1 dime(s).");
|
||||||
|
dollars %= DIME;
|
||||||
|
|
||||||
|
System.out.println((int) (dollars / NICKEL) + " $0.05 nickel(s).");
|
||||||
|
dollars %= NICKEL;
|
||||||
|
|
||||||
|
System.out.println((int) (dollars / PENNY) + " $0.01 pennie(s).");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package dev.sowinski.comp1510.assignment1.q2;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sqrt estimates the square root of a
|
||||||
|
* given number.
|
||||||
|
*
|
||||||
|
* @author Braeden Sowinski
|
||||||
|
* @version 1.0.0
|
||||||
|
*/
|
||||||
|
public class Sqrt {
|
||||||
|
/**
|
||||||
|
* main program entry.
|
||||||
|
* @param args unused
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scan = new Scanner(System.in);
|
||||||
|
System.out.print("Please enter a number: ");
|
||||||
|
double a = scan.nextDouble();
|
||||||
|
scan.close();
|
||||||
|
|
||||||
|
double s = (a + 1) / 2;
|
||||||
|
System.out.println("Estimate 1: " + s);
|
||||||
|
|
||||||
|
s = (s + a / s) / 2;
|
||||||
|
System.out.println("Esitmate 2: " + s);
|
||||||
|
|
||||||
|
s = (s + a / s) / 2;
|
||||||
|
System.out.println("Esitmate 3: " + s);
|
||||||
|
|
||||||
|
s = (s + a / s) / 2;
|
||||||
|
System.out.println("Esitmate 4: " + s);
|
||||||
|
|
||||||
|
s = (s + a / s) / 2;
|
||||||
|
System.out.println("Esitmate 5: " + s);
|
||||||
|
|
||||||
|
s = (s + a / s) / 2;
|
||||||
|
System.out.println("Esitmate 6: " + s);
|
||||||
|
|
||||||
|
s = (s + a / s) / 2;
|
||||||
|
System.out.println("Esitmate 7: " + s);
|
||||||
|
|
||||||
|
s = (s + a / s) / 2;
|
||||||
|
System.out.println("Esitmate 8: " + s);
|
||||||
|
|
||||||
|
s = (s + a / s) / 2;
|
||||||
|
System.out.println("Esitmate 9: " + s);
|
||||||
|
|
||||||
|
s = (s + a / s) / 2;
|
||||||
|
System.out.println("Esitmate 10: " + s);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package dev.sowinski.comp1510.assignment1.q3;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse reads strings back in reverse.
|
||||||
|
*
|
||||||
|
* @author Braeden Sowinski
|
||||||
|
* @version 1.0.0
|
||||||
|
*/
|
||||||
|
public class Reverse {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* main program entry.
|
||||||
|
* @param args unused
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Stack<String> wordStack = new Stack<String>();
|
||||||
|
|
||||||
|
Scanner scan = new Scanner(System.in);
|
||||||
|
System.out.println("Enter ten words!");
|
||||||
|
|
||||||
|
wordStack.push(scan.next());
|
||||||
|
wordStack.push(scan.next());
|
||||||
|
wordStack.push(scan.next());
|
||||||
|
wordStack.push(scan.next());
|
||||||
|
wordStack.push(scan.next());
|
||||||
|
wordStack.push(scan.next());
|
||||||
|
wordStack.push(scan.next());
|
||||||
|
wordStack.push(scan.next());
|
||||||
|
wordStack.push(scan.next());
|
||||||
|
wordStack.push(scan.next());
|
||||||
|
|
||||||
|
scan.close();
|
||||||
|
|
||||||
|
System.out.println(wordStack.pop() + " "
|
||||||
|
+ wordStack.pop() + " "
|
||||||
|
+ wordStack.pop() + " "
|
||||||
|
+ wordStack.pop() + " "
|
||||||
|
+ wordStack.pop() + " "
|
||||||
|
+ wordStack.pop() + " "
|
||||||
|
+ wordStack.pop() + " "
|
||||||
|
+ wordStack.pop() + " "
|
||||||
|
+ wordStack.pop() + " "
|
||||||
|
+ wordStack.pop()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package dev.sowinski.comp1510.assignment1.q4;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pack encodes 5 MIX-character strings into a
|
||||||
|
* single int variable, while also being able to
|
||||||
|
* decode an int variable back to the original
|
||||||
|
* characters.
|
||||||
|
*
|
||||||
|
* @author Braeden Sowinski
|
||||||
|
* @version 1.0.0
|
||||||
|
*/
|
||||||
|
public class Pack {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* main program entry.
|
||||||
|
* @param args unused
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scan = new Scanner(System.in);
|
||||||
|
System.out.print("Enter 5 MIX-characters (A-I): ");
|
||||||
|
String raw = scan.nextLine();
|
||||||
|
scan.close();
|
||||||
|
|
||||||
|
final int idx0 = 0;
|
||||||
|
final int idx1 = 1;
|
||||||
|
final int idx2 = 2;
|
||||||
|
final int idx3 = 3;
|
||||||
|
final int idx4 = 4;
|
||||||
|
|
||||||
|
char c1 = raw.charAt(idx0);
|
||||||
|
char c2 = raw.charAt(idx1);
|
||||||
|
char c3 = raw.charAt(idx2);
|
||||||
|
char c4 = raw.charAt(idx3);
|
||||||
|
char c5 = raw.charAt(idx4);
|
||||||
|
|
||||||
|
final int base = 56;
|
||||||
|
|
||||||
|
int encoded = (int) (c1 - 'A' + 1) * (int) Math.pow(base, idx4)
|
||||||
|
+ (c2 - 'A' + 1) * (int) Math.pow(base, idx3)
|
||||||
|
+ (c3 - 'A' + 1) * (int) Math.pow(base, idx2)
|
||||||
|
+ (c4 - 'A' + 1) * (int) Math.pow(base, idx1)
|
||||||
|
+ (c5 - 'A' + 1) * (int) Math.pow(base, idx0);
|
||||||
|
|
||||||
|
System.out.println("Encoded: " + encoded);
|
||||||
|
|
||||||
|
char decodeC5 = (char) ((encoded % base) - 1 + 'A');
|
||||||
|
encoded /= base;
|
||||||
|
|
||||||
|
char decodeC4 = (char) ((encoded % base) - 1 + 'A');
|
||||||
|
encoded /= base;
|
||||||
|
|
||||||
|
char decodeC3 = (char) ((encoded % base) - 1 + 'A');
|
||||||
|
encoded /= base;
|
||||||
|
|
||||||
|
char decodeC2 = (char) ((encoded % base) - 1 + 'A');
|
||||||
|
encoded /= base;
|
||||||
|
|
||||||
|
char decodeC1 = (char) ((encoded % base) - 1 + 'A');
|
||||||
|
|
||||||
|
System.out.println("Decoded: "
|
||||||
|
+ decodeC1
|
||||||
|
+ decodeC2
|
||||||
|
+ decodeC3
|
||||||
|
+ decodeC4
|
||||||
|
+ decodeC5);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user