一:修改手机默认语言

代码
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("中文");//输出信息}}
结果:

二:设置信用卡密码

代码:
package homework;public class ATM {//创建类String cardNum;//声明cardNumString password;//声明passwordpublic ATM(String cardNum,String password) {//主方法this.cardNum=cardNum;//设置cardNumthis.password=password;//设置passwordif(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");//重置后密码}}
结果:

三:飞速的高铁

代码:
package homework;/*** @author Dejon_D*/import java.io.PrintStream;//创建PrintStream类public class Train {//创建类final static float P=145.8f;//定义finalpublic 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型变量Ppublic huoche(float P){//方法this.P=P;//设置P的值System.out.println("火车的速度为"+P+"公里/小时");//输出信息}}class gaotie{//创建类float speed;//定义float型变量public gaotie(float speed){//方法this.speed=speed;//设置speed等于speedSystem.out.println("高铁的速度为"+speed+"公里/小时");//输出信息}}
结果:

四:计算机械钟和石英手表的时间

代码:
package homework;/**** @author Dejon_D**/public class Clock {//创建类String structure;//声明structureString style;//声明styledouble price;//声明pricepublic Clock(String structure,String style,double price) {//主方法super();//super()this.structure=structure;//设置structurethis.style=style;//设置stylethis.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();//获取时间}}
结果:

五:多功能参数(方法的重载)

代码
package java第七次作业;import java.util.Scanner;//导入Scanner方法public class one {//定义一个类static final double PI=3.141592653589793;//定义一个全局常量并赋予初值public static double add(double a,double b){//定义一个方法传入两个double型参数a,breturn(a*b);//返回a*b的值}public static double add(double r){//定义一个方法并传入一个double型参数rreturn(r*r*PI);//返回r*r*PI的值}public static void main(String[] args) {//主方法// TODO Auto-generated method stubSystem.out.println(PI);//输出PI的值System.out.println(add(4.0000001));//调用add方法并输出System.out.println(add(3.0,4.0));//调用add方法并输出}}
结果

六:输出圆形和矩形的面积


代码:
package 作业7;/**** @author Dejon_D**/class Shape {//创建Shape(图形)类final static double PI=3.1415926;//设置PIvoid s1(double r) {//定义半径double s1=r*r*PI;//圆形面积公式System.out.println("圆形面积:"+s1);//输出圆形面积}void s2(int a,int b) {//定义长和宽float s2=a*b;//矩形面积公式System.out.println("矩形面积:"+s2);//输出矩形面积}}public class 输出圆形and矩形面积 extends Shape{//主方法public static <YuanX> void main(String[] args) {//主方法Shape a=new Shape();//创建类a.s1(1.5);//圆的半径a.s2(1, 11);//矩形的长和宽}}
结果

七:定义人类的介绍方式


代码
package 作业7;/**** @author Dejon_D**/public class Human {//创建类static int age;//定义年龄public String toString() {//主方法1return "我"+age+"岁,我是";//输出内容}public static void main(String[] args) {//主方法age=18;//给age赋值为18if(age>=18) {//if语句,条件age>=18System.out.println(new Human()+"成年人");//条件成立时输出}else {//else,不符合条件System.out.println(new Human()+"未成年人");//条件不成立时输出}}}
结果

八: 编写登陆方法

代码;
package 作业7;/*** @author Dejon_D*/import java.util.Scanner;//输入函数public class Password {//创建类static boolean login(String username,String password) {//创建String类return "张三".equals(username)&&"123456".equals(password);//用户名及密码}public static void main(String[] args) {//主方法Scanner sc =new Scanner(System.in);//输入方法String username=null;//初始窗口String password=null;//初始窗口do {//do语句System.out.println("请输入用户名:");//输出:请输入用户名username =sc.nextLine();//输入用户名System.out.println("请输入密码:");//输出:请输入密码password=sc.nextLine();//输入密码}while(!login(username,password));//while语句System.out.println("-----------");//输出:---------System.out.println("登录成功");//输出:登录成功sc.close();//输入结束}}
结果;

九:人工包装的水果与普通水果的价格


代码
package 作业7;/**** @author Dejon_D**/class Past{//创建类double a[]=new double[]{1.98,5.0,0.0,9.9};//初始化价格}public class Price extends Past {//创建对象public static void main(String[]args){//主方法double b[]=new double[]{2.98,5.0,1.0,14.9};//创建对象System.out.println("水果名称 水果价格(元/千克)水果重量(千克) 包装费(元/千克) 总价 \n"+"——————————————————————————————————————————————————————————————————");//输出单位System.out.print("苹果\t");//输出:苹果Price ar=new Price();//创建对象for(int i=0;i<ar.a.length;i++){//for循环System.out.print(ar.a[i]);//输出arSystem.out.print("\t\t");//空格}System.out.println();//换行System.out.print("精装苹果");//输出:精装苹果for(int i=0;i<b.length;i++){//for循环System.out.print(b[i]);//输出bSystem.out.print("\t\t");//空格}System.out.println();//换行System.out.print("——————————————————————————————————————————————————————————————————");//分割线System.out.println();//换行System.out.print("差价\t\t\t\t\t\t\t");//输出空格double j=b[b.length-1]-ar.a[ar.a.length-1];//创建对象System.out.print(j);//输出j}}
结果:
