Topic supplement :

Create a subfolder in the folder where the source program is stored myPackage. for example , stay “D:\java” Create a subfolder with the same name as the package in the folder myPackage(D:\java\myPackage). stay myPackage Create a... In the package YMD class , This class has the ability to calculate the year of this year 、 Can output a string with the date of the function . Design procedure SY31.java, Give someone a name and date of birth , Calculate the person's age , And output the name of the person 、 Age 、 Date of birth . Program usage YMD How to calculate age .

The use of the main test package

be used java.util.Calendar; Find the time and date

YMD class :

 import java.util.Calendar;
public class YMD {
private int year,month,day;
YMD(){}
public YMD(int year,int month,int day){
this.year=year;
this.month=month;
this.day=day;
}
public int getYear(){
return year;
}
public int getMonth(){
return month;
}
public int getDay(){
return day;
}
public static int nowYear(){// Returns the current year
return Calendar.getInstance().get(Calendar.YEAR);
}
public static int nowMonth(){// Return to the current month
return Calendar.getInstance().get(Calendar.MONTH);
}
public void showYMD(){// String form output date
System.out.println(" Date of birth :"+year+"-"+month+"-"+day);
}
}

Test class :( Be careful : The use of objects is very special )

 import myPackage.YMD;
class personINfo{
private String name;
private YMD birthdate;// Create a private reference to the class
personINfo(){}
personINfo(String name,YMD d){
this.name=name;
birthdate=d;// Initialize object
}
personINfo(String name,int year,int month,int day){
this(name,new YMD(year,month,day));// To the object d To initialize , Assign initial value to , Refer to the construction method of two formal parameters of the current class
}
public int month(){// Calculate the month , Less than one year
return YMD.nowMonth()-birthdate.getMonth();
}
public int age(){// Calculation year
return YMD.nowYear()-birthdate.getYear();
}
public String getName(){
return name;
}
public void output(){
System.out.println(" full name :"+getName());
if(month()<0)
System.out.println(" Age :"+(age()-1));
else
System.out.println(" Age :"+age());
birthdate.showYMD(); // Display the date in the form of string
}
}
public class Test5_4 {
public static void main(String args[]){
personINfo p=new personINfo(" Zhang San ",1997,12,30);
p.output();
} }

Create a subfolder in the folder where the source program is stored myPackage. for example , stay “D:\java” Create a subfolder with the same name as the package in the folder myPackage(D:\java\myPackage). stay myPackage Create a... In the package YMD class , This class has the ability to calculate the year of this year 、 Can output a string with the date of the function . Design procedure SY31.java, Give someone a name and date of birth , Calculate the person's age , And output the name of the person 、 Age 、 Date of birth . Program usage YM More articles about

  1. ci 3.0 The default route is placed in a subfolder Inaccessible solutions

      For example, you want to configure the default route to : $route['default_controller'] = 'index/home'; ci3.0 It can be put in before controllers In the subfolder of , But here we are ci ...

  2. Eclipse start-up Tomcat after web Project classes There is no calss file

    Eclipse start-up Tomcat after web Project classes There is no calss file . The following solutions can be found on the Internet hold properties In the attribute java compiler-->buildi ...

  3. Keyboard input a folder path , Count this folder ( Include subfolders ) The number of files of each type in , Be careful : Use file type ( Suffix name , It doesn't contain .( spot ), Such as :&quot;java&quot;,&quot;txt&quot;) As key, Use the number as value, Put in map Collection , Traverse map aggregate

    package cn.it.zuoye5; import java.io.File;import java.util.HashMap;import java.util.Iterator;import ...

  4. MATLAB Check whether there are spaces in the file names in the subfolders in the specified path

    The test folder is : clear;close all;clc; %% % The function of the program % Check whether there are spaces in the file names in the subfolders in the specified path , And remove the space in the file name %% % The previously unknown functions used in the program are as follows % ...

  5. GIT How to merge another remote Git The remote submission record is not lost when the warehouse files are sent to a specified sub folder in the local warehouse ?

    The problem background :     Recently, I was reorganizing a project in my hands , At present, the project is divided into PC project , Mobile project , A third party interface project , Third party interface services and mobile phone projects     Because of the previous planning , The original four projects were managed by two solutions ...

  6. java Print stream Recursively copying subfolders Copy different coded files to the same file Serialize stream deserialize stream

    package com.swift.jinjie; import java.io.BufferedInputStream; import java.io.File; import java.io.Fi ...

  7. The folder contains subfolders , Modify the image storage format in the subfolder (python Realization )

    The folder contains subfolders , Modify the image storage format in the subfolder , hold png Image changed to jpg Images ,python The code is as follows : import os import cv2 filePath = 'C:\\Users\\admi ...

  8. linux Copy the files in the subfolder to In the current directory

    linux Copy the files in the subfolder to In the current directory , Such as The directory structure is about -sh |__ db_backup |___ test |____ 2018_01_01_00_00_00 |_____ 2018_ ...

  9. python Batch delete empty subfolders in subfolders

    for example A There are many subfolders under the folder , What I need to get is images in subfolders , But now it's not just pictures in subfolders , And mixed in empty folders ( In the use of OpenImages In the toolbox , According to the retrieval method, the downloaded image file contains label Of ...

Random recommendation

  1. Zend Framework introduction (3)— Error handling

    undefined Explain that some objects in the script are not set You should judge before using the object for example : if(typeof(aobject) == "undefined"){   // Error handling }

  2. Activiti Global event mechanism and its listening and processing

    summary Activiti stay 5.15 After later versions , Add a unified event entry , It doesn't need to be like before , When listening for process events , In process definition BPMN Add the following configuration for each node and process in the file , In order to achieve the practice of monitoring events , This led me to ...

  3. svn Version control moved to git

    Get the original SVN List of author names used by the repository Because importing into git You need to configure the original author (svn submitter ) and git The mapping of accounts The format for : vim authors-transform.txt taoxs = xsTao ...

  4. java.net.UnknownHostException: lc001 Unknown network service

    java.net.UnknownHostException: lc001 Unknown network service Read the name of the virtual machine One . Query environment variables :echo $HOSTNAME lc001 No problem Two . check host ...

  5. view On class ( One )

    /*************************************************************************************************** ...

  6. R Language - Default mirror settings

    problem 1: How to set the default image You want to download some R package , So I want to set the default CRAN Website image , such R You don't have to choose a mirror every time you download it . Solution The scheme requires users to R The system contains a .Rprofile file , Such as the method 3.16 describe ...

  7. vue-cli Use better-scroll

    better-scroll  api file https://ustbhuangyi.github.io/better-scroll/doc/zh-hans/ One : install better-scroll plug-in unit cn ...

  8. CSS A super useful collection of tools in coding

    When you develop websites and Web When applied , Using the right tools can save a lot of time . In this article I will collect some very useful CSS Coding tools , I hope it helps you . Pure CSS Pure It's from Yahoo CSS frame , Use  Norm ...

  9. modelsim In simulation Altera Usage of Library

    add to altera  library example : Set up lpm_mux IP Generated on .v file lpm_mux_ip.v Together with the test script file you wrote , stay modelsim To build a project , Add the following two files to the project direct compil ...

  10. be based on NLP and GAN The film and television of the novel

    outline : https://tieba.baidu.com/p/1271120336 To color :