This program simulates an alchemist mixing together different elements to see wh
ID: 3750331 • Letter: T
Question
This program simulates an alchemist mixing together different elements to see what happens. You have three different elements to mix together: earth, fire, and water.
Depending on the elements they provide, print out one of three responses:
• If they entered the same element twice:
o Print out That just makes more <ELEMENTS > than you need! (where is the element they entered)
• If they entered two known elements (earth, fire, or water):
o Print out <ELEMENT1 >and<ELEMENT2 > combined make <MIXED >
(where is the secondary element created)
Fire and water creates steam
Fire and earth creates lava
Water and earth creates mud
• If they enter anything else:
o Print out <ELEMENT1 >and <ELEMENT2>didn’t combine.
Your program only needs to work with lowercase letters; you do not need to worry about handling capitalization.
Explanation / Answer
Algorithm for the above question will be,
step 1:declare variable a, b & c
step 2: enter the three different elements and store in a , b and c.
step 3: if(a==b)||(b==c)||(c==a){ That just makes more elements than you need!
}
step 4: switch(x+y) {
case a + b:{print out Fire and water creates steam};
case a + c: {print out Fire and earth creates lava};
case b + c : {print out Water and earth creates mud};
defualt: {print out b and a doesn't combine};
}
The above algorithm is written as follows;
import.java.util.*;
class verify
char uppercase(){
if(a.uppercase){
system.out.println("entered element is in uppercase" +a );
}
if(b.uppercase){
system.out.println("entered element is in uppercase" +b );
}
if(c.uppercase){
system.out.println("entered element is in uppercase" +c );
}
exit();
}
string mixing(string x, string y, string z){
switch(q + w){
case a + b:{print out Fire and water creates steam};
case a + c: {print out Fire and earth creates lava};
case b + c : {print out Water and earth creates mud};
default: {print out b and a doesn't combine};
}
}
public static void main(String[] args){
string a, b, c;
System.out.println("Enter the element in lowercase");
system.out.println("Enter the element a:");
a=next();
system.out.println("Enter the element b:");
b=next();
system.out.println("Enter the element c:");
c=next();
char uppercase();
string mixing();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.