Question
How do I fix this code so it can work? import javax.swing.JOptionPane; public class Year { public static void main(String[] args) { String str =
How do I fix this code so it can work?
import javax.swing.JOptionPane;
public class Year { public static void main(String[] args) { String str = JOptionPane.showInputDialog("What year were you born?");
int yr = Integer.parseInt(str);
String zodiac = ""; switch (yr%12) { case 0: zodiac = "Monkey"; break; case 1: zodiac = "Rooster"; break; case 2: zodiac = "Dog"; break; case 3: zodiac = "Pig"; break; case 4: zodiac = "Rat"; break; case 5: zodiac = "Ox"; break; case 6: zodiac = "Tiger"; break; case 7: zodiac = "Rabbit"; break; case 8: zodiac = "Dragon"; break; case 9: zodiac = "Snake"; break; case 10: zodiac = "Horse"; break; case 11: zodiac = "Goat"; break; } JOptionPane.showMessageDialog(null, "It is a " + zodiac + " year!", "Chinese Zodiac", JOptionPane.PLAIN_MESSAGE); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started