目录
一、修改手机默认语言
代码1:
package homework;
public class changephonelanguage {//创建类
public changephonelanguage() {//主方法
System.out.println("智能手机的默认语言为英文");//输出信息
}
public changephonelanguage(String defaultLanguage) {//主方法
System.out.println("将智能手机的默认语言设置为"+defaultLanguage);//输出信息
}
public static void main(String[] args) {//主方法
changephonelanguage changephoneLanguage1=new changephonelanguage();//更改语言
changephonelanguage changephoneLanguage2=new changephonelanguage("中文");//输出信息
}
}
运行结果1:![](https://img-blog.csdnimg.cn/f5e5107fd1d24eb4a3a7d4676dde5f53.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAREVKT05fRA==,size_20,color_FFFFFF,t_70,g_se,x_16)
二、设置信用卡密码
代码2:
package homework;
public class ATM {//创建类
String cardNum;//声明cardNum
String password;//声明password
public ATM(String cardNum,String password) {//主方法
this.cardNum=cardNum;//设置cardNum
this.password=password;//设置password
if(password.equals("123456")) {//if语句
System.out.println("信用卡"+cardNum+"的默认密码为"+password);//输出信息
}else {
System.out.println("重置信用卡"+cardNum+"的密码为"+password);//输出信息
}
}
public ATM(String cardNum) {//主方法
this(cardNum,"123456");//设置密码
}
public static void main(String[] args) {//主方法
ATM initialATM=new ATM("4013735633800642");//卡号
ATM resetedATM=new ATM("4013735633800642","168779");//重置后密码
}
}
运行结果2:
三、飞速的高铁
代码3:
package homework;
/**
* @author Dejon_D
*/
import java.io.PrintStream;//创建PrintStream类
public class Train {//创建类
final static float P=145.8f;//定义final
public static void main(String[] args) {//主方法
int a=2;//定义int型变量
float speed=P*a;//运算公式
huoche b=new huoche(P);//赋值
gaotie c=new gaotie(speed);//赋值
}
}
class huoche{//创建类
float P;//定义float型变量P
public huoche(float P){//方法
this.P=P;//设置P的值
System.out.println("火车的速度为"+P+"公里/小时");//输出信息
}
}
class gaotie{//创建类
float speed;//定义float型变量
public gaotie(float speed){//方法
this.speed=speed;//设置speed等于speed
System.out.println("高铁的速度为"+speed+"公里/小时");//输出信息
}
}
运行结果3:
四、计算机械钟和石英手表的时间
代码4:
package homework;
/**
*
* @author Dejon_D
*
*/
public class Clock {//创建类
String structure;//声明structure
String style;//声明style
double price;//声明price
public Clock(String structure,String style,double price) {//主方法
super();//super()
this.structure=structure;//设置structure
this.style=style;//设置style
this.price=price;//设置price
}
static public void getTime() {//获取时间方法
System.out.println("当前时间:10点10分");//输出时间
}
public static void main(String[] args) {//主方法
Clock bell =new Clock("机械","钟",189.99);//输出信息
System.out.println(bell.structure+bell.style+"的价格为"+bell.price+"元RMB");//输出价格
getTime();//获取时间
Clock watch=new Clock("石英","手表",69);//输出信息
System.out.println(watch.structure+watch.style+"的价格为"+watch.price+"元RMB");//输出价格
getTime();//获取时间
}
}
运行结果4:
THE END!