Alrighty, so I'm working on a small assignment and I'm a bit stuck.
The assignment:
Code:
Write a program that computes the day of a week given Julian day.
People who deal with historical dates use a number called the Julian day to calculate the number of days between two events. The Julian day is the number of days that have elapsed since January 1, 4713 B.C. For example, the Julian day for October 16, 1956, is 2435763.
There are formulas for computing the Julian day from a given date, and vice versa. One very simple formula computes the day of the week from a given Julian day:
Day of the week = (Julian day + 1) % 7
Where % is the Java modulus operator. This formula gives a result of 0 for Sunday, 1 for Monday, and so on, up to 6 for Saturday. For Julian day 2435763, the result is 2 (Tuesday).
You have to write a java application (program) that requests and inputs a Julian day, computes the day of the week using the formula, and then displays the name of the day that corresponds to that number. Your output might look like this:
Enter a Julian day number:
2451545
Julian day number 2451545 is Saturday.
What I have so far:
Code:
import java.util.Scanner;
public class Julian
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int Julian;
System.out.print("Enter Julian day: ");
Julian = keyboard.nextInt();
double dayofweek = (String) ((Julian + 1) % 7);
dayofweek = dayofweek.replace("0", "Sunday");
dayofweek = dayofweek.replace("1", "Monday");
dayofweek = dayofweek.replace("2", "Tuesday");
dayofweek = dayofweek.replace("3", "Wednesday");
dayofweek = dayofweek.replace("4", "Thursday");
dayofweek = dayofweek.replace("5", "Friday");
dayofweek = dayofweek.replace("6", "Saturday");
System.out.println("The Julian day number " + Julian + "is " + dayofweek);
}
} I'm trying to make my program change the value returned after the equation "(Julian + 1) % 7)" to a day of the week. The only thing is, I've only used the replace method with strings. any hints?