Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
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
 
Old July 24th, 2010, 04:48 PM
Registered User
 
Join Date: Jul 2010
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default 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); }
}
}
}
 
Old July 25th, 2010, 01:48 AM
Registered User
 
Join Date: Jul 2009
Posts: 6
Thanks: 0
Thanked 2 Times in 2 Posts
Smile

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:
owais87 (July 25th, 2010)
 
Old July 25th, 2010, 02:56 AM
Registered User
 
Join Date: Jul 2010
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks friend ...

Quote:
Originally Posted by fulmen View Post
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);
		}
	}
}
 
Old July 25th, 2010, 07:19 AM
Registered User
 
Join Date: Jul 2010
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default 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);
}
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Root Cause:java.lang.NoSuchMethodError: java.util. anees81 JSP Basics 3 March 1st, 2011 08:55 AM
java.lang.OutOfMemoryError: Java heap space meetkotresh J2EE 1 February 2nd, 2008 01:52 AM
Java Media Framework(I am new to java) amirdiwan4eva Pro Java 4 July 12th, 2006 04:50 AM
Java Code - Wrox - Beginning JAVA - Ivor Horton ponguru Java Databases 3 May 18th, 2006 12:30 PM
Java vs Java Script functions joemorrison74 J2EE 0 July 6th, 2005 04:28 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.