 |
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

July 24th, 2010, 04:48 PM
|
Registered User
|
|
Join Date: Jul 2010
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
i am to java please help me
this is the program please help me to fing out the bugs from it ... Thanks
public class lab1_horo {
/** Creates a new instance of lab1_horo */
public lab1_horo() {
}
public static void main(String[] args) {
double day;
String month, name, sign = null;
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date date = new Date();
System.out.println(dateFormat.format(date));
Scanner input = new Scanner(System.in);
System.out.println("Hello, what is your name?");
name = input.nextLine();
System.out.println("In what month were you born?");
month = input.nextLine();
System.out.println("On what day of " month " were you born?");
day = input.nextDouble();
if (month.equals("March") && day >= 21 || month.equals("April")
&& day <= 20);{
sign = "Aries";
System.out.println(name ", you are an " sign ". You will have an awesome day");}
else if (month.equals("April") && day >= 21 || month.equals("May")
&& day <= 21) {
sign = "Taurus";
System.out.println(name ", you are an " sign);}
else if (month.equals("May") && day >= 22 || month.equals("June")
&& day <= 21) {
sign = "Gemini";
System.out.println(name ", you are an " sign);}
else if (month.equals("June") && day >= 22 || month.equals("July")
&& day <= 22); {
sign = "Cancer";
System.out.println(name ", you are an " sign);}
else if (month.equals("July") && day >= 23 || month.equals("August")&& day <= 23);
{ sign = "Leo";
System.out.println(name ", you are an " sign);}
else if (month.equals("August") && day >= 24 || month.equals("September")
&& day <= 23)
;
{
sign = "Virgo";
System.out.println(name ", you are an " sign);
}
else if (month.equals("September") && day >= 24 || month.equals("October")
&& day <= 23)
;
{
sign = "Libra";
System.out.println(name ", you are an " sign);
}
else if (month.equals("October") && day >= 24 || month.equals("November")
&& day <= 22)
;
{
sign = "Scorpio";
System.out.println(name ", you are an " sign);
}
else if (month.equals("November") && day >= 23 || month.equals("December")
&& day <= 21)
;
{
sign = "Sagittarius";
System.out.println(name ", you are an " sign);
}
else if (month.equals("December") && day >= 22 || month.equals("January")
&& day <= 20)
;
{
sign = "Capricorn";
System.out.println(name ", you are an " sign);
}
else if (month.equals("January") && day >= 21 || month.equals("February")
&& day <= 18) ;
{sign = "Aquarius";
System.out.println(name ", you are an " sign); }
else (month.equals("February") && day >= 19 || month.equals("March") && day <= 20);
{sign = "Pisces";
System.out.println(name ", you are an " + sign); }
}
}
}
|

July 25th, 2010, 01:48 AM
|
Registered User
|
|
Join Date: Jul 2009
Posts: 6
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
I had a quick look at your code and fixed it up for you a little bit. It can be complied now but you need to put in more hours to make it work properly.
Have fun
Code:
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class lab1_horo {
/** Creates a new instance of lab1_horo */
public lab1_horo() {
}
public static void main(String[] args) {
double day;
String month, name, sign = null;
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date date = new Date();
System.out.println(dateFormat.format(date));
Scanner input = new Scanner(System.in);
System.out.println("Hello, what is your name?");
name = input.nextLine();
System.out.println("In what month were you born?");
month = input.nextLine();
System.out.println("On what day of " + month + " were you born?");
day = input.nextDouble();
if (month.equals("March") && day >= 21 || month.equals("April")
&& day <= 20) {
sign = "Aries";
System.out.println(name + ", you are an " + sign
+ ". You will have an awesome day");
}
else if (month.equals("April") && day >= 21 || month.equals("May")
&& day <= 21) {
sign = "Taurus";
System.out.println(name + ", you are an " + sign);
}
else if (month.equals("May") && day >= 22 || month.equals("June")
&& day <= 21) {
sign = "Gemini";
System.out.println(name + ", you are an " + sign);
}
else if (month.equals("June") && day >= 22 || month.equals("July")
&& day <= 22) {
sign = "Cancer";
System.out.println(name + ", you are an " + sign);
} else if (month.equals("July") && day >= 23 || month.equals("August")
&& day <= 23) {
sign = "Leo";
System.out.println(name + ", you are an " + sign);
} else if (month.equals("August") && day >= 24
|| month.equals("September") && day <= 23) {
sign = "Virgo";
System.out.println(name + ", you are an " + sign);
} else if (month.equals("September") && day >= 24
|| month.equals("October") && day <= 23) {
sign = "Libra";
System.out.println(name + ", you are an " + sign);
} else if (month.equals("October") && day >= 24
|| month.equals("November") && day <= 22) {
sign = "Scorpio";
System.out.println(name + ", you are an " + sign);
} else if (month.equals("November") && day >= 23
|| month.equals("December") && day <= 21) {
sign = "Sagittarius";
System.out.println(name + ", you are an " + sign);
} else if (month.equals("December") && day >= 22
|| month.equals("January") && day <= 20) {
sign = "Capricorn";
System.out.println(name + ", you are an " + sign);
} else if (month.equals("January") && day >= 21
|| month.equals("February") && day <= 18) {
sign = "Aquarius";
System.out.println(name + ", you are an " + sign);
} else if (month.equals("February") && day >= 19
|| month.equals("March") && day <= 20) {
sign = "Pisces";
System.out.println(name + ", you are an " + sign);
}
}
}
|
The Following User Says Thank You to fulmen For This Useful Post:
|
|

