ı need help in my homework zodiac sign program

it is my first year on university but ı took a third grade java class and ı am not even computer science student so ı learned some things for first project which is ı need ı already did a functional menu that can go main and sub menus without crashing and for the 2-3 days ı am working on a program that will take input from user and says what is the users age and after that our program will show our users zodiac sign ı thinked about some parts but ı completely lost that ı can not figure out how to procces users age with using java time method that it ı do know we will use user input for zodiac sign but ı do not know how to procces user age and giving exceptions to string inputs for example user inputs aa for date my program will not crash
any help appreciated ı am sorry for my bad english
41 Replies
JavaBot
JavaBot2mo ago
This post has been reserved for your question.
Hey @this is mistifi! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
ayylmao123xdd
ayylmao123xdd2mo ago
so you want the user to input age and depending on it the app is supposed to do something yes
this is mistifi
this is mistifiOP2mo ago
yes
ayylmao123xdd
ayylmao123xdd2mo ago
show your current code the part where you grab users age
this is mistifi
this is mistifiOP2mo ago
by the way thanks for helping
JavaBot
JavaBot2mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
ayylmao123xdd
ayylmao123xdd2mo ago
if (date < 1 || date > 31) {

System.out.println("Please Enter a valid day \n a day can't be smaller than 1 and bigger than 31");
System.out.println("Please enter your birth date format like that \n XX \n YY \n MMMM ");
continue;
}

if (month < 1 || month > 12) {

System.out.println("Please Enter a valid month \n a month can't be smaller than 1 and bigger than 12");
System.out.println("Please enter your birth date format like that \n XX \n YY \n MMMM ");
continue;
}

if (year > currentYear) {

System.out.println("Please Enter a valid year \n a year can't be bigger than current year");
System.out.println("Please enter your birth date format like that \n XX \n YY \n MMMM ");
continue;
}
if (date < 1 || date > 31) {

System.out.println("Please Enter a valid day \n a day can't be smaller than 1 and bigger than 31");
System.out.println("Please enter your birth date format like that \n XX \n YY \n MMMM ");
continue;
}

if (month < 1 || month > 12) {

System.out.println("Please Enter a valid month \n a month can't be smaller than 1 and bigger than 12");
System.out.println("Please enter your birth date format like that \n XX \n YY \n MMMM ");
continue;
}

