Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello everyone! I seem to be having a lot of difficulty figuring out how to do t

ID: 3572630 • Letter: H

Question

Hello everyone! I seem to be having a lot of difficulty figuring out how to do this Java programming assignment. Would someone mind helping me out?

The assignment is as follows:

Write an astrology program on Java. The user will give their birthday as a month number (1 – 12) and then a day number (1 – 31). Your program will then output the person's astrological sign on one line, and then a horoscope for the user on the next. You may make up whatever horoscope you want for each different sign. Here are the sign dates: Sign Start Date End Date Aries March 21 April 19 Taurus April 20 May 20 Gemini May 21 June 21 Cancer June 22 July 22 Leo July 23 August 22 Virgo August 23 September 22 Libra September 23 October 22 Scorpio October 23 November 21 Sagittarius November 22 December 21 Capricorn December 22 January 19 Aquarius January 20 February 18 Pisces February 19 March 20

and here is an example execution:

Enter your birth month (1-12): 9

Enter your birth day (1-31): 26

You are a Libra!

Tony Stark will buy out your business.

You will need to use a long set of if and else if statements. You will either need to use compound expressions (combining expressions with the “and” and “or” operators) or have nested if statements (if statements inside of if statements). To get started, try to get one or two of the signs correct first, then try to make it work for the rest. You should verify that the month is between 1 and 12 and the day is between 1 and 31, but you don't need to check the day for specific months. You have been supplied with JUnit tests for each of the signs, as well as day/month inputs that are too large.

Thank you all so much in advance for the help!!

Explanation / Answer

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.GregorianCalendar;
import java.text.DateFormat;

public class astrology
{
public static void main(String[] args)
{
System.out.println(df.format(calendar.getTime()));
int day = 0;
int month = 0;
int year = 0;
while(true)
{
// for input the date
System.out.print("Enter the year for your Bith: ");
year = readInt();
while(true)
{
System.out.print("Enter the month for your Birth");
month = readInt();

}

while(true)
{
System.out.print("Enter the day of your Birth: ");
day = readInt();
  
}
}


calendar.set(year, month,day); // Set the calendar to the date entered
// Match the year for the sign start dates
for(int i = 0 ; i < signStartDates.length ; ++i)
signStartDates[i].set(GregorianCalendar.YEAR, year);

for(int i = 0 ; i < signStartDates.length ; ++i)
if(calendar.after(signStartDates[i]) && calendar.before(signStartDates[(i+1)%signStartDates.length])) {
System.out.println(df.format(calendar.getTime()) + " is in the sign of " + signs[i]);
break;
}

  
}


// Reads an integer from the keyboard
private static int readInt()
{
int value = 0;
while(true)
{
try
{
value = Integer.parseInt(in.readLine().trim());
return value;
}
catch(NumberFormatException e)
{
System.out.println("Invalid input. Try again.");
}
catch(IOException e)
{
System.out.println("Error reading for the keyboard." + e.getMessage());
}
}
}


private static boolean yes() {
String str = null;
while(true) {
try {
str = in.readLine().trim();
} catch(IOException e) {
System.out.println("Error reading for the keyboard." + e.getMessage());
}

if(str.equalsIgnoreCase("Y")) {
return true;
} else if(str.equalsIgnoreCase("N")) {
break;
} else {
System.out.print("Invalid input. Try again. Enter Y or N: ");
}
}
return false;
}

private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  
private static String[] signs = {"Aquarius", "Pisces", "Aries" , "Taurus",
"Gemini" , "Cancer", "Leo" , "Virgo",
"Libra" ,"Scorpio", "Sagittarius", "Capricorn" };
private static GregorianCalendar[] signStartDates = {
new GregorianCalendar(2002, 0, 20), // Aquarius start date
new GregorianCalendar(2002, 1, 19), // Pisces start date
new GregorianCalendar(2002, 2, 21), // Aries start date
new GregorianCalendar(2002, 3, 20), // Taurus start date
new GregorianCalendar(2002, 4, 21), // Gemini start date
new GregorianCalendar(2002, 5, 21), // Cancer start date
new GregorianCalendar(2002, 6, 23), // Leo start date
new GregorianCalendar(2002, 7, 23), // Virgo start date
new GregorianCalendar(2002, 8, 23), // Libra start date
new GregorianCalendar(2002, 9, 23), // Scorpio start date
new GregorianCalendar(2002, 10, 22), // Sagittarius start date
new GregorianCalendar(2002, 11, 22), // Capricorn start date
};
private static GregorianCalendar calendar = new GregorianCalendar();

  
private static final String[] MONTH_NAMES = {
"January" , "February", "March" , "April",
"May" , "June" , "July" , "August",
"September", "October" , "November", "December" };
private static DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote