quiz4Solu

quiz4Solu - ’s age in person years is ”...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE182 Applied Problem Solving with C# Quiz #4 First Name (print): ____________________ Last Name (print):_________________________ 1. If we have a class called Fish, what is the header of the default constructor? How to use it to create a Fish called jellyFish ? header: public Fish( ) To create an object: Fish jellyfish = new Fish( ); 2. Look at class Dog , according to the description, fill in the blanks //A driver's class used to test the Dog class using System; namespace Chp4DogClass { class TestDog { static void Main(string[] args) { //use the no-arguments contructor to create a dog called myDog Dog myDog = new Dog( ); //use another constructor to create a dog called yourDog with name //“Jack” and is 3 years old Dog yourDog = new Dog(“Jack”, 3); //Set myDog name to “Robin”, age to 4 myDog.Name = “Robin”; myDog.Age = 4; //let myDog run myDog.run(); //let yourDog run yourDog.run(); //Print yourDog ’s person age on screen Console.WriteLine(“Your dog
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: \ ’s age in person years is: ” + yourDog.calInPersonAge()); //Print myDog ’s info. (name and age) on screen Console.WriteLine(myDog); } } } CSE182 Applied Problem Solving with C# Quiz #4 First Name (print): ____________________ Last Name (print):_________________________ //This class define a Dog using System; namespace Chp4DogClass { class Dog { private string name; private int age; public Dog() { } public Dog(string dogName, int dogAge) { name = dogName; age = dogAge; } public string Name { get { return name; } set { name = value; } } public int Age { get { return age; } set { age = value; } } public void run() { Console.WriteLine(name + " is running. .."); Console.WriteLine(); } //this method return the dog age in "person years" public int calInPersonAge() { return age * 7; } public override string ToString() { string result = ""; result = name + " is " + age + " years old."; return result; } }}...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

quiz4Solu - ’s age in person years is ”...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online