zoukankan      html  css  js  c++  java
  • 第十二章类的无参方法

    一.javaDoc注释:

    语法:/**

                 *

                 *@author FLC

                 */

          生成javaDoc文档的步骤:点击File——Export——展开java文件夹——选择javaDoc——点击Next——制定生成doc文档的文件位置——点击Fish——找到生成文件位置查看。

    二.类中的方法:

    语法:   访问修饰符  方法返回值类型  方法名称(){}

    例如:

    public void run(){
    }
    public String ball(){
    }
              String ball="球";
              return ball;
    }

    三.局部变量和成员变量的区别:

       1.局部变量定义在类的具体方法中,成员变量直接定义在类中。

       2.访问的作用域不同:

              成员变量只能在调用方法时才能用,成员变量在创建出类的对象时才能使用。

       3.初始值不同:

              局部变量必须给其赋值,成员变量可以不赋值,如果不赋值,java会自动给其赋初始值,如:String--null--0

    四.return关键字用途:

        1.return 代表跳出当前方法,表是方法执行结束。

        2.return 表达式:代表返回一个值或者是表达式。

    例如:如果方法没有返回值则不用加return关键字,而且返回类型为默认的void。

    五.面向对象(oo)思想:

        把重复的代码封装到一个方法中,而我们只需要知道这个方法的名称和它的用途,不需要知道方法的底层代码是如何编写,当我想要实现这个功能的时候直接调用它的方法就可以,解决了代码的重复。

    (1)package 第十二章;
    
    public class AutoLion示例1 {
        String color = "黄色";
        //跑方法
        public void run(){
            System.out.println("正在以0.1米/秒的速度向前奔跑");
        }
        //叫方法
        public void cry(){
            System.out.println("大声吼叫");
        }
        //抢球方法
        public String robBall(){
            String ball = "球";
            return ball;
        }
    }
    
    public class TestLion示例1 {
    
        public static void main(String[] args) {
             AutoLion示例1 a = new  AutoLion示例1();//调用对象
             a.run();//调用方法
             a.cry();
             System.out.println("这是一个"+a.robBall());    
        }
        }
    package 第十二章;
    
    (2)public class AutoLion示例2 {
         String color = "黄色";//颜色
         /**/
         public void run(){
             System.out.println("正在以0.1米/秒的速度向前奔跑。");
         }
         /*抢球*/
         public String robBall(){
             String ball = "球";
             return ball;
         }
         /*获的颜色*/
         public String getColor(){
             return color;
         }
         /*显示狮子特性*/
         public String showLion(){
             return "这是一个"+getColor()+"的玩具狮子!";
         }
         }
    public class TestLion示例2 {
    
        public static void main(String[] args) {
            AutoLion示例2 a = new AutoLion示例2();//创建对象
            System.out.println(a.showLion());
            a.run();//调用跑方法
            System.out.println("抢到一个"+a.robBall());
        }
    }
    (3)package 第十二章;
    
    public class Jijie {
         int yue;
         public void show(){
             if(yue>=1&&yue<=3){
                 System.out.println("该季节为春季");
        }else if(yue>=4&&yue<=6){
            System.out.println("该季节为夏季");
        }else if(yue>=7&&yue<=9){
            System.out.println("该季节为秋季");
        }else if(yue>=10&&yue<=12){
            System.out.println("该季节为冬季");
        }else{
            System.out.println("输入错误!");
            show();
        }
         }
         
       
    }
    import java.util.Scanner;
    
    public class TestJijie {
    
        public static void main(String[] args) {
            Jijie a = new Jijie();
            Scanner input = new Scanner(System.in);
            System.out.println("请输入月份:");
            a.yue = input.nextInt();
            
            a.show();
        
            
            
        }
    
    }
    (4)package 第十二章;
    
    public class Manager2 {
          String name;
          String mima;
          public void show(){
              System.out.println("管理员信息用户名为:"+name+"	"+"密码为:"+mima);
          }
    }
    public class TestManager {
    
        public static void main(String[] args) {
            Manager2 a = new Manager2();
            a.name="JadeBird";
            a.mima="0000";
            a.show();
    
        }
    
    }
    (5)package 第十二章;
    
    import java.util.Scanner;
    
    public class Menu {
        Scanner input = new Scanner(System.in);
      public void showLoginMenu(){
          System.out.println("
    	欢迎使用我行我素购物管理系统
    ");
          System.out.println("		1.登录
    ");
          System.out.println("		2.退出
    ");
          System.out.println("* ** * * * * * * * * * * * * * *");
          System.out.println("请选择,输入数字:");
          int num=input.nextInt();
          switch(num){
             case 1:
                showMainMenu();
                 break;
             case 2:
                    System.out.println("退出");
                     break;
             default:
                 System.out.println("输入错误。");
                 break;    
          }
      }
      public void showMainMenu(){
          System.out.println("
    	我行我素购物管理系统主菜单 ");
          System.out.println("* ** * * * * * * * * * * * * * *");
          System.out.println("		1.客户信息管理");
          System.out.println("		2.真情回馈");
          System.out.println("* ** * * * * * * * * * * * * * *");
          System.out.println("请选择,输入数字或按0返回上一级菜单:");
          boolean con;
          do{
              con = false;
              Scanner input = new Scanner(System.in);
              int no = input.nextInt();
              if(no == 1){
                  System.out.println("输入错误。");
              }else if(no==2){
                  showSendGMenu();
              }else if(no==0){
                  showLoginMenu();
          }else{
              System.out.println("输入错误,请重新输入数字:");
              con = true;
          }      
        }while(con);
    }
    
       public void showSendGMenu(){
           System.out.println("我行我素购物管理系统> 真情回馈");
           System.out.println("* ** * * * * * * * * * * * * * *");
           System.out.println("		1.幸运大放送");
           System.out.println("		2.幸运抽奖");
           System.out.println("		3.生日问候");
           System.out.println("* ** * * * * * * * * * * * * * *");
           System.out.println("请选择,输入数字或按0返回上一级菜单:");
           boolean con;
           do{
               con = false;
               Scanner input = new Scanner(System.in);
               int no = input.nextInt();
               if(no==1){
                   System.out.println("执行幸运大放送");
               }else if(no==2){
                   System.out.println("执行幸运抽奖");
               }else if(no==3){
                   System.out.println("执行生日问候");
               }else if(no==0){
                   showMainMenu();
               }else{
                   System.out.println("输入错误,请重新输入:");
                   con = true;
               }
           }while(con);
    }
    }
    import java.util.Scanner;
    
    public class TestMenu {
    
        public static void main(String[] args) {
           boolean con=true;
           do{
               Menu menu = new Menu();
               menu.showLoginMenu();
        Scanner input = new Scanner(System.in);
        int choice = input.nextInt();
        switch(choice){
           case 1:
               menu.showMainMenu();
               break;
           case 2:
               System.out.println("谢谢您的使用!");
               con=false;
               break;
        }   
           }while(con);
        }
    }
      
      
      
    (6)package 第十二章;
    
    import java.util.Scanner;
    
    public class StartSMS {
        Scanner input = new Scanner(System.in);
        public void showLoginMenu(){
            System.out.println("
    	欢迎使用我行我素购物管理系统");
            System.out.println("		1.登录系统");
            System.out.println("		2.退出");
            System.out.println("* * * * * * * * * * * * * * * * *");
            System.out.println("请选择,输入数字:");
            int num = input.nextInt();
            System.out.println("请输入用户名:");
            String name = input.next();
            System.out.println("请输入密码:");
            String mima = input.next();
             if(name.equals("JadeBird") && mima.equals("0000")){
                    System.out.println("@@登录成功,JadeBird@@");
                    System.out.println("
    	我行我素购物管理系统");
                    System.out.println("* * * * * * * * * * * * * * * * *");
                    System.out.println("		1.客户信息管理");
                    System.out.println("		2.真情回馈");
             }else{
                    System.out.println("@@您没有权限进入系统,请重新登录。@@");
              switch(num){
                 case 1:
                     showLoginMenu();
                     break;
                 case 2:
                     System.out.println("退出");
                     break;
                 default:
                     System.out.println("输入错误");
                     break;
              }
                    
             }    
              }
        }
        import java.util.Scanner;
    
    public class TestStartSMS {
    
        public static void main(String[] args) {
            StartSMS a = new StartSMS();
               a.showLoginMenu();
                Scanner input = new Scanner(System.in);
                int choice = input.nextInt();
                switch(choice){
                   case 1:
                       a.showLoginMenu();
                       break;
                   case 2:
                       System.out.println("谢谢您的使用!");
                       break;
                }   
        
              
    
        }
    
    }
        标         签       含                 义     标         签       含                义
          @author        作者名         @version         版本标识
          @parameter           参数及其意义         @since           最早使用该方法/类/接口的JDK版本
        @return           返回值          @throws           异常类及抛出条件
  • 相关阅读:
    第三部分 学习shell与shell scipt---第九章 vim程序编辑器
    端口映射与容器互联
    在web工程中如何查看编译后class路径
    Spring配置JDBC连接Orcale、MySql、sqlserver
    org.springframework.beans.factory.BeanNotOfRequiredTypeException错误
    windows系统中如何启动两个tomcat
    eclipse+maven搭建SSM框架
    windows下安装和配置多个版本的JDK
    java环境变量为1.7jdk为何在dos窗口中查看版本为1.8
    查看jdk、eclipse、tomcat的是32位还是64
  • 原文地址:https://www.cnblogs.com/1402380606HZ/p/7349805.html
Copyright © 2011-2022 走看看