July 25th, 2010, 02:56 AM
|
Registered User
|
|
Join Date: Jul 2010
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Thanks friend ...
Quote:
Originally Posted by fulmen
I had a quick look at your code and fixed it up for you a little bit. It can be complied now but you need to put in more hours to make it work properly.
Have fun
Code:
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class lab1_horo {
/** Creates a new instance of lab1_horo */
public lab1_horo() {
}
public static void main(String[] args) {
double day;
String month, name, sign = null;
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date date = new Date();
System.out.println(dateFormat.format(date));
Scanner input = new Scanner(System.in);
System.out.println("Hello, what is your name?");
name = input.nextLine();
System.out.println("In what month were you born?");
month = input.nextLine();
System.out.println("On what day of " + month + " were you born?");
day = input.nextDouble();
if (month.equals("March") && day >= 21 || month.equals("April")
&& day <= 20) {
sign = "Aries";
System.out.println(name + ", you are an " + sign
+ ". You will have an awesome day");
}
else if (month.equals("April") && day >= 21 || month.equals("May")
&& day <= 21) {
sign = "Taurus";
System.out.println(name + ", you are an " + sign);
}
else if (month.equals("May") && day >= 22 || month.equals("June")
&& day <= 21) {
sign = "Gemini";
System.out.println(name + ", you are an " + sign);
}
else if (month.equals("June") && day >= 22 || month.equals("July")
&& day <= 22) {
sign = "Cancer";
System.out.println(name + ", you are an " + sign);
} else if (month.equals("July") && day >= 23 || month.equals("August")
&& day <= 23) {
sign = "Leo";
System.out.println(name + ", you are an " + sign);
} else if (month.equals("August") && day >= 24
|| month.equals("September") && day <= 23) {
sign = "Virgo";
System.out.println(name + ", you are an " + sign);
} else if (month.equals("September") && day >= 24
|| month.equals("October") && day <= 23) {
sign = "Libra";
System.out.println(name + ", you are an " + sign);
} else if (month.equals("October") && day >= 24
|| month.equals("November") && day <= 22) {
sign = "Scorpio";
System.out.println(name + ", you are an " + sign);
} else if (month.equals("November") && day >= 23
|| month.equals("December") && day <= 21) {
sign = "Sagittarius";
System.out.println(name + ", you are an " + sign);
} else if (month.equals("December") && day >= 22
|| month.equals("January") && day <= 20) {
sign = "Capricorn";
System.out.println(name + ", you are an " + sign);
} else if (month.equals("January") && day >= 21
|| month.equals("February") && day <= 18) {
sign = "Aquarius";
System.out.println(name + ", you are an " + sign);
} else if (month.equals("February") && day >= 19
|| month.equals("March") && day <= 20) {
sign = "Pisces";
System.out.println(name + ", you are an " + sign);
}
}
}
|
|

July 25th, 2010, 07:19 AM
|
Registered User
|
|
Join Date: Jul 2010
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
i am creating a simple calculator
i am creating a simple calculator in which user gives input ... in last line i found error in looping ... any one point out my errors ...
import java.util.Scanner;
public class calculator
{
public static void main(String[] args)
{
char answer;
String input;
int firstnumber;
int secondnumber;
System.out.println ("Welcome to the calculator!");
System.out.println ("To multiply use m, to divide use d, to add use a, to subtract use s");
Scanner keyboard = new Scanner(System.in);
do
{
System.out.println ("Do you want to multiply, divide, add, or subtract? ");
keyboard.nextLine();
input = keyboard.nextLine();
answer = input.charAt(0);
if (answer == 'm')
System.out.println ("Input first number: ");
keyboard.nextLine();
input = keyboard.nextLine();
firstnumber = keyboard.nextInt();
System.out.println ("Would you like another calculation (y/n)? ");
keyboard.nextLine();
input = keyboard.nextLine();
answer = input.charAt(0);
}
while(answer == 'y')
if(answer == 'n');
System.exit(0);
}
}
|
|
 |