week 5 done

This commit is contained in:
Scott 2025-09-22 22:10:48 -07:00
parent 27dab22a7a
commit bbfffb87ac
25 changed files with 699 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/.metadata/

10
dropbox12/.classpath Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=""/>
<classpathentry kind="output" path=""/>
</classpath>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>dropbox08</name>
<name>dropbox12</name>
<comment></comment>
<projects>
</projects>

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

3
dropbox12/dropbox12/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/Student.class
/student.class
/StudentTest.class

View File

@ -0,0 +1,66 @@
/**
* Assignment 12
* Course: CISS238
* Student: Scott Steely
* Date: Sep 22, 2025
*/
package dropbox12;
import java.util.ArrayList;
import java.util.Collections;
public class Student {
// fileds
private String name;
private ArrayList<String> courses;
//accessors
public String getName() {
return name;
}
public ArrayList<String> getCourses() {
return courses;
}
// mutators
public void setName(String name) {
this.name = name;
}
public void setCourses(ArrayList<String> courses) {
this.courses = courses;
}
// constructors
public Student(String name, ArrayList<String> courses) {
this.name = name;
this.courses = courses;
}
// methods
public void addCourse(String course) {
getCourses().add(course);
}
public void removeCourse(String course) {
getCourses().remove(course);
}
public void sortCourses() {
Collections.sort(getCourses());
}
public int findCoursePosition(String course) {
return getCourses().indexOf(course) + 1;
}
public boolean isCourseCompleted(String course) {
return getCourses().contains(course);
}
// toString
@Override
public String toString() {
String str;
str = String.format("Name: %s%n$d courses%n", getName(), getCourses().size());
for(String c:getCourses()) {
str += String.format("%s, ", c);
}
return str;
}
}

View File

@ -0,0 +1,86 @@
/**
* Assignment 12
* Course: CISS238
* Student: Scott Steely
* Date: Sep 22, 2025
*/
package dropbox12;
import java.util.ArrayList;
import java.util.Scanner;
public class StudentTest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// variables
String name;
String course;
// two courses in an ArrayList
ArrayList<String> myCourses = new ArrayList<>();
myCourses.add("CS 101");
myCourses.add("CS 102");
// prompt user for input
System.out.println("Enter student name: ");
name = input.nextLine();
// create a student with the two courses
Student student = new Student(name, myCourses);
int menuSelected;
// display a user menu
System.out.println("Enter a number for the task:");
System.out.println("1. Add a course.");
System.out.println("2. Drop a course.");
System.out.println("3. Find the position of a course.");
System.out.println("4. Display all courses.");
System.out.println("5. Sort courses.");
System.out.println("6. Exit.");
menuSelected = input.nextInt();
input.nextLine();
while(menuSelected > 0 && menuSelected <6) {
switch(menuSelected) {
case 1:
System.out.println("Enter a course: ");
course = input.nextLine();
student.addCourse(course);
System.out.println("Course added.");
break;
case 2:
System.out.println("Enter a course to delete:");
course = input.nextLine();
student.removeCourse(course);
System.out.println("Course dropped.");
break;
case 3:
System.out.println("Enter a course to see its position: ");
course = input.nextLine();
// check if the course is in the completed list
if(student.isCourseCompleted(course)) {
System.out.printf("%s is in position %d%n",
course, student.findCoursePosition(course));
} else {
System.out.printf("%s is not completed yet.", course);
}
break;
case 4:
System.out.println(student);
break;
case 5:
student.sortCourses();
System.out.println(student);
}
// display a user menu
System.out.println("Enter a number for the task:");
System.out.println("1. Add a course.");
System.out.println("2. Drop a course.");
System.out.println("3. Find the position of a course.");
System.out.println("4. Display all courses.");
System.out.println("5. Sort courses.");
System.out.println("6. Exit.");
menuSelected = input.nextInt();
input.nextLine();
}
input.close();
}
}

10
dropbox13/.classpath Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=""/>
<classpathentry kind="output" path=""/>
</classpath>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>dropbox08</name>
<name>dropbox13</name>
<comment></comment>
<projects>
</projects>

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

2
dropbox13/dropbox13/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/Employee.class
/EmployeeTest.class

View File

@ -0,0 +1,67 @@
/**
* Assignment 13
* Skill: CISS238
* Student: Scott Steely
* Date: Sep 22, 2025
*/
package dropbox13;
import java.util.ArrayList;
import java.util.Collections;
public class Employee{
// fileds
private String name;
private ArrayList<String> skills;
//accessors
public String getName() {
return name;
}
public ArrayList<String> getSkills() {
return skills;
}
// mutators
public void setName(String name) {
this.name = name;
}
public void setSkills(ArrayList<String> skills) {
this.skills = skills;
}
// constructors
public Employee(String name, ArrayList<String> skills) {
this.name = name;
this.skills = skills;
}
// methods
public void addSkill(String skill) {
getSkills().add(skill);
}
public void removeSkill(String skill) {
getSkills().remove(skill);
}
public void sortSkills() {
Collections.sort(getSkills());
}
public int findSkillPosition(String skill) {
return getSkills().indexOf(skill) + 1;
}
public boolean isSkillCompleted(String skill) {
return getSkills().contains(skill);
}
// toString
@Override
public String toString() {
String str;
str = String.format("Name: %s%nSkills :%n", getName(), getSkills().size());
for(String c:getSkills()) {
str += String.format("%s, ", c);
}
return str;
}
}