if (year > currentYear) {

System.out.println("Please Enter a valid year \n a year can't be bigger than current year");
System.out.println("Please enter your birth date format like that \n XX \n YY \n MMMM ");
continue;
}
so im assuming below these checks you want to print the zodiac sign ok so hold on let me write it
this is mistifi
this is mistifiOP2mo ago
okay no problem ı have 2 more days to finish it after that ı will do reverse string program fortunately ı found a tutorial
ayylmao123xdd
ayylmao123xdd2mo ago
you can do something like this
Map<Integer, String> monthMessages = Map.ofEntries(
Map.entry(1, "a"),
Map.entry(2, "b"),
Map.entry(3, "c"),
Map.entry(4, "d"),
Map.entry(5, "e"),
Map.entry(6, "f"),
Map.entry(7, "g"),
Map.entry(8, "h"),
Map.entry(9, "i"),
Map.entry(10, "j"),
Map.entry(11, "k"),
Map.entry(12, "l")
);
Map<Integer, String> monthMessages = Map.ofEntries(
Map.entry(1, "a"),
Map.entry(2, "b"),
Map.entry(3, "c"),
Map.entry(4, "d"),
Map.entry(5, "e"),
Map.entry(6, "f"),
Map.entry(7, "g"),
Map.entry(8, "h"),
Map.entry(9, "i"),
Map.entry(10, "j"),
Map.entry(11, "k"),
Map.entry(12, "l")
);
and then oh yea replace the letters with ur zodiac sign thing and then if you wanna print it just do
System.out.println("Your zodiac sign is " + monthMessages.get(month));
System.out.println("Your zodiac sign is " + monthMessages.get(month));
i saw month is your variable so i put it there
this is mistifi
this is mistifiOP2mo ago
do ı need any other methods for program
ayylmao123xdd
ayylmao123xdd2mo ago
no try this
public static void main(String[] args){
//month messages here

LocalDate today = LocalDate.now();

int currentYear = today.getYear();

boolean isRunning = true;

int year;

boolean check = false;

int month;

int date;



while (isRunning) {

Scanner scanner = new Scanner(System.in);

System.out.println("Please enter your birth date format like that \n XX \n YY \n MMMM ");

date = scanner.nextInt();

month = scanner.nextInt();

year = scanner.nextInt();


if (date < 1 || date > 31) {

System.out.println("Please Enter a valid day \n a day can't be smaller than 1 and bigger than 31");
System.out.println("Please enter your birth date format like that \n XX \n YY \n MMMM ");
continue;
}

if (month < 1 || month > 12) {

System.out.println("Please Enter a valid month \n a month can't be smaller than 1 and bigger than 12");
System.out.println("Please enter your birth date format like that \n XX \n YY \n MMMM ");
continue;
}

if (year > currentYear) {

System.out.println("Please Enter a valid year \n a year can't be bigger than current year");
System.out.println("Please enter your birth date format like that \n XX \n YY \n MMMM ");
continue;
}

}

//zodiac sign print here
}
}
public static void main(String[] args){
//month messages here

LocalDate today = LocalDate.now();

int currentYear = today.getYear();

boolean isRunning = true;

int year;

boolean check = false;

int month;

int date;



while (isRunning) {

Scanner scanner = new Scanner(System.in);

System.out.println("Please enter your birth date format like that \n XX \n YY \n MMMM ");

date = scanner.nextInt();

month = scanner.nextInt();

year = scanner.nextInt();


if (date < 1 || date > 31) {

System.out.println("Please Enter a valid day \n a day can't be smaller than 1 and bigger than 31");
System.out.println("Please enter your birth date format like that \n XX \n YY \n MMMM ");
continue;
}

if (month < 1 || month > 12) {

System.out.println("Please Enter a valid month \n a month can't be smaller than 1 and bigger than 12");
System.out.println("Please enter your birth date format like that \n XX \n YY \n MMMM ");
continue;
}

if (year > currentYear) {

System.out.println("Please Enter a valid year \n a year can't be bigger than current year");
System.out.println("Please enter your birth date format like that \n XX \n YY \n MMMM ");
continue;
}

}

//zodiac sign print here
}
}
Madjosz
Madjosz2mo ago
Zodiac sign does not change on month though. It's somewhere around the 21st but different for each sign.
ayylmao123xdd
ayylmao123xdd2mo ago
oh yea lmao i forgot have to tweak it a bit then
this is mistifi
this is mistifiOP2mo ago
so ı oly need to use date variable also how ı am going to do the math between the time methot and our ınputted year it says you can not do that they are diffrenent types
ayylmao123xdd
ayylmao123xdd2mo ago
which thing we will use day and month ill show how in a second
this is mistifi
this is mistifiOP2mo ago
currentYear-year=user age it is not implemented yet but ı need it
ayylmao123xdd
ayylmao123xdd2mo ago
oh user age its just let me write it
this is mistifi
this is mistifiOP2mo ago
thanks ı appcreaite your effort
JavaBot
JavaBot2mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
ayylmao123xdd
ayylmao123xdd2mo ago
int userAge = Period.between(LocalDate.of(day, month, year), LocalDate.now()).getYears();
int userAge = Period.between(LocalDate.of(day, month, year), LocalDate.now()).getYears();
this is user age i named it day but in your code its date
this is mistifi
this is mistifiOP2mo ago
is it built in method our teacher stated that you can not use built in methots
ayylmao123xdd
ayylmao123xdd2mo ago
interesting did he say if you can use localdate.now its also a built in method
this is mistifi
this is mistifiOP2mo ago
only for getting current time he said
ayylmao123xdd
ayylmao123xdd2mo ago
ok
this is mistifi
this is mistifiOP2mo ago
ı dont know wht it is so hard
ayylmao123xdd
ayylmao123xdd2mo ago
ok question do you want longer answer or simpler answer for zodiac sign
this is mistifi
this is mistifiOP2mo ago
ı think the longer answer ı need to push my limits
ayylmao123xdd
ayylmao123xdd2mo ago
did you have enums in school
this is mistifi
this is mistifiOP2mo ago
yeah in todays class we looked into enums they are reference types like arrays but improved arrays
ayylmao123xdd
ayylmao123xdd2mo ago
so will you be able to explain whats happening when the teacher asks you to explain im asking cuz im thinking whether to show the answer with enums or no or just ifs ill do enums and if its too complex ill show the simple version
this is mistifi
this is mistifiOP2mo ago
enums are just like arrays as ı understand if there is parts that ı do not know i will learn ı am putting 4-5 hours to coding as it is my first year
ayylmao123xdd
ayylmao123xdd2mo ago
ok
ayylmao123xdd
ayylmao123xdd2mo ago
replace your publci static void main with what i put and check it out basically i used enums to create date ranges and since you cant use built in stuff i put it as int otherwise the best idea would be using monthday and then it just compares the range sees if a value is in range and returns the name of that enum
this is mistifi
this is mistifiOP2mo ago
thanks for your help as in my country time is 23.10
JavaBot
JavaBot2mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
this is mistifi
this is mistifiOP2mo ago
ı will look at toworrow
ayylmao123xdd
ayylmao123xdd2mo ago
when you typed it was 23:14 ez
this is mistifi
this is mistifiOP2mo ago
damm ı gotta sleep well or ı am going to find time travel
JavaBot
JavaBot2mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?