Java编程-类与对象

一.什么是类和对象
类和对象(class)是两种以计算机为载体的计算机语言的合称。对象是对客观事物的抽象,类是对对象的抽象。类是一种抽象的数据类型。它们的关系是,对象是类的实例,类是对象的模板。对象是通过new className产生的,用来调用类的方法,类的构造方法 。

二.课后作业
1.创建管理员对象
package task_x303_20181106;

public class kind {
public static void main(String[] args) {
Administrator book = new Administrator();
book.name = “admin1”;
book.password = “111111”;
book.name1 = “admin2”;
book.password1 = “222222”;
book.show();
}
}

package task_x303_20181106;

public class Administrator {

String name;	    
String password;	

String name1;
String password1;

public void show(){
	System.out.println("姓名:" + name + "密码:" + password);
	System.out.println("姓名:" + name1 + "密码:" + password1);
}

}

2.更改管理员密码
package task_x303_20181106;

import java.util.Scanner;

public class Administrators {

String name;
int code;
int code2;

public void show() {
	System.out.println("修改成功,您的新密码是:" + code2);
}
public void show2() {
	System.out.println("用户名和密码不匹配!您没有权限修改管理员信息!");
}
public static void main(String[] args) {
	
	Administrators administrators = new Administrators();
	Scanner scanner = new Scanner(System.in);
	System.out.print("请输入用户名:");
	String name = scanner.next();
	administrators.name = name;
	System.out.print("请输入您的密码:");
	int code = scanner.nextInt();
	administrators.code = code;
	while (code == 111111) {
		if(name.equals("admin1")){
		System.out.print("请输入您新密码:");
		int code2 = scanner.nextInt();
		administrators.code2 = code2;
		administrators.show();
		break;}
		else{administrators.show2();
		break;		
		}
	}
	while (code != 111111) {
		administrators.show2();
		break;
	}
}

}

3.客户积分回馈
package task_x303_20181106;

import java.util.Scanner;

public class Integral {

int score;
String card;

public void show() {
	System.out.println("积分:" + score + "\t\t卡类型:" + card + "\t\t回馈积分500分!");
}
public void show2() {
	System.out.println("积分:" + score + "\t\t卡类型:" + card);
}
public static void main(String[] args) {
	Integral integral = new Integral();
	Scanner scanner = new Scanner(System.in);
	System.out.print("积分是:");
	int score = scanner.nextInt();
	integral.score = score;
	System.out.print("卡类型是:");
	String card = scanner.next();
	integral.card = card;
	if (card.equals("普通卡")) {
		if (score >= 5000) {
			integral.show();
		}
		if (score < 5000) {
			integral.show2();
		}
	}
	if (card.equals("金卡")) {
		if (score >= 1000) {
			integral.show();
		}
		if (score < 1000) {
			integral.show2();
		}
	}
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值