View File

@ -0,0 +1,87 @@
/**
* Assignment 13
* Skill: CISS238
* Employee: Scott Steely
* Date: Sep 22, 2025
*/
package dropbox13;
import java.util.ArrayList;
import java.util.Scanner;
public class EmployeeTest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// variables
String name;
String skill;
// two skills in an ArrayList
ArrayList<String> mySkills = new ArrayList<>();
mySkills.add("Diviner/Dowser");
mySkills.add("Alchemist");
// prompt user for input
System.out.println("Enter employee name: ");
name = input.nextLine();
// create a employee with the two skills
Employee employee = new Employee(name, mySkills);
int menuSelected;
// display a user menu
System.out.println("Enter a number for the task:");
System.out.println("1. Add a skill.");
System.out.println("2. Drop a skill.");
System.out.println("3. Find the position of a skill.");
System.out.println("4. Display all skills.");
System.out.println("5. Sort skills.");
System.out.println("6. Exit.");
menuSelected = input.nextInt();
input.nextLine();
while(menuSelected > 0 && menuSelected <6) {
switch(menuSelected) {
case 1:
System.out.println("Enter a skill: ");
skill = input.nextLine();
employee.addSkill(skill);
System.out.println("Skill added.");
break;
case 2:
System.out.println("Enter a skill to delete:");
skill = input.nextLine();
employee.removeSkill(skill);
System.out.println("Skill dropped.");
break;
case 3:
System.out.println("Enter a skill to see its position: ");
skill = input.nextLine();
// check if the skill is in the completed list
if(employee.isSkillCompleted(skill)) {
System.out.printf("%s is in position %d%n",
skill, employee.findSkillPosition(skill));
} else {
System.out.printf("%s is not completed yet.", skill);
}
break;
case 4:
System.out.println(employee);
break;
case 5:
employee.sortSkills();
System.out.println(employee);
}
// display a user menu
System.out.println("Enter a number for the task:");
System.out.println("1. Add a skill.");
System.out.println("2. Drop a skill.");
System.out.println("3. Find the position of a skill.");
System.out.println("4. Display all skills.");
System.out.println("5. Sort skills.");
System.out.println("6. Exit.");
menuSelected = input.nextInt();
input.nextLine();
}
input.close();
}
}

10
dropbox14/.classpath Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=""/>
<classpathentry kind="output" path=""/>
</classpath>

17
dropbox14/.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>dropbox14</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

2
dropbox14/dropbox14/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/Date2.class
/Date2Test.class

View File

@ -0,0 +1,144 @@
/**
* Assignment 14
* Skill: CISS238
* Student: Scott Steely
* Date: Sep 28, 2025
*/
package dropbox14;
public class Date2 {
// fields
private String month;
private int day;
private int year;
// accessors
public String getMonth() {
return month;
}
public int getDay() {
return day;
}
public int getYear() {
return year;
}
// mutators
public void setMonth(String month) {
this.month = month;
}
public void setDay(int day) {
this.day = day;
}
public void setYear(int year) {
this.year = year;
}
// constructors
public Date2() {
month = "January";
day = 1;
year = 1000;
}
public Date2(String month, int day, int year) {
this.month = month;
this.day = day;
this.year = year;
}
public Date2(int month, int day, int year) {
this.day = day;
this.year = year;
switch(month) {
case 1:
this.month = "January";
break;
case 2:
this.month = "February";
break;
case 3:
this.month = "March";
break;
case 4:
this.month = "April";
break;
case 5:
this.month = "May";
break;
case 6:
this.month = "June";
break;
case 7:
this.month = "July";
break;
case 8:
this.month = "August";
break;
case 9:
this.month = "September";
break;
case 10:
this.month = "October";
break;
case 11:
this.month = "November";
break;
case 12:
this.month = "December";
break;
}
}
public Date2(int year) {
this(1, 1, year);
}
public Date2(Date2 date2) {
this(date2.getMonth(), date2.getDay(), date2.getYear());
}
// methods
public String dateInNumber() {
String str;
switch(getMonth()) {
case "January":
str = "1";
break;
case "February":
str = "2";
break;
case "March":
str = "3";
break;
case "April":
str = "4";
break;
case "May":
str = "5";
break;
case "June":
str = "6";
break;
case "July":
str = "7";
break;
case "August":
str = "8";
break;
case "September":
str = "9";
break;
case "October":
str = "10";
break;
case "November":
str = "11";
break;
case "December":
str = "12";
break;
default:
str = "00";
break;
}
str += "/" + getDay() + "/" + getYear();
return str;
}
public String dateInWord() {
String str;
str = getMonth() + " " + getDay() + " " + getYear();
return str;
}
}

