Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 31st, 2006, 01:04 PM
flaminblone111 flaminblone111 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 1 flaminblone111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 16 sec
Reputation Power: 0
Unhappy HELP!!! I'm Pulling my hair

I can't get this thing to run. It is an assignment that I'm working on and this is what the instructions say. and here is what I have.

INSTRUCTIONS:

Create a new class called Cat that is devifed from PetRecord class

The new class has the additional attributes of:
breed - type String
declawed - type boolean - true for has no claws, false for has claws

Be sure our classes have a reasonable complement of constructors and accessor methods.

Example:
public void setBreed(String inBreed) used to set the breed
public void set(Boolean inClaws) used to set claws or not
(You must overload the set method to set deClawed value)

Write a driver program that reads in 3 pets of type Cat and prints out the name and age of all cats with claws and over 3 years old.

The following information should be read in:
Name
Age
Weight
Breed
DeClawed



You are required to turn in 3 files.
PetRecord.java
Cat.java
DriverProgram.java - you can name this as you like. It will use the other 2 class files.
--------------------------------------------------

Here is what I have (However I can't figure out how to start a driver program. And my other ones won't work)

CAT CLASS----

Code:
public class Cat101 extends PetRecord101
{
	private String breed;
	private boolean deClawed;

	public void catinfo(String	name, int age, double weight,
		String initialBreed, boolean initialDeClawed);
	
	{
		

		breed = initialBreed;
		deClawed = initialDeClawed;
		
			
	}

	public void	set(boolean newDeClawed)
	{
			deClawed = newDeClawed;
	}

	public void setBreed(String newBreed)
	{
		breed = newBreed;
	}

	public String getBreed()
	{
		return breed;
	}

	public boolean getDeClawed()
	{
		return deClawed;
	}

	public void print()
	{
		System.out.println("name: " + getName() + " age: " + getAge() + " weight: " + getWeight() +
			" breed: " + getBreed() + " deClawed: " + getDeClawed());
	}
}



PETRECORD-=----------

Code:
import java.util.*; 
import java.text.DecimalFormat;

public class PetRecord101 
{ 
private String name; 
private int age;//in years 
private double weight;//in pounds 

public static void main(String[] args)
{

		Cat101 firstCat = new Cat101();
		Cat101 secondCat = new Cat101();
		Cat101 thirdCat = new Cat101();
    
        firstCat101.catinfo("Sora", "3", "7.6");
        secondCat101.catinfo("Riku", "1", "10.3");
        thirdCat101.catinfo("Daisy", "5", "8.2");
        }

public void writeOutput() 
{ 
System.out.println("Name: " + name); 
System.out.println("Age: " + age + " years"); 
System.out.println("Weight: " + weight + " pounds"); 
} 
/** Creates a new instance of Class */ 

public PetRecord101(String initialName, int initialAge, 
double initialWeight) 
{ 
name = initialName; 
if ((initialAge < 0) || (initialWeight < 0)) 
{ 
System.out.println("Error: Negative age or weight."); 
System.exit(0); 
} 
else 
{ 
age = initialAge; 
weight = initialWeight; 
} 
} 
public void set(String newName, int newAge, double newWeight) 
{ 
name = newName; 
if ((newAge < 0) || (newWeight < 0)) 
{ 
System.out.println("Error: Negative age or weight."); 
System.exit(0); 
} 
else 
{ 
age = newAge; 
weight = newWeight; 
} 
} 
public PetRecord101(String initialName) 
{ 
name = initialName; 
age = 0; 
weight = 0; 
} 

public void set(String newName) 
{ 
name = newName; //age and weight are unchanged. 
} 

public PetRecord101(int initialAge) 
{ 
name = "No name yet."; 
weight = 0; 
if (initialAge < 0) 
{ 
System.out.println("Error: Negative age."); 
System.exit(0); 
} 
else 
age = initialAge; 
} 

public void set(int newAge) 
{ 
if (newAge < 0) 
{ 
System.out.println("Error: Negative age."); 
System.exit(0); 
} 
else 
age = newAge; 
//name and weight are unchanged 
} 
public PetRecord101(double initialWeight) 
{ 
name = "No Name yet"; 
age = 0; 
if (initialWeight < 0) 
{ 
System.out.println("Error: Negative weight."); 
System.exit(0); 
} 
else 
weight = initialWeight; 
} 
public void set (double newWeight) 
{ 
if (newWeight < 0) 
{ 
System.out.println("Error: Negative weight."); 
System.exit(0); 
} 
else 
weight = newWeight; //name and age are unchanged. 
} 
public PetRecord101() 
{ 
name = "No name yet."; 
age = 0; 
weight = 0; 
} 
public String getName() 
{ 
return name; 
} 
public int getAge() 
{ 
return age; 
} 
public double getWeight() 
{ 
return weight; 
} 
}

---------------------------------------------

I can't get it to run or compile. I don't understand. ANd how do I do the driver program?

Thanks for the help in advance

Last edited by MadCowDzz : February 1st, 2006 at 08:28 AM. Reason: added [code] tags

Reply With Quote
  #2  
Old January 31st, 2006, 03:04 PM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Click here for more information. Click here for more information
 
Join Date: Sep 2005
Posts: 719 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 3 Days 8 h 15 m 26 sec
Reputation Power: 4
There are a couple of things going wrong. I'm going to tell you a couple I've spotted (but not all) to get you underway:

First of: remove the semi-colon ( after the signature of the catinfo method.
In the main method (PetRecord101 class) you declare objects with the name firstCat, secondCat, etc. but you try to reference them using firstCat101, secondCat101,.. choose one. I don't understand the 101 you put behind all your classes btw, I'd suggest to remove all of them.
Another thing in the main is that you are calling catinfo with 3 arguments where the real catinfo method has 5 arguments (catinfo should also be turned into a constructor to be clean..).
To compile you need to do something like:
"javac Cat.java PetRecord.java"

If you move the main method from PetRecord to a third file, then that 3rd file is the 'driver' which 'starts/constructs' the other two.

Hope this will get you to stop pulling your hair. If there are more questions after this don't hesitate to ask.

Good luck
Comments on this post
MadCowDzz agrees: Great explanations

Last edited by Icon : February 1st, 2006 at 01:39 AM.

Reply With Quote
  #3  
Old September 14th, 2006, 06:40 PM
mlorente mlorente is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 1 mlorente User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 52 sec
Reputation Power: 0
Java Driver Program with Inheritance

Icon are you still around?... I was playing with your suggestions on this post and came close to making it work (i think).

Look forward to hearing from you.

Quote:
Originally Posted by Icon
There are a couple of things going wrong. I'm going to tell you a couple I've spotted (but not all) to get you underway:

First of: remove the semi-colon ( after the signature of the catinfo method.
In the main method (PetRecord101 class) you declare objects with the name firstCat, secondCat, etc. but you try to reference them using firstCat101, secondCat101,.. choose one. I don't understand the 101 you put behind all your classes btw, I'd suggest to remove all of them.
Another thing in the main is that you are calling catinfo with 3 arguments where the real catinfo method has 5 arguments (catinfo should also be turned into a constructor to be clean..).
To compile you need to do something like:
"javac Cat.java PetRecord.java"

If you move the main method from PetRecord to a third file, then that 3rd file is the 'driver' which 'starts/constructs' the other two.

Hope this will get you to stop pulling your hair. If there are more questions after this don't hesitate to ask.

Good luck

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > HELP!!! I'm Pulling my hair


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT