-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColor.java
More file actions
47 lines (41 loc) · 1.05 KB
/
Copy pathColor.java
File metadata and controls
47 lines (41 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* Color class
* Author: Shobhin Basu
* Email: sbasu25@wisc.edu
* CS Account: shobhin
* Description: This class provides methods to manipulate colors.
*/
public class Color{
private String color;
//Constructor
public Color(String iniColor){
if(isColorValid(iniColor)){
this.color = iniColor;
}
else{
System.out.println("Failed to initalize the color");
}
}
//Getter
public String getColor(){
return this.color;
}
/* The method for changing the color
* TODO: Revise the code so that it return true only if the input color is valid
* and different from the exisitng color before making the change
*/
public boolean changeColor(String newColor){
this.color = newColor;
return isColorValid(newColor);
}
public boolean isColorValid(String inputColor){
String [] validColor = {"red","orange","yellow","green", "cyan", "blue","purple"};
for(int i=0; i<validColor.length; i++){
if(inputColor.equals(validColor[i])){
return true;
}
}
//Failed to find a match, the color is invalid
return false;
}
}