//1.
class phone1 {
private String language = "英文"; //设置默认语言为英语
public phone1() {
System.out.println("智能手机的默认语言为" + language); //输出
}
public phone1(String language) {
this.language = language; //赋值
System.out.println("智能手机的默认语言设置为" + language); //输出
}
}
public class Main {
public static void main(String[] args) {
phone1 p = new phone1(); //默认的语言
phone1 p1 = new phone1("中文"); //改变语言
}
}
//2.
class card{
private String kahao; //卡号
private int password = 123456; //默认密码
//4013735633800642
public card(String kahao) {
super();
this.kahao = kahao; //赋值
System.out.println("信用卡" + kahao + "的默认密码" + password); //输出
}
public card(String kahao,int password) {
super();
this.kahao = kahao; //赋值
this.password = password; //赋值
System.out.println("重置信用卡" + kahao + "的密码" + password); //输出
}
}
public class Main {
public static void main(String[] args) {
card p = new card("4013735633800642"); //默认密码
card p1 = new card("4013735633800642",168779); //修改后的密码
}
}
//3.
class train{
double velocity; //速度
public train() {
super();
}
public train(double velocity) { //火车
super();
this.velocity = velocity; //赋值
System.out.println("火车的速度为" + velocity + "公里/小时"); //输出
}
}
class gt extends train{ //高铁
public gt(double velocity) {
super();
this.velocity = velocity; //赋值
System.out.println("火车的速度为" + 2*velocity + "公里/小时"); //输出
}
}
public class Main{
public static void main(String[] args) {
train t = new train(125.5); //速度为125.5
gt g = new gt(125.5); //高铁速度
}
}
//4.
class table{
String name; //名字
double price; //价格
String time = "10时10分";
public table(String name, double price) {
super();
this.name = name; //赋值
this.price = price; //赋值
System.out.println(name + "的价格为" + price + "元RMB"); //输出
System.out.println("当前时间为" + time); 输出
}
}
public class Main{
public static void main(String[] args) {
table t = new table("机械钟",189.99); //机械钟
table t1 = new table("石英手表",69.0); //石英手表
}
}
//5.
class sc{
double p = 3.141592653589793; //
double r; //半径
double c; //长
double k; //宽
public sc() {
super();
System.out.println(p);
}
public sc(double r) { //圆
super();
this.r = r; //赋值
System.out.println(p * r * r); //输出
}
public sc(double c, double k) { //矩形
super();
this.c = c; //赋值
this.k = k; //赋值
System.out.println(c * k); //输出
}
}
public class Main{
public static void main(String[] args) {
sc s = new sc(); //空
sc s1 = new sc(2); //圆面积
sc s2 = new sc(3,4); //矩形面积
}
}
//6.
class Shape{
double p = 3.141592653589793;
double r; //半径
double c; //长
double k; //宽
public Shape() {
super();
}
public Shape(double r) { //圆
super();
this.r = r; //赋值
System.out.println(p * r * r); //输出面积
}
public Shape(double c, double k) {
super();
this.c = c; //赋值
this.k = k; //赋值
System.out.println(c * k); //面积
}
}
class yuan extends Shape{ //继承
public yuan(double r) {
super();
this.r = r;
System.out.println(p * r * r);
}
}
class jx extends Shape{ //继承
public jx(double c, double k) {
super();
this.c = c;
this.k = k;
System.out.println(c * k);
}
}
public class Main{
public static void main(String[] args) {
yuan y = new yuan(3); //圆面积
jx j = new jx(3,4); //矩形面积
}
}
//7.
class people{
int age; //年龄
public people() {
super();
}
public people(int age) {
super();
this.age = age; //赋值
}
public String toString(){
if(age >= 18) { //判断年龄
return "我" + age + "岁,我是成年人。";
}else {
return "我" + age + "岁,我是未成年人。";
}
}
}
public class Main{
public static void main(String[] args) {
people p = new people(18);//年龄为18
System.out.println(p);
}
}
//8.
class dl{
String name; //用户名
int password; //密码
public dl() {
super();
Scanner sc = new Scanner(System.in);
System.out.println("请输入用户名:");
String a = sc.next();
System.out.println("请输入密码:");
int b = sc.nextInt();
System.out.println("----------------");
if(b == 123456) { //判断密码是否正确
System.out.println("登陆成功");
}else {
System.out.println("登陆失败");
}
}
}
public class Main{
public static void main(String[] args) {
dl d = new dl();
}
}
//9.
class pg{
String name; //名字
double jg; //价格
double zl; //重量
double bzf; //包装费
double zj; //总价
public pg() {
super();
}
public pg(String name, double jg, double zl, double bzf) {
super();
this.name = name;
this.jg = jg;
this.zl = zl;
this.bzf = bzf;
this.zj = jg * zl + bzf;
System.out.println("水果名称" + " " + "水果价格(元/千克)" + " " + "水果重量(千克)" + " " + "包装费(元/千克)" + " " + "总价");
System.out.println("------------------------------------------------------");
System.out.println(name + " " + jg + " " + zl + " " + bzf + " " + this.zj); //输出
}
}
class jzpg extends pg{
public jzpg(String name, double jg, double zl, double bzf,double zj) {
super();
this.name = name;
this.jg = jg;
this.zl = zl;
this.bzf = bzf;
this.zj = jg * zl + bzf;
System.out.println(name + " " + jg + " " + zl + " " + bzf + " " + this.zj); //输出
System.out.println("------------------------------------------------------"); //输出
System.out.println("差价" + " " + (this.zj - zj)); //输出
}
}
public class Main{
public static void main(String[] args) {
pg p = new pg("苹果",1.98,5.0,0.0); //传入信息
jzpg p1 = new jzpg("精装苹果",2.98,5.0,1.0,p.zj); //传入信息
}
}
//10.
interface wenhou{
public void draw(); //抽象类问候
}
interface gongzhuo{
public void draw(); //抽象类工作
}
class student implements wenhou{
public void draw() { //方法的重载
System.out.println("peter:老师好"); //输出
System.out.println("mike:同学们好"); //输出
}
}
class teacher implements gongzhuo{
public void draw() { //方法的重载
System.out.println("mike:老师开始上课"); //输出
System.out.println("peter:同学开始记笔记"); //输出
}
}
public class Main{
public static void main(String[] args) {
student s = new student();
s.draw();
teacher t = new teacher();
t.draw();
}
}
//11.
class mother{
public void hobby() { //爱好
System.out.println("看电视"); //输出
System.out.println("做饭"); //输出
};
}
interface father{
public void hobby();
}
class son extends mother implements father{
public void hoppy1() {
System.out.println("抽烟"); //输出
System.out.println("钓鱼"); //输出
}
}
public class Main {
public static void main(String[] args) {
son s = new son();
System.out.println("儿子的爱好有:");
s.hobby();
s.hoppy1();
}
}