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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!