Program 3: Zodiac ID: ID003 Make sure you include this ID as a System.out.printl
ID: 3733186 • Letter: P
Question
Program 3: Zodiac
ID: ID003
Make sure you include this ID as a System.out.println() message at the beginning of your program. This helps us with grading, and is required.
Before starting this project, make sure to completely read through the instructions first, draw the flowchart, and then write the pseudocode in the header comments. Both will be graded, and flowcharts will be taken up at the beginning of our next Lab.
Write a program with the class name “ZodiacSigns”. The program should have the user input their birth month and birth day. Then, display their Zodiac Sign (Aries, Taurus, etc.), as well as one additional fact about that particular sign.
For the second part, have a randomly generated month and day. Display the Zodiac Sign of this random date.
Submit these programs to the Post Lab Program Submission area under the Week 4 Module. Upload just the JAVA class file. Make sure you have proper documentation (header comments and inline comments). Both flowcharts will be taken up at the beginning of next Lab.
Below is the input and the output we expect from your program. This is to help you know if you are on the right track.
Example input :
5
10
Example output:
ID003
Enter the month you were born: [integer]
Enter the day you were born: [integer]
Your Zodiac Sign is Taurus! Taurus’s are well known to break many of the ethical codes of dentistry. Watch out!
Generating random month and day: 6 2 [random output]
Your Zodiac Sign is Gemini! Gemini’s have a crippling fear of snails that move too fast
Explanation / Answer
Please find my implementation of First Part:
ZodiacSign.java
import java.util.Random;//random number generator package
import java.util.Scanner;//keybard inputting package
public class ZodiacSign {//main class
public static void main(String[] args) {//main method
Scanner sc = new Scanner(System.in);
System.out.print("Enter your birth month ");
int month = sc.nextInt();//keyboard inputting
System.out.print("Enter your birth date ");
int day = sc.nextInt();//keyboard inputting
Zodiac(month, day);//calling method
Random r = new Random();
month = r.nextInt((12 - 1) + 1);//max month=12 min month=1 ;; r.nexInt(max-min)+min
day = r.nextInt((31 - 1) + 1);
System.out.print("Zodiac sign of random date ");
Zodiac(month, day);//calling method
}
public static void Zodiac(int month, int day) {//static method
if ((month == 12 && day >= 22 && day <= 31) || (month == 1 && day >= 1 && day <= 19)) {
System.out.println("Capricorn");
} else if ((month == 1 && day >= 20 && day <= 31) || (month == 2 && day >= 1 && day <= 17)) {
System.out.println("Aquarius");
} else if ((month == 2 && day >= 18 && day <= 29) || (month == 3 && day >= 1 && day <= 19)) {
System.out.println("Pisces");
} else if ((month == 3 && day >= 20 && day <= 31) || (month == 4 && day >= 1 && day <= 19)) {
System.out.println("Aries");
} else if ((month == 4 && day >= 20 && day <= 30) || (month == 5 && day >= 1 && day <= 20)) {
System.out.println("Taurus");
} else if ((month == 5 && day >= 21 && day <= 31) || (month == 6 && day >= 1 && day <= 20)) {
System.out.println("Gemini");
} else if ((month == 6 && day >= 21 && day <= 30) || (month == 7 && day >= 1 && day <= 22)) {
System.out.println("Cancer");
} else if ((month == 7 && day >= 23 && day <= 31) || (month == 8 && day >= 1 && day <= 22)) {
System.out.println("Leo");
} else if ((month == 8 && day >= 23 && day <= 31) || (month == 9 && day >= 1 && day <= 22)) {
System.out.println("Virgo");
} else if ((month == 9 && day >= 23 && day <= 30) || (month == 10 && day >= 1 && day <= 22)) {
System.out.println("Libra");
} else if ((month == 10 && day >= 23 && day <= 31) || (month == 11 && day >= 1 && day <= 21)) {
System.out.println("Scorpio");
} else if ((month == 11 && day >= 22 && day <= 30) || (month == 12 && day >= 1 && day <= 21)) {
System.out.println("Sagittarius");
} else {
System.out.println("Illegal date");
}
}
}
output
Enter your birth month 4
Enter your birth date 15
Aries
Zodiac sign of random date Illegal date
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.