I\'m in java one and I need help solving this program. please fallow the instruc
ID: 3670595 • Letter: I
Question
I'm in java one and I need help solving this program. please fallow the instructions and help me to write this program. I will appreciate your help thank you.
Write a program that will add the digits of a person’s birth date to obtain a single digit to generate a numerology report.
First: Get a Date
Numerology has been used since ancient times to shed light on relationships, health and global events. Each element in a birth date is believed to possess a special numerical significance. We are going to develop our own rudimentary numerology prediction program. The first thing to do is ask the user to enter a birth date to process.
You will need to indicate to your user that they need to enter the month, day and year in that order separated by spaces and forward slashes, which look like this: /. An example would be 12 / 25 / 2112. The spaces must be present between the numeric and character input.
Second: Validate the Date
The important and time-consuming portion of this program is validating your input from the user. This means that you need to check to make sure the month is between 1 and 12, the day is appropriate for the month, and the year is between 1880 and 2280, inclusive.
By “the day is appropriate for the month and year”, this means that if a date of January 32nd is entered or a date of June 0th is entered, you should recognize and report that. This also means that you should check to see that if the year is a leap year, you should allow February 29th and if it's not a leap year, you should disallow February 29th. See the "Solution Suggestions" for a website that discusses leap years.
Allow the user to input the entire date before you validate it.
You should continuously re-prompt the user for a date until a valid date is entered. If one part of the date fails (month, day or year), re-prompt for the entire date again. Do not simply re-prompt for the offending part of the date. Output appropriate error messages for the incorrect dates. See the example runs for sample error messages.
Third: Crunch the Date
Then, you need to calculate a single digit from the birth date. For example if your birth date is 3/19/1955 you add 3+1+9+1+9+5+5 to get 33. You would then break this apart and add 3+3 to get 6.
You will need to be careful because it is possible to have to “fold” the number more than just once, as in the above example. For example, if the birth date was 7/5/1942, you would add up the individual digits 7+5+1+9+4+2 to get 28, then you would need to add 2 + 8 to get 10. This is still a two-digit number, and needs to be added again – 1 + 0 – to get a single-digit result of 1.
You can simplify the process by combining the month day and year into a single value first and then breaking down and adding that result. You should never have to crunch a number more than 3 times and will usually only need to add the digits once or twice.
For example: If month = 2, day = 15 and year = 1999 – combine the values to a single number: 19990215 Use the following logic to combine the values: value = year * 10000 + month * 100 + day
Output Specifications
Once you have obtained the single digit you are going to print out a numerology forecast for that number. If your number was 1, you would print out the numerology report for the number 1. Use the following one-line format for your output:
=1= Neither give cherries to pigs nor advice to a fool.
For your output, have the text =X= start the line, where X is the number of the numerology report surrounded immediately by equals
signs and followed by a space. Then, issue your numerology forecast on the remainder of the line.
Use your own numerology forecasts for each number. Have fun, be creative, don't be mean-spirited and please keep the content to a PG-13 format (i.e., no foul language and nothing that is outright offensive; remember not to offend your instructor).
solutions suggestions
It might actually be easier to work backwards solving this program, like this, checking each step as you complete it:
o The first thing you could do is write a switch statement that handles 9 possible numerology forecasts. Test this switch statement by using exact values for the switch's variable to make sure it works and outputs all 9 numerology forecasts before moving on.
o Then add the code to take a date and crunch it down to a single digit. This code should come before your switch statement. For simply testing this code, don’t worry about validating the date or input format yet; declare three variables (for example: month, date, year), read in the date to process from the user and then feed that result into the switch statement you've already developed and that you know works from the previous step.
o Finally, add code to validate the date that you read from the keyboard before crunching it. Validation will need to include tests for the month, day and year as well as for using forward slashes between those pieces of information.
Information about leap years: http://j.mp/whatisaleapyear
Goals
Use most everything we've learned through chapter 5.
Use only the data type int for numbers in this program; there’s no need to calculate floating point numbers.
Solve a moderately complex Java program using the techniques you’ve learned through chapter 5.
Points to Think About
Validate to make sure that the year is between 1880 and 2280, inclusive.
Validate to make sure that the month is between 1 and 12, inclusive.
Validate to make sure that the day is appropriate for the month (at least >=1 and <= 28, 29, 30 or 31 depending on which
month and year it is).
Validate that the user uses forward slashes (/) between the month, day and year.
You may only use material through chapter 5 of the book.
For a valid date, make sure to follow the output specifications from the other side of this sheet to print your numerology report. Programs that do not follow the output specifications will not receive full credit.
Make sure that your program continuously prompts the user for a date until a valid date is entered.
Make sure to allow the user to enter the entire date before validating it. In other words, don't just validate the month, then
validate the day and then validate the year. Allow the entire date to be entered, then validate it and output an appropriate error message, repeating input if necessary.
Testing Your Program
A good way to start testing your program is to enter all the bad dates you can think of (i.e., 1/0/2007, 1/32/2007, 2/-1/2007, 1/1/2281, etc).
Then, starting with 9/1/2007, test your program with all dates through 9/10/2007 to make sure you output 9 different numerology reports (9/1/2007 and 9/10/2007 should both output the :1: report).
Sample Program Run (user input is underlined)
Enter the birth date (mm/dd/yyyy): 7 / 23 / 1982
Welcome to the numerology report for 7/23/1982 :
=5= Your sweetheart may be too beautiful for words, but not for arguments.
Sample Program Run (user input is underlined)
Enter the birth date (mm/dd/yyyy): 7 / 27 / 1981
Welcome to the numerology report for 7/27/1981 :
=8= You are almost there
Sample Program Run (user input is underlined)
Enter the birth date (mm/dd/yyyy): 0 / 10 / 2000
Bad month: 0
Enter the birth date (mm/dd/yyyy): 13 / 10 / 2000
Bad month: 13
Enter the birth date (mm/dd/yyyy): 2 – 29 - 2007
Use forward slashes between mm/dd/yyyy!
Enter the birth date (mm/dd/yyyy): 2 / 29 - 2007
Use forward slashes between mm/dd/yyyy!
Enter the birth date (mm/dd/yyyy): 2 / 29 / 2007
Bad day for 2/2007 : 29
Enter the birth date (mm/dd/yyyy): 2 / 28 / 2007
Welcome to the numerology report for 2/28/2007 :
=3= Your dearest dream is coming true.
Explanation / Answer
import java.util.Scanner;
public class HelloWorld
{
public static void main( String args[])
{
Scanner input = new Scanner(System.in);
int sum, day, month, year, daytot, yeartot, monthtot, sumtot, dayv = 1, monthv =1, yearv = 1, chv = 1, leapv1, leapv2, leapv3;
boolean leapyear = false;
char ch1, ch2;
// Valitation of date
do {
System.out.println("Enter the birth date(mm/dd/yyyy): ");
month = input.nextInt();
ch1 = input.next().charAt(0);
day = input.nextInt();
ch2 = input.next().charAt(0);
year = input.nextInt();
leapv1 = year;leapv2 = year; leapv3 =year;
leapv1 %= 4;
leapv2 %= 100;
leapv3 %= 400;
if( leapv1 == 0 && leapv2 == 0 && leapv3 == 0){
leapyear = true;}
//Validate year
if (year >1879 && year<2280){
yearv = 2;}
//end Validate year
//Validate month
if (month > 0 && month < 13){
monthv = 2;}
//end Validate month
//Validation of day
switch (month){
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
{if (day > 0 && day < 32){
dayv = 2;
}
}
case 4: case 6: case 9: case 11:
{ if (day > 0 && day < 31){
dayv = 2;
}
}
case 2:
{
if( leapyear == true){
if( day > 0 && day < 30){
dayv = 2;}
}
if (leapyear == false){
if( day > 0 && day < 29){
dayv = 2;}
}
}
}
if(ch1 != '/' || ch2 != '/'){
System.out.print("Use forward slashes between mm/dd/yyyy! ");
chv = 1;
}
else{
chv = 2;
if (dayv == 1){
System.out.printf("Bad day for %d/%d: %d ", month, year, day);}
if (monthv == 1)
System.out.printf("Bad month: %d ", month);
if (yearv == 1 )
System.out.printf("Bad year: %d ", year);
}} while( dayv == 1 || monthv == 1 || yearv == 1 || chv ==1 );
//end Validation of day
// end Validation of date
//add each integer in year,month,day and store them in totals
yeartot = (year/1000);
year %= 1000;
yeartot += (year/100);
year %= 100;
yeartot += (year/10);
year %= 10;
yeartot += year;
monthtot = (month/10);
monthtot += (month%10);
daytot= (day/10);
daytot += (day%10);
sum = (yeartot+daytot+monthtot);
sumtot = (sum/10);
sumtot +=(sum%10);
System.out.printf("Welcome to the numerology report for %d/%d/%d :%n", month, day, year);
switch(sumtot){
case 1:
System.out.println("=1= Do not dwell in the past, do not dream of the future, concentrate the mind on the present ");break;
case 2:
System.out.println("=2= Health is the greatest gift, contentment the greatest wealth, faithfulness the best relationship ");break;
case 3:
System.out.println("=3= An insincere and evil friend is more to be feared than a wild beast ");break;
case 4:
System.out.println("=4= The way is not in the sky. The way is in the heart ");break;
case 5:
System.out.println("=5= Holdling on to anger is like grasping a hot coal with the intent of throwing it at someone else; you are the one wh gets burned ");break;
case 6:
System.out.println("=6= Three things cannot be long hidden: the sun, the moon, and the truth ");break;
case 7:
System.out.println("=7= The tongue like a sharp knife... Kills without drawing blood. ");break;
case 8:
System.out.println("=8= The mind is everything. What you think you become. ");break;
case 9:
System.out.println("=9= Better than a thousand hollow words, is one word that brings peace ");break;
}
}}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.