Markou is absolutely insane
This commit is contained in:
14
Semester 4/EnumDemo/pom.xml
Normal file
14
Semester 4/EnumDemo/pom.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>edu.slcc.asdv.caleb</groupId>
|
||||
<artifactId>EnumDemo</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>20</maven.compiler.source>
|
||||
<maven.compiler.target>20</maven.compiler.target>
|
||||
<exec.mainClass>edu.slcc.asdv.caleb.enumdemo.EnumDemo</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
|
||||
package edu.slcc.asdv.caleb.enumdemo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class EnumDemo {
|
||||
|
||||
public enum Day {
|
||||
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
|
||||
THURSDAY, FRIDAY, SATURDAY
|
||||
}
|
||||
Day day;
|
||||
|
||||
public EnumDemo(Day day)
|
||||
{
|
||||
this.day = day;
|
||||
}
|
||||
|
||||
|
||||
public void tellItLikeItIs() {
|
||||
switch (day) {
|
||||
case MONDAY:
|
||||
System.out.println("Mondays are bad.");
|
||||
break;
|
||||
|
||||
case FRIDAY:
|
||||
System.out.println("Fridays are better.");
|
||||
break;
|
||||
|
||||
case SATURDAY: case SUNDAY:
|
||||
System.out.println("Weekends are best.");
|
||||
break;
|
||||
|
||||
default:
|
||||
System.out.println("Midweek days are so-so.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
public static void main(String[] args)
|
||||
{
|
||||
EnumDemo day1 = new EnumDemo(Day.MONDAY);
|
||||
day1.tellItLikeItIs();
|
||||
EnumDemo day2 = new EnumDemo(Day.TUESDAY);
|
||||
day2.tellItLikeItIs();
|
||||
EnumDemo day3 = new EnumDemo(Day.WEDNESDAY);
|
||||
day3.tellItLikeItIs();
|
||||
EnumDemo day4 = new EnumDemo(Day.THURSDAY);
|
||||
day4.tellItLikeItIs();
|
||||
EnumDemo day5 = new EnumDemo(Day.FRIDAY);
|
||||
day5.tellItLikeItIs();
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package edu.slcc.asdv.caleb.enumdemo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public enum Planet {
|
||||
MERCURY(3.303e+23, 2.4397e6),
|
||||
VENUS(4.869e+24, 6.0518e6),
|
||||
EARTH(5.976e+24, 6.37814e6),
|
||||
MARS(6.421e+23, 3.3972e6),
|
||||
JUPITER(1.9e+27, 7.1492e7),
|
||||
SATURN(5.688e+26, 6.0268e7),
|
||||
URANUS(8.686e+25, 2.5559e7),
|
||||
NEPTUNE(1.024e+26, 2.4746e7);
|
||||
|
||||
private final double mass; // in kilograms
|
||||
private final double radius; // in meters
|
||||
|
||||
Planet(double mass, double radius)
|
||||
{
|
||||
this.mass = mass;
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
private double mass()
|
||||
{
|
||||
return mass;
|
||||
}
|
||||
|
||||
private double radius()
|
||||
{
|
||||
return radius;
|
||||
}
|
||||
|
||||
// universal gravitational constant (m3 kg-1 s-2)
|
||||
public static final double G = 6.67300E-11;
|
||||
|
||||
double surfaceGravity()
|
||||
{
|
||||
return G * mass / (radius * radius);
|
||||
}
|
||||
|
||||
double surfaceWeight(double otherMass)
|
||||
{
|
||||
return otherMass * surfaceGravity();
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
args = new String[1];
|
||||
args[0] = "175";
|
||||
if (args.length != 1) {
|
||||
System.err.println("Usage: java Planet <earth_weight>");
|
||||
System.exit(-1);
|
||||
}
|
||||
double earthWeight = Double.parseDouble(args[0]);
|
||||
double mass = earthWeight / EARTH.surfaceGravity();
|
||||
for (Planet p : Planet.values()) {
|
||||
System.out.printf("Your weight on %s is %f%n",
|
||||
p, p.surfaceWeight(mass));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package edu.slcc.asdv.caleb.enumdemo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class TestPlanet {
|
||||
Planet planet;
|
||||
|
||||
public TestPlanet(Planet planet) {
|
||||
this.planet = planet;
|
||||
}
|
||||
public static void main(String[] args)
|
||||
{
|
||||
//TestPlanet testPlanet = new Planet.valueOf("EARTH");
|
||||
// System.out.println(testPlanet.planet.EARTH);
|
||||
}
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package singlenton;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class SingletonFlight {
|
||||
|
||||
private ArrayList<String> seats;
|
||||
private static SingletonFlight instance;
|
||||
|
||||
private SingletonFlight() {
|
||||
seats = new ArrayList<String>(4);
|
||||
|
||||
}
|
||||
public static SingletonFlight getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new SingletonFlight();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public boolean bookFlight(String nameOfPassenger) {
|
||||
if (seats.size() > 4) {
|
||||
System.out.println("Flight full!");
|
||||
return false;
|
||||
} else {
|
||||
System.out.println("Added " + nameOfPassenger + " now has their seat booked.");
|
||||
seats.add(nameOfPassenger);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public static void main(String[] args)
|
||||
{
|
||||
SingletonFlight passenger1 = SingletonFlight.getInstance();
|
||||
SingletonFlight passenger2 = SingletonFlight.getInstance();
|
||||
SingletonFlight passenger3 = SingletonFlight.getInstance();
|
||||
SingletonFlight passenger4 = SingletonFlight.getInstance();
|
||||
|
||||
passenger1.bookFlight("John Wayne");
|
||||
passenger2.bookFlight("John Wayne Jr.");
|
||||
passenger3.bookFlight("Joanne Wayne");
|
||||
passenger4.bookFlight("Joseph Wayne");
|
||||
passenger4.bookFlight("Jessica Wayne");
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user