Skip to content

Commit 5299aac

Browse files
authored
Add files via upload
1 parent 5f3eccf commit 5299aac

File tree

8 files changed

+434
-0
lines changed

8 files changed

+434
-0
lines changed

homework02/bin/hw02/Main.class

2.27 KB
Binary file not shown.

homework02/bin/hw02/PPMImage.class

4.01 KB
Binary file not shown.
110 Bytes
Binary file not shown.

homework02/bin/module-info.class

149 Bytes
Binary file not shown.

homework02/src/hw02/Main.java

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package hw02;
2+
3+
import java.util.Scanner;
4+
5+
/**
6+
* Creates a nice console menu which allows the user to do the following: Choose
7+
* an image to manipulate, change the image to sepia, greyscale, or negative,
8+
* and save the new image with a user chosen file name
9+
*
10+
* @author angy xajil; CIN: 400304005; CS 2013-05
11+
*/
12+
13+
public class Main {
14+
15+
public static void main(String[] args) {
16+
17+
System.out.println("Which image would you like to manipulate?");
18+
19+
Scanner scan = new Scanner(System.in);
20+
21+
String nameOfFile = scan.nextLine();
22+
23+
/**
24+
* Chosen image input is converted to lower case to ensure file can
25+
* still be used despite the case type (upper, lower, or both)
26+
*/
27+
nameOfFile.toLowerCase();
28+
29+
/**
30+
* Validates the given file is of type .ppm. If not, it prints an error
31+
* message on line 74
32+
*/
33+
if (nameOfFile.endsWith(".ppm")) {
34+
35+
System.out.println("You chose " + nameOfFile);
36+
37+
/**
38+
* The chosen file gets passed to the PPMImage object and is directed
39+
* through a relative path
40+
*/
41+
PPMImage ppm = new PPMImage("src/ppm_images/" + nameOfFile);
42+
43+
System.out.println();
44+
System.out.println("Would you like to change it to sepia, grayscale,"
45+
+ " or negative?");
46+
47+
/**
48+
* String to hold the user input
49+
*/
50+
String effect = scan.nextLine();
51+
52+
/**
53+
* Switch case to to select one effect to be executed. NOTE: user
54+
* input is converted to lower case to ensure the effect chosen
55+
* still gets applied despite the case type (upper, lower, or both)
56+
*/
57+
switch (effect) {
58+
59+
case "sepia":
60+
effect.toLowerCase();
61+
ppm.sepia();
62+
break;
63+
64+
case "grayscale":
65+
effect.toLowerCase();
66+
ppm.grayscale();
67+
break;
68+
69+
case "negative":
70+
effect.toLowerCase();
71+
ppm.negative();
72+
break;
73+
74+
case "none":
75+
break;
76+
77+
default:
78+
System.out.println("Something went wrong, please check your"
79+
+ " spelling and try again!");
80+
System.exit(0);
81+
}
82+
83+
System.out.print("Enter your new file name: ");
84+
85+
/**
86+
* String to hold the new file name inputed by the user
87+
*/
88+
String newFile = scan.nextLine();
89+
90+
scan.close();
91+
92+
/**
93+
* Adds the extension type in case the user failed to do so. This also
94+
* helps to ignore other file extension types the user may have used
95+
*/
96+
if (!newFile.endsWith(".ppm")) {
97+
newFile += ".ppm";
98+
}
99+
100+
ppm.writeImage(newFile);
101+
102+
System.out.println();
103+
System.out.println("Your new file " + newFile + " has been created");
104+
105+
} else {
106+
System.out.println("The image you have entered could not be found."
107+
+ "\nMissing '.ppm' extension.");
108+
}
109+
110+
/**
111+
* exits the program
112+
*/
113+
System.exit(0);
114+
115+
}
116+
117+
}

0 commit comments

Comments
 (0)