mankind0.java

来自「java 教程源码」· Java 代码 · 共 47 行

JAVA
47
字号
//c4:Mankind0.java
//author:ZhangHongbin 
//This program is protected by copyright laws.
//a widely used class example in my book.  
public class Mankind0
{
	int sex;
	int salary;
	void manOrWoman( int sexValue)
	{ 
		switch(sexValue)
		{	
			case 0:
					System.out.println("I am a man");
					break;
			case 1:
					System.out.println("I am a woman");
					break;
			default:
					System.out.println("I am not a man or a women");
		}
	}
	void employed (int salaryValue)
	{
		if (salaryValue==0)
			System.out.println("I am jobless ");
		else
 			System.out.println("I have a job");
	}
	double income(int wage)
	{
		System.out.println("My income this year is "+wage);
		return wage*0.9;
	}
	public static void main(String[] args) 
	{
		Mankind0 somePerson=new Mankind0();//创建对象
		somePerson.sex=1;//给对象中的数据赋值
		somePerson.manOrWoman( somePerson.sex);//执行对象中的方法
		somePerson.salary=5; //给对象中的数据赋值
		somePerson.employed(somePerson.salary); //执行对象中的方法
		double netIncome = somePerson.income(200);
		System.out.println("My net income this year is "+netIncome);

	} 
} 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?