BirthdaySongTest

I'm having trouble trying to get my program print out the lyrics

Page 1 of 1

2 Replies - 790 Views - Last Post: 15 February 2009 - 08:08 PM Rate Topic: -----

#1 grifter8875  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 09-February 09

BirthdaySongTest

Post icon  Posted 15 February 2009 - 05:29 PM

I'm working on a lab assignment for an introduction to Javas class and the trouble is getting my program to print out the lyrics to happy birthday. This is what I have so far in BirthdaySongTest.java
/*
 *Name: Allan  
 *Purpose: Birthday song test
 *Date: Feb 14, 2009
 */



public class BirthdaySongTest {
	public static void main(String[] args) {


/*Test the BirthdaySong class.
 * Instantiate a BirthdaySong object named b1. 
 */
  
  BirthdaySong b1 = new BirthdaySong();
//Have b1 print the song. 
	  System.out.println(b1); 


	  
	}//end main ()
}//end BirthdaySongTest


the output is [email protected]
it should be the lyrics to happy birthday as seen below.

In the same folder i have saved BirthdaySong.java. This is what I have in BirthdaySong.java.

public class BirthdaySong {

	public BirthdaySong() {

	}

	public void sing() {
		System.out.println("Happy birthday to you");
		System.out.println("Happy birthday to you");
		System.out.println("Happy birthday dear ");
		System.out.println("Happy birthday to you");
	}
}



I would greatly appreciate any insights and an explanation on what i have to do to get it to print out the correct lyrics.

Is This A Good Question/Topic? 0
  • +

Replies To: BirthdaySongTest

#2 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 729
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: BirthdaySongTest

Posted 15 February 2009 - 05:33 PM

change this
System.out.println(b1); 



to
b1.sing();


[email protected]
what that weird output is, is the address in the memory that the object you created is pointing at..what you needed to do is call the method sing() as i have done to display the lyrics..hope this helps

This post has been edited by mostyfriedman: 15 February 2009 - 05:34 PM

Was This Post Helpful? 1
  • +
  • -

#3 grifter8875  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 09-February 09

Re: BirthdaySongTest

Posted 15 February 2009 - 08:08 PM

Thanks! That helped alot. I was just so use to using Sytem.out.println for getting it to output anything.

This post has been edited by grifter8875: 15 February 2009 - 08:10 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1