diff --git a/java-track/assignments/Course.java b/java-track/assignments/Course.java new file mode 100644 index 0000000..17d62c5 --- /dev/null +++ b/java-track/assignments/Course.java @@ -0,0 +1,97 @@ + +public class Course { + + private String name; + private int Credits; + private int remainingSeats; + private Student[] roster; + + public Course( String name, int Credits, int numberofSeats) { + + this.name = name; + this.Credits = Credits; + this.remainingSeats = numberofSeats; + this.roster = new Student[numberofSeats]; + } + + + public String getName() { + return name; + } + + + public int getCredits() { + return Credits; + } + + + public int getRemainingSeats() { + return remainingSeats; + } + + + public Student[] getRoster() { + return roster; + } + + + public boolean addStudent(Student student) { + + if (this.remainingSeats == 0) { + return false; + } + + for(int i = 0; i < this.roster.length; i++) { + if(this.roster[i] != null && this.roster[i].getName() == student.getName() ) { + return false; + } + } + + this.roster[this.roster.length - this.remainingSeats ] = student; + this.remainingSeats -= 1; + return true; + } + + public String generateRoster() { + + String rosterNames = ""; + for(int i = 0; i < this.roster.length; i++) { + if(this.roster != null) { + String names = roster[i].getName(); + rosterNames += names + "\n"; + } + } + + return rosterNames; + } + + public double averageGPA(){ + double sumGPA = 0.0; + int numberGPA = 0; + for( int i = 0; i < this.roster.length; i++) + { + if(this.roster[i] != null) { + sumGPA += this.roster[i].getGPA(); + numberGPA ++; + } + } + double averageGPA = sumGPA/numberGPA; + return averageGPA; + } + + public String toString() { + + return this.name + " (" + this.Credits + ")"; + } + + + + + + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} diff --git a/java-track/assignments/Student.java b/java-track/assignments/Student.java new file mode 100644 index 0000000..42f6c45 --- /dev/null +++ b/java-track/assignments/Student.java @@ -0,0 +1,98 @@ + +public class Student { + + private String name; + private int StudentID; + private int Credits; + private double GPA; + + public Student ( String firstName, String lastName, int StudentID){ + this.name = firstName + " " + lastName; + this.StudentID = StudentID; + this.Credits = 0; + this.GPA = 0.0; + + } + + public Student ( String firstName, String lastName, int studId, int Credits, double GPA){ + this.name = firstName + " " + lastName; + this.StudentID = studId; + this.Credits = Credits; + this.GPA = GPA; + + } + + + + + String getName() { + return name; + } + + int getStudentID() { + return StudentID; + } + + int getCredits() { + return Credits; + } + + double getGPA() { + return GPA; + } + + public String getClassStanding() + { + if(this.Credits < 30){ + return "Freshman"; + } + else if( this.Credits <60) { + return "Sophomore"; + } + else if( this.Credits <90) { + return "Junior"; + } + else + return "Senior"; + } + + public void submitGrade(double grade, int credits ){ + double totalCredits = this.Credits + credits; + double oldQualityScore = this.GPA * this.Credits; + double newQualityScore = oldQualityScore + (credits * grade); + double newGpa = newQualityScore / totalCredits; + this.GPA = (double) Math.round(newGpa * 1000.0) / 1000.0; + this.Credits += (int) credits; + return; + } + + public double computeTuition() { + + return (this.Credits / 15) * 20000.0 + (this.Credits % 15) * 1333.33; + } + + public Student createLegacy(Student parent1, Student parent2) { + return new Student( parent1.getName(), + parent2.getName(), + (parent1.StudentID + parent2.StudentID), + (Math.max(parent1.getCredits(), parent2.getCredits())), + ((parent1.getGPA() + parent2.getGPA())/2.0)); + + } + + public String toString() { + return this.name + "(" + this.StudentID + ")" + " " + this.Credits + " " + this.GPA; + } + + public static void main(String[] args) { + // TODO Auto-generated method stub + Student s = new Student("Kwaku", "Twumasi", 3690209, 0,3.6); + Student b = new Student("Kwaku", "Twumasi", 3690209, -2,3.5); + Student m = s.createLegacy(s,b); +System.out.println(s.toString()); +System.out.println(s.getClassStanding()); +System.out.println(m.toString()); + + } + +} diff --git a/java-track/assignments/javagram/Javagram.java b/java-track/assignments/javagram/Javagram.java index c7188d9..ad29d9b 100644 --- a/java-track/assignments/javagram/Javagram.java +++ b/java-track/assignments/javagram/Javagram.java @@ -3,79 +3,205 @@ import javagram.filters.*; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; +import java.util.InputMismatchException; import java.util.Scanner; +import javagram.Picture; public class Javagram { + + protected ArrayList filter; + protected Scanner s; + + public Javagram(){ + + this.s = new Scanner(System.in); + this.filter = new ArrayList(); + + } + + private static int displayFilterMenu(Scanner in){ + System.out.println("Select filter by choosing corresponding number"); + System.out.println("1. BlueFilter"); + System.out.println("2. InvertFilter"); + System.out.println("3. BrightnessFilter"); + + int selectedInt = in.nextInt(); + return selectedInt; + } + public static void main(String[] args) { // Create the base path for images String[] baseParts = {System.getProperty("user.dir"), "images"}; String dir = String.join(File.separator, baseParts); - String relPath; + String relPath = null; Picture picture = null; Scanner in = new Scanner(System.in); - + + + + + + // prompt user for image to filter and validate input + do { - + String imagePath = "path not set"; - + // try to open the file try { - + System.out.println("Image path (relative to " + dir + "):"); relPath = in.next(); - - String[] relPathParts = relPath.split(File.separator); - imagePath = dir + File.separator + String.join(File.separator, Arrays.asList(relPathParts)); - + + imagePath = dir + File.separator + relPath; + picture = new Picture(imagePath); - + } catch (RuntimeException e) { System.out.println("Could not open image: " + imagePath); } - + } while(picture == null); - + // TODO - prompt user for filter and validate input - + + + + int x = 0; + Javagram fm = new Javagram(); + + do { + + try{ + x = Javagram.displayFilterMenu(in); + if(x < 0 || x > 3){ + System.out.println("Please enter valid interger"); + } + }catch (InputMismatchException e) { + System.out.println("Input number not an interger"); + + //fm.processInput(x); + } + + } while (x < 0 || x > 3); + + // TODO - pass filter ID int to getFilter, and get an instance of Filter back - BlueFilter filter = getFilter(); + Filter filter = getFilter(x); // filter and display image Picture processed = filter.process(picture); processed.show(); - + System.out.println("Image successfully filtered"); - + // save image, if desired - - System.out.println("Save image to (relative to " + dir + ") (type 'exit' to quit w/o saving):"); - String fileName = in.next(); - - // TODO - if the user enters the same file name as the input file, confirm that they want to overwrite the original - - if (fileName.equals("exit")) { - System.out.println("Image not saved"); - } else { - String absFileName = dir + File.separator + fileName; - processed.save(absFileName); - System.out.println("Image saved to " + absFileName); - } - + boolean invalidFilename = true; + do { + System.out.println("Save image to (relative to " + dir + ") (type 'exit' to quit w/o saving):"); + System.out.println(relPath); + String fileName = in.next(); + String fileNameHolder = fileName; + + + if(fileName.equals("yes")|| fileName.equals("Yes")|| fileName.equals("y") || fileName.equals("Y")){ + System.out.println("Enter file name:"); + + if(!fileName.equals(relPath)){ + fileName = in.next(); + String absFileName = dir + File.separator + fileName; + processed.save(absFileName); + System.out.println("Image saved to " + absFileName); + invalidFilename = false; + } + } + // TODO - if the user enters the same file name as the input file, confirm that they want to overwrite the original + + + if (fileName.equals("exit")) { + System.out.println("Image not saved"); + invalidFilename = false; + in.close(); + System.exit(0); + } + + + do { + + if (fileName.equals(relPath)){ + System.out.println("Do you want to overwrite the original picture? (type 'yes' to overwrite original file or no to save with different file name)"); + fileName = in.next(); + + if(fileName.equals("yes")|| fileName.equals("Yes")|| fileName.equals("y") || fileName.equals("Y")) { + String absFileName = dir + File.separator + fileNameHolder; + processed.save(absFileName); + System.out.println("Image saved to " + absFileName); + invalidFilename = false; + in.close(); + System.exit(0); + } + + else if (fileName.equals("no")|| fileName.equals("No")|| fileName.equals("n") || fileName.equals("N")){ + System.out.println("Please enter a different name to save picture"); + fileName = in.next(); + if (fileName.equals(relPath)){ + System.out.println("Could not save picture please try again"); + invalidFilename = false; + + } else { + + String absFileName = dir + File.separator + fileNameHolder; + processed.save(absFileName); + System.out.println("Image saved to " + absFileName); + invalidFilename = false; + in.close(); + System.exit(0); + } + } + } + } while (!fileName.equals("Yes") || !fileName.equals("yes") || !fileName.equals("Y") || !fileName.equals("y") || !fileName.equals("No") || + !fileName.equals("no") || !fileName.equals("n") || !fileName.equals("N")); + + + + + } while (invalidFilename); + // close input scanner in.close(); + } - + + // TODO - refactor this method to accept an int parameter, and return an instance of the Filter interface - // TODO - refactor this method to thrown an exception if the int doesn't correspond to a filter - private static BlueFilter getFilter() { - + private static Filter getFilter(int x) { + + + + // TODO - refactor this method to thrown an exception if the int doesn't correspond to a filter + if(x < 0 || x > 3) { + throw new IllegalArgumentException(); + } + + // TODO - create some more filters, and add logic to return the appropriate one - return new BlueFilter(); + if(x == 1){ + return new BlueFilter(); + } + + else if (x == 2) { + return new InvertFilter(); + } + else if (x == 3) { + return new BrightnessFilter(); + } + + else return new BlueFilter(); } - } \ No newline at end of file diff --git a/java-track/assignments/javagram/Picture.java b/java-track/assignments/javagram/Picture.java index 82a39d9..ebece57 100644 --- a/java-track/assignments/javagram/Picture.java +++ b/java-track/assignments/javagram/Picture.java @@ -295,4 +295,8 @@ public static void main(String[] args) { pic.show(); } +public String getFilename() { + return filename; +} + } diff --git a/java-track/assignments/javagram/filters/BlueFilter.java b/java-track/assignments/javagram/filters/BlueFilter.java index c3acf8f..d039986 100644 --- a/java-track/assignments/javagram/filters/BlueFilter.java +++ b/java-track/assignments/javagram/filters/BlueFilter.java @@ -3,7 +3,7 @@ import javagram.Picture; import java.awt.Color; -public class BlueFilter { +public class BlueFilter implements Filter { public Picture process(Picture original) { diff --git a/java-track/assignments/javagram/filters/BrightnessFilter.java b/java-track/assignments/javagram/filters/BrightnessFilter.java new file mode 100644 index 0000000..d8fb9d4 --- /dev/null +++ b/java-track/assignments/javagram/filters/BrightnessFilter.java @@ -0,0 +1,44 @@ +package javagram.filters; + +import java.awt.Color; + +import javagram.Picture; + +public class BrightnessFilter implements Filter { + + public Picture process(Picture original) { + + Picture processed = new Picture(original.width(), original.height()); + + //get each pixel one by one + for (int i = 0; i < original.width(); i++) { + for (int j = 0; j < original.height(); j++) { + + Color c = original.get(i, j); + + //get color components from each pixel + int r = c.getRed(); + int g = c.getGreen(); + int b = c.getBlue(); + + + + + if(r < 230 && r > 10){ + r = r + 25; + } + if(g < 230 && g > 10 ){ + g = g + 25; + } + if(b < 230 && b > 10){ + b = b + 25; + } + + processed.set(i, j, new Color(r, g, b)); + + } + } + + return processed; + } +} diff --git a/java-track/assignments/javagram/filters/Filter.java b/java-track/assignments/javagram/filters/Filter.java new file mode 100644 index 0000000..9a2c2dd --- /dev/null +++ b/java-track/assignments/javagram/filters/Filter.java @@ -0,0 +1,10 @@ +package javagram.filters; + +import javagram.Picture; + +public interface Filter { + + public Picture process(Picture picture); + +} + diff --git a/java-track/assignments/javagram/filters/InvertFilter.java b/java-track/assignments/javagram/filters/InvertFilter.java new file mode 100644 index 0000000..303bc4a --- /dev/null +++ b/java-track/assignments/javagram/filters/InvertFilter.java @@ -0,0 +1,36 @@ +package javagram.filters; + +import java.awt.Color; + +import javagram.Picture; + +public class InvertFilter implements Filter { + + public Picture process(Picture original) { + + Picture processed = new Picture(original.width(), original.height()); + + //get each pixel one by one + for (int i = 0; i < original.width(); i++) { + for (int j = 0; j < original.height(); j++) { + + Color c = original.get(i, j); + + //get color components from each pixel + int r = c.getRed(); + int g = c.getGreen(); + int b = c.getBlue(); + + + r = 255 - r; + g = 255 - g; + b = 255 - b; + processed.set(i, j, new Color(r, g, b)); + + } + } + + return processed; + } + +} diff --git a/java-track/images/mentorcenter.jpg b/java-track/images/mentorcenter.jpg index 9b56291..cb46c79 100644 Binary files a/java-track/images/mentorcenter.jpg and b/java-track/images/mentorcenter.jpg differ diff --git a/java-track/mentorcenter.jpg b/java-track/mentorcenter.jpg new file mode 100644 index 0000000..cb46c79 Binary files /dev/null and b/java-track/mentorcenter.jpg differ