10 Replies - 1232 Views - Last Post: 03 March 2016 - 01:48 AM Rate Topic: -----

#1 darkangelos   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 20-January 16

method error trying to print

Posted 02 March 2016 - 04:52 PM

I am having issues with getting this to print correctly. I seem to have a problem with these all the time. And I Just need to know what I am doing wrong please.

it is a multiple class package, using inheritance.

please and info would help me out.


this is my tester(main) class

package project1;

import java.util.Scanner;

public class Main{

public static void main(String[] args)
{

	Hobby d1 = new Hobby(1000, "Warhammer", "Death");
	
	
	System.out.println(d1);
	
	
	
	
	 

}
}



This is the class that I have as the parent class

package project1;

public class Hobby 

{
	 Hobby(int hoursplayed,String hobbyname,String HobbyType) 
	 {
		
		System.out.println(hoursplayed + hobbyname + HobbyType);
			
		
		 
		 
		 
	}

	 public int hoursplayed()
	   {
	      return hoursplayed();
	   }

	 public int hobbyname()
	   {
	      return hobbyname();
	   }
	 public int HobbyType()
	   {
	      return HobbyType();
	   }

		
	
	
	




	
	
	
	
}



this is the child class. For some reason in the public void Battle, I am getting a method error, the suggested fixed under eclipse dont really help me.

package project1;


/*
 * This statement allows the Constructor in Hobby to be called.
 */
public class Warhammer extends Hobby 
{

	
	Warhammer(int hoursplayed, String hobbyname, String HobbyType) {
		
		
		
		super(hoursplayed , hobbyname , HobbyType );
		// TODO Auto-generated constructor stub
	}

	public void Battle()
	{
		System.out.println(super.gethoursplayed() + " " + super.gethobbyname() 
				+ super.gethobbyname()+ " for the Emperor");
	}
	

	
	
	
	
}



Is This A Good Question/Topic? 0
  • +

Replies To: method error trying to print

#2 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 870
  • View blog
  • Posts: 6,695
  • Joined: 25-December 13

Re: method error trying to print

Posted 02 March 2016 - 04:58 PM

Quote

having issues with getting this to print correctly.

please explain.
Post the current output and add some comments saying what is wrong with it and show what it should be.
Was This Post Helpful? 0
  • +
  • -

#3 darkangelos   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 20-January 16

Re: method error trying to print

Posted 02 March 2016 - 05:04 PM

1000WarhammerDeath
[email protected]



above is the ouput and to be very very straight forward this is:

Design and implement a class hierarchy that represents one of your hobbies. Build a main driver class to test the features of your class hierarchy. Include at least one of each of the following items: inheritance, super, method overriding, method overloading, override the toString/equals methods from the object class, comparable interface, abstract class/method, final reserved word. In your main driver class, use an array to store a list of objects in your class hierarchy. Use the Arrays.sort() method to sort your list of objects. Use a for-each loop to print out information from each object in the array.

I am not completely done with this, i am just stuck at this point.
Was This Post Helpful? 0
  • +
  • -

#4 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 870
  • View blog
  • Posts: 6,695
  • Joined: 25-December 13

Re: method error trying to print

Posted 02 March 2016 - 05:17 PM

You forgot to say what was wrong with the print out and to show what you want to see printed.

Quote


That is the String returned by the default toString() method for the Hobby class. If you want to see something different, you need to override the Hobby class's toString() method and have it return the String you want to see printed.
Was This Post Helpful? 0
  • +
  • -

#5 darkangelos   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 20-January 16

Re: method error trying to print

Posted 02 March 2016 - 05:22 PM

I am trying to make it so it doesnt print the hobby.project10008
Was This Post Helpful? 0
  • +
  • -

#6 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 870
  • View blog
  • Posts: 6,695
  • Joined: 25-December 13

Re: method error trying to print

Posted 02 March 2016 - 05:32 PM

Quote

trying to make it so it doesnt print the hobby.project10008

Ok, what statement prints that?

That was not shown in the print out in post#3

This post has been edited by NormR: 02 March 2016 - 05:34 PM

Was This Post Helpful? 0
  • +
  • -

#7 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: method error trying to print

Posted 02 March 2016 - 05:35 PM

Do not use a meaningless title "Having issues with this", I have changed it for you.
Was This Post Helpful? 0
  • +
  • -

#8 darkangelos   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 20-January 16

Re: method error trying to print

Posted 02 March 2016 - 05:36 PM

ha,

I actually just figured it out. Thanks though.
Was This Post Helpful? 0
  • +
  • -

#9 MentalFloss   User is offline

  • .
  • member icon

Reputation: 619
  • View blog
  • Posts: 1,590
  • Joined: 02-September 09

Re: method error trying to print

Posted 02 March 2016 - 06:03 PM

View Postdarkangelos, on 03 March 2016 - 12:36 AM, said:

ha,

I actually just figured it out. Thanks though.


What did you do to figure it out? Why don't you tell us, so others can learn too. Perhaps your problem is shared by others who may benefit if you provide a detailed explanation as to what you did to fix it. You benefit too by trying to be as detailed as possible because being detailed requires deep understanding, and you will know if you understand the material well enough when you try to explain it.

If you just one-shot figure something out, and go on about your day, nothing solidifies in your mind about it, so you will do the same incorrect thing next time (most likely).
Was This Post Helpful? 0
  • +
  • -

#10 darkangelos   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 20-January 16

Re: method error trying to print

Posted 02 March 2016 - 06:32 PM

I added a to-string method in my hobby class, You have a good point BTW.


@Override
	public String toString() {
	        return "";
	    


View Postandrewsw, on 02 March 2016 - 05:35 PM, said:

Do not use a meaningless title "Having issues with this", I have changed it for you.


I am not use to forums so thank you! for future posts I will make the title more meaningful.
Was This Post Helpful? 1
  • +
  • -

#11 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3744
  • View blog
  • Posts: 17,121
  • Joined: 20-September 08

Re: method error trying to print

Posted 03 March 2016 - 01:48 AM

Quote

I added a to-string method in my hobby class

That's worse than doing nothing. Effectively you have introduced what amounts to a bug. Your real problem was the failure to create an instance of the correct subclass and was nothing to do with printing

This post has been edited by g00se: 03 March 2016 - 01:49 AM
Reason for edit:: Formatting bork

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1