Jump to content

Classes and Methods... Pseudo Code

- - - - -

  • Please log in to reply
No replies to this topic

#1
wolfman

wolfman

    Newbie

  • Members
  • PipPip
  • 18 posts
Alright, I'm trying to design a program that asks the user for 3 different inputs, pet name, pet type and pet age. When everything is entered, I want what they entered displayed at the end. I need to this using a class named Pet and various methods that store and return the values.

The book I'm using keeps referring back and forth to figures and doesn't provide good examples similar to what I'm trying to do. So this is what I came up with.

Here go my questions and concerns. I'm not sure if I placed the class Pet in the correct spot, I think I did though. The other two are related to where I ask the user for their input and output, is that the correct placement?

This is PSEUDO CODE by the way.


class PetClassProgram

	main()

		//Declarations

		private string petName

		private string petType

		private num petAge


                Pet (string name, string type, num age)

		petName = name

                petType = type

                petAge = age


		public void setPetName(string name)

		     petName = name

		return


		public void setPetType(string type)

		     petType = type

		return


		public void setPetAge(num age)

		     petAge = age

		return

 

		public string getPetName()

		     string petName

		output “Please enter your pet’s name: ”

		input petName

		return petName


		public string getPetType()

		     string petType

		output “Please enter what type of pet you have (i.e. Dog, Cat, Bird, Lizard, etc.): ”

		input petType

		return petType


		public num getPetAge()

		     num petAge

		output “Please enter your pet’s age: ”

		input petAge

		return petAge


		output “Pet’s name : ” getPetName()

		output “Pet type : ” getPetType()

		output “Pet’s age : ” getPetAge()

		

	return

endClass



Just reviewing the code right now, would I be correct to assume that I don't need string petType, string petName , num petAge declared as variables in my get methods if I already did it in the beginning? Something like this....


		public string getPetName()

		output “Please enter your pet’s name: ”

		input petName

		return petName


		public string getPetType()

		output “Please enter what type of pet you have (i.e. Dog, Cat, Bird, Lizard, etc.): ”

		input petType

		return petType


		public num getPetAge()

		output “Please enter your pet’s age: ”

		input petAge

		return petAge


Thank you,

-=wolfman
-=[ w | o | l | f | m | a | n ]=-




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users