View File

@ -0,0 +1,28 @@
/**
* Assignment 14
* Skill: CISS238
* Student: Scott Steely
* Date: Sep 28, 2025
*/
package dropbox14;
public class Date2Test {
public static void main(String[] args) {
// five objects
Date2 date2a = new Date2();
Date2 date2b = new Date2("August", 12, 1990);
Date2 date2c = new Date2(3, 21, 1991);
Date2 date2d = new Date2(1992);
Date2 date2e = new Date2(date2b);
// display each object in two formats
System.out.println(date2a.dateInNumber());
System.out.println(date2a.dateInWord());
System.out.println(date2b.dateInNumber());
System.out.println(date2b.dateInWord());
System.out.println(date2c.dateInNumber());
System.out.println(date2c.dateInWord());
System.out.println(date2d.dateInNumber());
System.out.println(date2d.dateInWord());
System.out.println(date2e.dateInNumber());
System.out.println(date2e.dateInWord());
}
}

10
dropbox15/.classpath Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=""/>
<classpathentry kind="output" path=""/>
</classpath>

17
dropbox15/.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>dropbox15</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

2
dropbox15/dropbox15/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/Time2.class
/Time2Test.class

View File

@ -0,0 +1,88 @@
/**
* Assignment 15
* Skill: CISS238
* Student: Scott Steely
* Date: Sep 28, 2025
*/
package dropbox15;
public class Time2 {
// fields
private int hour;
private int minute;
private int second;
// accessors
public int getHour() {
return hour;
}
public int getMinute() {
return minute;
}
public int getSecond() {
return second;
}
// mutators
public void setHour(int hour) {
if (hour < 0 || hour > 23) { // There is no such thing as 24 'oclock' in standard military time
throw new IllegalArgumentException("Hour must be between 0 and 23.");
}
this.hour = hour;
}
public void setMinute(int minute) {
if (minute < 0 || minute > 59) {
throw new IllegalArgumentException("Minute must be between 0 and 59.");
}
this.minute = minute;
}
public void setSecond(int second) {
if (second < 0 || second > 59) {
throw new IllegalArgumentException("Second must be between 0 and 59.");
}
this.second = second;
}
// constructors
public Time2() {
this(1,1,1);
}
public Time2(int hour, int minute, int second) {
setHour(hour);
setMinute(minute);
setSecond(second);
}
public Time2(int hour) {
this(hour, 0, 0);
}
public Time2(int hour, int minute) {
this(hour, minute, 00);
}
public Time2(Time2 time2) {
this(time2.getHour(), time2.getMinute(), time2.getSecond());
}
// method
public String militaryTime(){
return String.format("%02d:%02d:%02d", getHour(), getMinute(), getSecond());
}
public String standardTime() {
int displayHour = getHour();
String AM_PM = "AM";
if (displayHour == 0) { // 00:xx:xx (Midnight) -> 12:xx:xx AM
displayHour = 12;
AM_PM = "AM";
}
else if (displayHour == 12){
AM_PM = "PM";
}
else if (displayHour > 12){
displayHour = displayHour - 12;
AM_PM = "PM";
}
return String.format("%d:%02d:%02d %s",
displayHour,
getMinute(),
getSecond(),
AM_PM);
}
}

View File

@ -0,0 +1,39 @@
/**
* Assignment 15
* Skill: CISS238
* Student: Scott Steely
* Date: Sep 28, 2025
*/
package dropbox15;
public class Time2Test {
public static void main(String[] args) {
// five objects
// The default constructor was changed to initialize to 00:00:00
Time2 time2a = new Time2(); // 00:00:00
Time2 time2b = new Time2(14, 12, 43); // 14:12:43
Time2 time2c = new Time2(3); // 03:00:00
Time2 time2d = new Time2(3, 25); // 03:25:00
Time2 time2e = new Time2(time2b); // 14:12:43 (Copy of time2b)
System.out.println("--- Time 2a (Default: 00:00:00) ---");
System.out.println("Standard Time: " + time2a.standardTime()); // Calling standardTime() with NO arguments
System.out.println("Military Time: " + time2a.militaryTime());
System.out.println("\n--- Time 2b (14:12:43) ---");
System.out.println("Standard Time: " + time2b.standardTime());
System.out.println("Military Time: " + time2b.militaryTime());
System.out.println("\n--- Time 2c (03:00:00) ---");
System.out.println("Standard Time: " + time2c.standardTime());
System.out.println("Military Time: " + time2c.militaryTime());
System.out.println("\n--- Time 2d (03:25:00) ---");
System.out.println("Standard Time: " + time2d.standardTime());
System.out.println("Military Time: " + time2d.militaryTime());
System.out.println("\n--- Time 2e (Copy of 2b: 14:12:43) ---");
System.out.println("Standard Time: " + time2e.standardTime());
System.out.println("Military Time: " + time2e.militaryTime());
}
}