Skip to content

Commit 3191ffc

Browse files
authored
Add files via upload
1 parent faede65 commit 3191ffc

File tree

3 files changed

+464
-0
lines changed

3 files changed

+464
-0
lines changed

hw02/Main.java

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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 still be
25+
* 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 message
31+
* on line 74
32+
*/
33+
if (nameOfFile.endsWith(".ppm")) {
34+
System.out.println("You chose " + nameOfFile);
35+
36+
/**
37+
* The chosen file gets passed to the PPMImage object and is directed through a
38+
* relative path
39+
*/
40+
PPMImage ppm = new PPMImage("src/ppm_images/" + nameOfFile);
41+
42+
System.out.println();
43+
System.out.println("Would you like to change it to sepia, grayscale, or negative?");
44+
45+
/**
46+
* String to hold the user input
47+
*/
48+
String effect = scan.nextLine();
49+
50+
/**
51+
* Switch case to to select one effect to be executed. NOTE: user input is
52+
* converted to lower case to ensure the effect chosen still gets applied
53+
* despite the case type (upper, lower, or both)
54+
*/
55+
switch (effect) {
56+
57+
case "sepia":
58+
effect.toLowerCase();
59+
ppm.sepia();
60+
break;
61+
62+
case "grayscale":
63+
effect.toLowerCase();
64+
ppm.grayscale();
65+
break;
66+
67+
case "negative":
68+
effect.toLowerCase();
69+
ppm.negative();
70+
break;
71+
72+
default:
73+
System.out.println("Something went wrong, please check your spelling and try again!");
74+
System.exit(0);
75+
}
76+
77+
System.out.print("Enter your new file name: ");
78+
79+
/**
80+
* String to hold the new file name inputed by the user
81+
*/
82+
String newFile = scan.nextLine();
83+
84+
scan.close();
85+
86+
/**
87+
* Adds the extension type in case the user failed to do so. This also helps to
88+
* ignore other file extension types the user may have used
89+
*/
90+
if (!newFile.endsWith(".ppm")) {
91+
newFile += ".ppm";
92+
}
93+
94+
ppm.writeImage(newFile);
95+
96+
System.out.println();
97+
System.out.println("Your new file " + newFile + " has been created");
98+
99+
} else {
100+
System.out.println("The image you have entered could not be found."
101+
+ "\nIncorrect file name or missing '.ppm' extension.");
102+
}
103+
104+
/**
105+
* exits the program
106+
*/
107+
System.exit(0);
108+
109+
}
110+
111+
}

0 commit comments

Comments
 (0)