zoukankan      html  css  js  c++  java
  • 2017.12.6T19_B2_3.2 zuoye

    package com.whxiong.work03;

    import java.util.Scanner;

    public class Student {
     String name;
     int age;
     Scanner input = new Scanner(System.in);

     public void setAge(String name, int age) {
      System.out.println("请输入您的年龄:");
      age = input.nextInt();
      if (age < 16) {
       do {
        System.out.println("您输入的年龄不正确,请重新输入!");
        System.out.println("请输入您的年龄:");
        age = input.nextInt();
       } while (age < 16);
      }
      this.age = age;
     }

     public void showStudent() {
      System.out.println("大家好!我叫:" + name + ",今年" + this.age + "岁!");
      System.out.println("欢迎您" + name + "学员!");
     }

    }****************************************************************

    package com.whxiong.work03;

    import java.util.Scanner;

    public class Student2 {
     private String name;
     private int age;
     private String sex;
     private String major;
     Scanner input = new Scanner(System.in);
     //带参构造
     public Student2(String name,int age) {
      this.name = name;
      this.age = age;
      this.sex = "男";
      this.major = "Java";
     }

     public void showSt1() {
      System.out.println("大家好,我叫" + this.name + ",我是" + this.sex + "生!");
      System.out.println(" 今年" + this.age + "岁,我的专业是" + this.major);
     }
     //有参构造
     public Student2(String name, int age, String sex, String major) {
      this.name = name;
      this.age = age;
      this.sex = sex;
      this.major = major;
     }

     public void showSt2() {
      System.out.println("大家好,我叫" + this.name + ",我是" + this.sex + "生!");
      System.out.println(" 今年" + this.age + "岁,我的专业是" + this.major);
     }

    }**********************************************************************************

    package com.whxiong.work03;

    import java.util.Scanner;

    public class Work03 {

     /**
      * @param args
      */
     public static void main(String[] args) {
      Scanner input = new Scanner(System.in);

      System.out.println("第四题");
      System.out.println("******************************");
      Student st = new Student();
      System.out.println("请输入您的姓名:");
      st.name = input.next();
      st.setAge(st.name,st.age);
      st.showStudent();

      System.out.println(" ");
      System.out.println("第五题");
      System.out.println("******************************");
      
      
      System.out.println("请输入您的姓名:");
      String name1 = input.next();
      System.out.println("请输入您的年龄:");
      int age = input.nextInt();
      System.out.println("请输入您的性别:");
      String sex = input.next();
      System.out.println("请输入您的专业:");
      String major = input.next();
      Student2 st2 = new Student2(name1,age);
      st2.showSt1();
      Student2 st3 = new Student2(name1,age,sex,major);
      st3.showSt2();

     }
    }

  • 相关阅读:
    如何将网页变成灰色的.
    页面中的传参介质(ViewState,Session,Items),Dictionary的用法.
    CSS控制Table单元格强制换行与强制不换行
    网页效果大集合
    结合ashx来在DataGrid中显示从数据库中读出的图片
    Atlas学习手记(29):JavaScript面向对象的扩展(三):接口Interface
    FormView中EditItemTemplate的注意事项
    javascript基本和常用的东西
    eclipse X11 xming 打造window下的linux c++开发环境
    转一篇软件测试方面的思考小文
  • 原文地址:https://www.cnblogs.com/xiaoxiao1016/p/7991501.html
Copyright © 2011-2022 走看看