using System;
using System.Collections.Generic;
using System.Text;
namespace test
{
class Program
{
static void Main(string[] args)
{
Date birthday = new Date(, , , new Time(, , ));//传入的第四个参数是对象
Console.WriteLine("我出生于{0}年{1}月{2}日{3}", birthday.year, birthday.month, birthday.day, birthday.clock.To24());//调用第四个对象的方法
}
}
class Time
{
private int hour;
private int minute;
private int second;
private void SetTime(int h, int m, int s)
{
Hour = h;//属性赋值
Minute = m;//属性赋值
Second = s;//属性赋值
}
public Time()//无参构造函数
{
SetTime(, , );
}
public Time(int hourvalue)//一参构造函数
{
SetTime(hourvalue, , );
}
public Time(int hourvalue, int minutevalue, int secondvalue)//三参构造函数
{
SetTime(hourvalue, minutevalue, secondvalue);
}
public int Hour//属性赋值
{
set { hour = (value >= && value <= ? value : ); }
get { return hour; }
}
public int Minute//属性赋值
{
set { minute = (value >= && value <= ? value : ); }
get { return minute; }
}
public int Second//属性赋值
{
set { second = (value >= && value <= ? value : ); }
get { return second; }
}
public string To24()//显示24小时制方法
{
string output = Hour + ":" + Minute + ":" + Second;
return output;
}
public string To12()//显示24小时制方法
{
string output;
if (Hour >= )
{
output = Hour % + ":" + Minute + ":" + Second + "PM";
}
else
{
output = Hour % + ":" + Minute + ":" + Second + "AM";
}
/*下面也是可以的
int HOURTEMP = (Hour == 0 || Hour == 12) ? 00 : (Hour % 12);
string PMAM = (Hour < 12) ? "AM" : "PM";
string output1 = HOURTEMP + ":" + Minute + ":" + Second + PMAM;*/
return output;
}
}
class Date
{
public int year;
public int month;
public int day;
public Time clock;//对象定义为成员
public Date(int yearvalue, int monthvalue, int dayvalue, Time clockvalue)
{
year = yearvalue;
month = monthvalue;
day = dayvalue;
clock = clockvalue;
}
}
}

最新文章

  1. iOS开发之三个Button实现图片无限轮播(参考手机淘宝,Swift版)
  2. Windows下通过socket进行字符串和文件传输
  3. h.APR通道是个怎么回事
  4. 使用clipboard.js复制页面内容到剪切板
  5. vmware10安装win8x64(亲测)
  6. 常见的三种Web服务架构
  7. UVA 12219 Common Subexpression Elimination
  8. js中赋值表达式的值为右边
  9. Fiddler抓包请求前设置断点
  10. hive on spark
  11. Cocos2dx开发之运行与渲染流程分析
  12. UTC时间、GMT时间、本地时间、Unix时间戳
  13. Docker操作删除所有容器镜像
  14. 论如何优雅的自定义ThreadPoolExecutor线程池
  15. nginx 多级反向代理获取客户端真实IP
  16. display:none和visibility:hidden
  17. python模块之linecache
  18. 工具软件 PYUV打开raw图片
  19. 最优比率生成树 POJ 2728 迭代或者二分
  20. 2018.08.30 bzoj4318: OSU!(期望dp)

热门文章

  1. git 每次提交需要输入密码
  2. Object类和异常
  3. SpringMVC生成的验证码图片不显示
  4. MIT-6.824 操作系统 汇总
  5. uni-app实现图片和视频上传功能
  6. C# 利用AForge进行摄像头信息采集
  7. 上传图片报错-Failed to load resource:the server responded with a status of 413(Request Entity Too Large)
  8. JS---BOM基本知识 (顶级对象,系统对话框,加载事件,location对象, history对象, navigator对象)
  9. 简单看看es6解构赋值
  10. [Android逆向]APK反编译与回编译