Head first C # Chinese Version chapter 12th review and foresight page520

Source: Internet
Author: User

 

 

Let's jump directly to the code. First, we need a flower
Class.
Flower
Class requires
Point
Defined location, age, and lifetime. As time passes, flowers will grow older. Then, when the age reaches the lifetime value, the flowers will die. Your task is to implement these.



① Write flower
Framework Code of the class



Below is the flower
Class diagram. Write out the basic class framework,
Location
,
Age
,
Alive
,
Nectar
And
Nectarharvested
All are automatic attributes.
Nectarharvested
It is writable, and the other four are read-only. Leave the method blank now; we will return to process them later.



 

② Add some constants to the class


We need to give flowers many constants. Flower for you
Add six classes:



◆ Lifespanmin
, The shortest life of flowers

◆ Lifespanmax
, The longest life of flowers

◆ Maxnectar
How much pollen a flower can contain

◆ Nectaraddedperturn
How much pollen will the flowers increase every time they grow older?

◆ Nectargatheredperturn
, How many pollen will be collected in a life cycle



(By The Way, constants are usually not drawn in class diagrams)


You should be able to deduce their types based on the value of each constant. Flowers can survive 15000 million
To
30000
Life cycle, including
1.5
Unit of pollen. Can contain at most
5
Unit of pollen. In each lifecycle, flowers increase
0.01
Unit of pollen, and the pollen that can be collected in each lifecycle is
0.3
Unit.

 



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.