Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

import java.io.

*;
class HOROSCOPE
{
private static String Name,DOB,StarSign;
private static int dd,mm,yy;
public static void main() throws IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader x=new BufferedReader(isr);
String cont;
do
{
System.out.print("Enter Your Name : ");
Name=x.readLine();
System.out.print("Enter Date of Birth (DD/MM/YYYY): ");
DOB=x.readLine();
extractDate();
System.out.print("Do you want to continue (Y/N) : ");
cont=x.readLine();
}while(cont.equals("Y") || cont.equals("y"));
}
private static void extractDate() throws IOException
{
int POS1=DOB.indexOf("/");
if(POS1==-1)
{
System.out.println("Invalid Date Format");
return;
}
dd=Integer.parseInt(DOB.substring(0,POS1));
int POS2=DOB.indexOf("/",++POS1);
mm=Integer.parseInt(DOB.substring(POS1,POS2));
yy=Integer.parseInt(DOB.substring(++POS2));
if(dateValid()==false)
{
System.out.println("Invalid Date");
return;
}
yourStarSign();
}
private static boolean dateValid()
{
int mon[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
mon[2] = (yy%4==0) ? 29 : 28;
if(dd<1 || dd>31)
return(false);
if(mm<1 || mm>12)
return(false);
if(dd>mon[mm])
return(false);
if(yy<1900 || yy>2100)
return(false);
return(true);
}
private static void yourStarSign() throws IOException
{
if((dd>=21 && mm==3) || (dd<=20 && mm==4))
StarSign="ARIES";
if((dd>=21 && mm==4) || (dd<=20 && mm==5))
StarSign="TAURUS";
if((dd>=21 && mm==5) || (dd<=20 && mm==6))
StarSign="GEMINI";
if((dd>=21 && mm==6) || (dd<=20 && mm==7))
StarSign="CANCER";
if((dd>=21 && mm==7) || (dd<=20 && mm==8))
StarSign="LEO";
if((dd>=21 && mm==8) || (dd<=20 && mm==9))
StarSign="VIRGO";
if((dd>=21 && mm==9) || (dd<=20 && mm==10))
StarSign="LIBRA";
if((dd>=21 && mm==10) || (dd<=20 && mm==11))
StarSign="SCORPIO";
if((dd>=21 && mm==11) || (dd<=20 && mm==12))
StarSign="SAGITTARIUS";
if((dd>=21 && mm==12) || (dd<=19 && mm==1))
StarSign="CAPRICORN";
if((dd>=20 && mm==1) || (dd<=18 && mm==2))
StarSign="AQUARIUS";
if((dd>=19 && mm==2) || (dd<=20 && mm==3))
StarSign="PISCES";
displayNature();
}
private static void displayNature() throws IOException
{
FileReader fr=new FileReader("HOROSCOPE.txt");
BufferedReader br=new BufferedReader(fr);
String Sign,Nature;
while(true)
{
Sign=br.readLine();
if(Sign==null)
break;
Nature=br.readLine();
if(Sign.equals(StarSign))
{
System.out.println("Your Name : "+Name);
System.out.println("Your date of Birth : "+DOB);
System.out.println("Star Sign : "+Sign);
System.out.println("\t\t\t\t-: Your Nature :-");
wordWrap(Nature);
}
}
br.close();
}
private static void wordWrap(String s)
{
String word,line="";
s=s+" ";
int p=0;
while(p<s.length())
{
int x=s.indexOf(' ',p);
String w=s.substring(p,x);
line=line+" "+w;
if(line.length()>70)
{
System.out.println(line);
line="";
}
p=x+1;
}
System.out.println(line);
}
}

You might also like