hi.. im an amateur in java and im having problems in switch statements..
i would appreciate if you would help me solve this problem..
Problem: Write a java program that will let the user input 2 colors and display the result color..
This is what i come up with.. and the error is "incompatible type"
import java.io.*;
public class Projedential {
public static void main(String[] args)throws IOException {
BufferedReader xan=new BufferedReader(new InputStreamReader(System.in));
String white,black,red,blue,green,cyan,magnta,yellow,pink,brown,orange,violet="";
System.out.println("*****************************************");
System.out.println("Enter Color 1 :");
String c1=xan.readLine();
System.out.println("Enter Color 2 :");
String c2=xan.readLine();
//if switch WHITE
if (c1.equals("white")) {
switch (c2)
{
case "black":
System.out.println("Color mixture result : GRAY" );
break;
case "red":
System.out.println("Color mixture result : PINK" );
break;
case "blue":
System.out.println("Color mixture result : LIGHT BLUE" );
break;
case "green":
System.out.println("Color mixture result : LIGHT GREEN" );
break;
case "yellow":
System.out.println("Color mixture result : LIGHT YELLOW" );
break;
case "pink":
System.out.println("Color mixture result : LIGHT PINK" );
break;
case "brown":
System.out.println("Color mixture result : LIGHT BROWN" );
break;
case "orange":
System.out.println("Color mixture result : LIGHT ORANGE" );
break;
case "violet":
System.out.println("Color mixture result : LIGHT VIOLET" );
break;
default:
System.out.println("No possible Mixture for " +c1+ " and " +c2);
break;
}
}
//if switch black
else if(c1.equals("black"))
{
switch (c2)
{
case "white":
System.out.println("Color mixture result : GRAY" );
break;
case "red":
System.out.println("Color mixture result : DARK RED" );
break;
case "blue":
System.out.println("Color mixture result : DARK BLUE" );
break;
case "green":
System.out.println("Color mixture result : DARK GREEN" );
break;
case "yellow":
System.out.println("Color mixture result : DARK YELLOW" );
break;
case "pink":
System.out.println("Color mixture result : DARK PINK" );
break;
case "brown":
System.out.println("Color mixture result : DARK BROWN" );
break;
case "orange":
System.out.println("Color mixture result : DARK ORANGE" );
break;
case "violet":
System.out.println("Color mixture result : DARK VIOLET" );
break;
default:
System.out.println("No possible Mixture for " +c1 +" and "+ c2);
break;
}
}
//if switch red
else if (c1.equals("red")) {
switch (c2)
{
case "blue":
System.out.println("Color mixture result : MAGENTA (Additive)/ VIOLET(Subtractive)" );
break;
case "green":
System.out.println("Color mixture result : YELLOW" );
break;
case "yellow":
System.out.println("Color mixture result : ORANGE" );
break;
case "magenta":
System.out.println("Color mixture result : ROSE" );
break;
case "orange":
System.out.println("Color mixture result : VERMILION" );
break;
case "violet":
System.out.println("Color mixture result : VIOLET RED" );
break;
case "black":
System.out.println("Color mixture result : DARK RED" );
break;
case "white":
System.out.println("Color mixture result : LIGHT RED" );
break;
default:
System.out.println("No possible Mixture for " +c1+ " and " +c2);
break;
}}
//if switch BLUE
else if (c1.equals("blue")) {
switch (c2)
{
case "red":
System.out.println("Color mixture result : MAGENTA (Additive)/ VIOLET(Subtractive)" );
break;
case "green":
System.out.println("Color mixture result : CYAN" );
break;
case "yellow":
System.out.println("Color mixture result : GREEN" );
break;
case "magenta":
System.out.println("Color mixture result : VIOLET" );
break;
case "orange":
System.out.println("Color mixture result : BROWN" );
break;
case "cyan":
System.out.println("Color mixture result : AZURE" );
break;
case "violet":
System.out.println("Color mixture result : INDIGO" );
break;
case "black":
System.out.println("Color mixture result : DARK BLUE" );
break;
case "white":
System.out.println("Color mixture result : LIGHT RED" );
break;
default:
System.out.println("No possible Mixture for " +c1+ " and " +c2);
break;
}}
//if switch GREEN
else if (c1.equals("green")) {
switch (c2)
{
case "red":
System.out.println("Color mixture result : YELLOW" );
break;
case "blue":
System.out.println("Color mixture result : CYAN" );
break;
case "yellow":
System.out.println("Color mixture result : CHARTREUSE" );
break;
case "cyan":
System.out.println("Color mixture result : SPRING GREEN" );
break;
case "black":
System.out.println("Color mixture result : DARK GREEN" );
break;
case "white":
System.out.println("Color mixture result : LIGHT GREEN" );
break;
case "black":
System.out.println("Color mixture result : DARK GREEN" );
break;
default:
System.out.println("No possible Mixture for " +c1+ " and " +c2);
break;
}}
//if switch YELLOW
else if (c1.equals("yellow")) {
switch (c2)
{
case "red":
System.out.println("Color mixture result : ORANGE" );
break;
case "blue":
System.out.println("Color mixture result : GREEN" );
break;
case "black":
System.out.println("Color mixture result : DARK YELLOW" );
break;
case "white":
System.out.println("Color mixture result : LIGHT YELLOW" );
break;
case "green":
System.out.println("Color mixture result : CHARTREUSE" );
break;
case "orange":
System.out.println("Color mixture result : AMBER" );
break;
case "cyan":
System.out.println("Color mixture result : GREEN" );
break;
default:
System.out.println("No possible Mixture for " +c1+ " and " +c2);
break;
}}
//if switch CYAN
else if (c1.equals("cyan")) {
switch (c2)
{
case "magenta":
System.out.println("Color mixture result : BLUE" );
break;
case "blue":
System.out.println("Color mixture result : AZURE" );
break;
case "yellow":
System.out.println("Color mixture result : GREEN" );
break;
case "green":
System.out.println("Color mixture result : SPRING GREEN" );
break;
default:
System.out.println("No possible Mixture for " +c1+ " and " +c2);
break;
}}
//if switch MAGENTA
else if (c1.equals("magenta")) {
switch (c2)
{
case "cyan":
System.out.println("Color mixture result : BLUE" );
break;
case "yellow":
System.out.println("Color mixture result : RED" );
break;
case "blue":
System.out.println("Color mixture result : VIOLET" );
break;
case "red":
System.out.println("Color mixture result : ROSE" );
break;
default:
System.out.println("No possible Mixture for " +c1+ " and " +c2);
break;
}}
//if switch PINK
else if (c1.equals("pink")) {
switch (c2)
{
case "white":
System.out.println("Color mixture result : LIGHT PINK" );
break;
case "black":
System.out.println("Color mixture result : DARK PINK" );
break;
default:
System.out.println("No possible Mixture for " +c1+ " and " +c2);
break;
}}
//if switch BROWN
else if (c1.equals("brown")) {
switch (c2)
{
case "white":
System.out.println("Color mixture result : LIGHT BROWN" );
break;
case "black":
System.out.println("Color mixture result : DARK BROWN" );
break;
default:
System.out.println("No possible Mixture for " +c1+ " and " +c2);
break;
}}
//if switch ORANGE
else if (c1.equals("orange")) {
switch (c2)
{
case "blue":
System.out.println("Color mixture result : BROWN" );
break;
case "yellow":
System.out.println("Color mixture result : AMBER" );
break;
case "red":
System.out.println("Color mixture result : VERMILION" );
break;
case "white":
System.out.println("Color mixture result : LIGHT ORANGE" );
break;
case "black":
System.out.println("Color mixture result : DARK ORANGE" );
break;
default:
System.out.println("No possible Mixture for " +c1+ " and " +c2);
break;
}}
//if switch VIOLET
else if (c1.equals("violet")) {
switch (c2)
{
case "red":
System.out.println("Color mixture result : VIOLET RED" );
break;
case "blue":
System.out.println("Color mixture result : INDIGO" );
break;
case "white":
System.out.println("Color mixture result : LIGHT VIOLET" );
break;
case "black":
System.out.println("Color mixture result : DARK VIOLET" );
break;
default:
System.out.println("No possible Mixture for " +c1+ " and " +c2);
break;
}}
else{
System.out.println("The color you have entered has no possible mixture");
System.out.println("Please Start Again");
}
} }
thanks