08_java Basic Grammar _ 8th Day (Eclipse) _ Handouts

Source: Internet
Author: User

Introduction of today's content
1. Eclipse Development Tools
2. Supermarket Inventory management System

01Eclipse Download and Installation
* A: Eclipse的下载安装       ?    * a: 下载        * http://www.eclipse.org    * b: 安装        * 只需要解压后就能使用    * c: 卸载        * 只需要将文件夹删除就可以了    * d: 注意         * 开发软件的安装目录中,尽量不要出现空格与中文* B: Eclipse的特点    * a: 免费    * b: 纯Java语言编写    * c: 免安装    * d: 扩展性强    
02Eclipse working space and new project
* A: Eclipse的工作空间和新建工程    * a: 工作空间        *  其实就是我们写的源代码所在的目录                         * b: 创建工程(项目)        * 右键/Package Explore 空白区/new /Java Project/输入项目名称如day08/                * c: 创建包(后面讲包的概念)        * 打开上面建立的day08项目/右键/new/package/在弹出的对话框的name中输入报名如"com.itheima.tests"/finish    * d: 创建类        * 创建一个java类:右击包名/new/class/在对话框的name中输入类名/finish* B: 编译与执行    * a: 编译        * 自动编译,当java代码保存的时候,自动 编译class文件    * b: 运行        * 方式1:点击菜单工具栏中的 绿色带有三角形的 run按钮 运行        * 方式2:点击菜单栏中Run, 点击Run 运行  快捷键是 ctrl+F11        * 方式3:选中要运行的java文件,或者在编写代码的空白区域,右键选择 Run As --> 运行java程序
03Eclipse of HelloWorld Writing
* A:HelloWorld编写    * a: 编写过程(参照上个知识点)        * 建立day08项目        * 建立包结构(包的概念还没有学到,不建立包的话,使用默认包结构default)        * 创建HelloWorld类(自动生成main方法)    * b: 案例代码        public class HelloWorld {            public static void main(String[] args) {                System.out.println("Hello World");            }        }        
Font settings for 04Eclipse
* A: Eclipse的字体设置    * a: 修改编译环境和运行环境        * 编译环境:Window -- Preferences – Java - Compiler        * 运行环境:Window -- Preferences – Java - Installed JREs            * b: 显示行号与隐藏行号        * 显示:在代码区域的左边空白区域,右键 -- Show Line Numbers        * 隐藏:将上面的操作再做一遍            * c: 更改字体大小与颜色        * Java代码区域的字体大小和颜色:            * window -- Preferences -- General -- Appearance -- Colors And Fonts --Java修改 -- Java Edit Text Font--edit进行修改        * 控制台            * window -- Preferences -- General -- Appearance -- Colors And Fonts -- Debug -- Console font        * 其他文件            * window -- Preferences -- General -- Appearance -- Colors And Fonts -- Basic -- Text Font            
Window settings for 05Eclipse
* A: 窗口设置    * a: 显示的窗口乱了,还原默认显示模式        * Window – Perspective -- Reset Prespective    * b: 显示控制台        * Window--Show View—Console             
06Eclipse Remove extraneous annotations
* A: Eclipse的去掉多余的注释    * a:如何去掉默认注释        * Window -- Preferences -- Java -- Code Style -- Code Templates --         * Comments – Methods,点击Edit ,将注释部分删除 (不建议删除)        * Window -- Preferences -- Java -- Code Style -- Code Templates --        *  Code -- Method body,点击Edit ,将注释部分删除    * b: 切换工作空间        * File – Switch Workspace – 指定工作空间 – ok        
07Eclipse shortcut keys
* A: Eclipse的快捷键    * a: 内容辅助键  Alt+/        * 自动补齐main方法  main 然后 Alt+/        * 自动补齐输出语句  syso 然后 Alt+/    * b: 格式化代码        * Ctrl+Shift+f        * 代码区域右键 -- Source – Format    * c: 自动导包        * Ctrl+Shift+o        * 如果当前类在多个包中都存在,这时候,使用Ctrl+shift+o,进行选择一个包导入即可。    * d: 注释        * 单行注释        ?   * 加注释: 先选中需要注释的内容,然后 Ctrl+/        ?   * 取消注释:先选中需要取消注释的内容, 然后 Ctrl+/    ?   * 多行注释        ?   * 加注释: 先选中需要注释的内容,然后 Ctrl+Shift+/        ?   * 取消注释:先选中需要取消注释的内容, 然后 Ctrl+Shift+    * e: 补充        * 代码上下移动            * 选中代码alt+上/下箭头        * 查看源码            * 选中类名(F3或者Ctrl+鼠标点击)        * 查找具体的类             * ctrl + shift + t,输入要查找的类的名称-->确定        * 查找具体类的具体方法             * ctrl + o        * 给建议             * ctrl+1,根据右边生成左边的数据类型,生成方法        * 删除代码             * ctrl + d        * 抽取方法            * alt + shift + m         * 改名            * alt + shift + r(类名,方法名,变量名)            
08Eclipse Breakpoint Debugging
* A:断点调试(又称为Debug调试)的作用    * 调试程序    * 查看程序执行流程* B:如何查看程序执行流程          * 什么是断点:        * 就是一个标记,从哪里开始。            * 如何设置断点:        * 你想看哪里的程序,你就在那个有效程序的左边双击即可。            * 在哪里设置断点:        * 哪里不会点哪里。        * 目前:我们就在每个方法的第一条有效语句上都加。            * 如何运行设置断点后的程序:        * 右键 -- Debug as -- Java Application            * 看哪些地方:        * Debug:断点测试的地方            * 在这个地方,记住F6,或者点击也可以。一次看一行的执行过程。        * Variables:查看程序的变量变化        * ForDemo:被查看的源文件        * Console:控制台            * 如何去断点:        * a:再次双击即可        * b:找到Debug视图,Variables界面,找到Breakpoints,并点击,然后看到所有的断点,最后点击那个双叉      
09Eclipse of engineering Delete and import
* A:删除项目    * 选中项目 – 右键 – 删除        * 从项目区域中删除        * 从硬盘上删除* B:导入项目    * 在项目区域右键找到import    * 找到General,展开,并找到    * Existing Projects into Workspace    * 点击next,然后选择你要导入的项目    * 注意:这里选择的是项目名称
10 Supermarket management system function introduction
* A:超市管理系统功能介绍    * a: 显示主菜单            ============欢迎光临ItCast超市============        1: 货物 清单   2: 添加货物   3: 删除货物   4: 修改货物  5: 退出        请您输入要操作的功能序号            * b: 货物清单            输入1:货物清单        ================商品库存清单================        商品编号         商品名称                商品单价        9527            少林寺酥饼核桃            12.7        9008            尚康杂粮牡丹饼            5.6        9879            新疆原产哈密瓜             599.6            * c: 添加新货物            输入2:添加新货物                   请输入新商品的编号:9523        请输入新商品的名字:斯柯达苹果醋        请输入新商品的单价:19.9        商品添加成功            * d: 删除货物            输入3:删除货物                选择的是删除功能        请输入商品的编号:9523        货物信息删除完毕            * e: 修改货物            输入4:修改货物                选择的是修改功能        请输入您要修改的商品的编号:9527        输入新的商品编号:100        输入新的商品名字:味道好凤梨干        输入新的商品价格:6.5        商品修改成功    * f: 输入5:退出系统
11 Supermarket management System case study
* A: 超市管理系统案例分析    * 完成超市商品初始化。创建商品,将商品添加到集合?   * 显示来到超市能做的操作,也就是显示主菜单?   * 根据接收到的功能选项,执行对应的功能?   * 库存货物查询?   * 添加新货物 ?   * 删除货物?   * 修改货物?   * 退出系统,结束main方法的运行?   * 循环,回到 2.显示主菜单
12 Custom Product Classes
* A: 自定义商品类    * a: 目的        * 每种库存商品都拥有多项商品信息,为了方便管理每种商品的信息,我们对商品信息进行封装,编写FruitItem.java文件    * b:案例代码        public class FruitItem {            int  ID;            //商品编号            String  name;       //商品名称            double  price;      //商品单价            double  number;     //商品数量            double  money;      //商品金额        }    * 补充        * 上述代码中,对商品信息(编号、名称、单价、数量、金额)进行了封装。        * 这样做的好处在于以后只要找到这个商品,就能够知道该商品的每项信息了。
13 Initializing Commodity properties
* A: Initialize commodity properties * A: Case code import java.util.ArrayList;        Import Java.util.Scanner; /* * Supermarket Management System Master * implementation: * 1. Initialization of commodity data * 2. User's menu selection * 3.       Perform different functions depending on the selection * 3.1 Read view item * 3.2 Create Add Item * 3.3 Delete Delete Item *        3.4 Update Modify Item * * * All functions must be defined method implementation * Main method main Call function */ public class Shopp {public static void main (string[] args) {//Create ArrayList collection, store commodity type, store data type                Fruititem type arraylist<fruititem> array = new arraylist<fruititem> ();                                Invokes the product initialization method, passing the collection init (array);             }/* * Define the method to initialize the product data * The first part of the data is stored in the collection * return value: None * Parameters: Set * Method Name: Init */public static void init (arraylist<fruititem> array{//Create multiple Fruititem types, and attribute assignment Fruititem f1 = new Fruititem ();                F1.id = 9527;                F1.name = "Shaolin Cake Walnut";                                F1.price = 12.7;                Fruititem F2 = new Fruititem ();                F2.id = 9008;                F2.name = "Changkang cereal peony cake";                                F2.price = 5.6;                Fruititem F3 = new Fruititem ();                F3.id = 9879;                F3.name = "Xinjiang Origin cantaloupe";                                F3.price = 599.6;                Created 3 fruititem type variables, stored in the collection Array.add (F1);                Array.add (F2);            Array.add (F3); }                    }
14 Main Menu function
* A: Main Menu function * A: Case code import java.util.ArrayList;        Import Java.util.Scanner; /* * Supermarket Management System Master * implementation: * 1. Initialization of commodity data * 2. User's menu selection * 3.       Perform different functions depending on the selection * 3.1 Read view item * 3.2 Create Add Item * 3.3 Delete Delete Item *        3.4 Update Modify Item * * * All functions must be defined method implementation * Main method main Call function */ public class Shopp {public static void main (string[] args) {//Create ArrayList collection, store commodity type, store data type                Fruititem type arraylist<fruititem> array = new arraylist<fruititem> ();                Invokes the product initialization method, passing the collection init (array);                         while (true) {//Call menu Method MainMenu (); }/* * Define the method, implement the main menu * Prompt the user which choice lets select the ordinal number * return value: no * parameter            Number: None */public static void MainMenu () {System.out.println ();                SYSTEM.OUT.PRINTLN ("============ Welcome to Itcast supermarket ============");                System.out.println ("1: Goods List 2: Add goods 3: Delete Goods 4: Modify goods 5: Exit");            System.out.println ("Please enter the function number you want to operate"); }/* * Define the method to initialize the product data * The first part of the data is stored in the collection * return value: None * parameter                Number: Set * Method Name: Init */public static void init (arraylist<fruititem> array) {                Multiple Fruititem types are created, and the properties are assigned fruititem f1 = new Fruititem ();                F1.id = 9527;                F1.name = "Shaolin Cake Walnut";                                F1.price = 12.7;                Fruititem F2 = new Fruititem ();                F2.id = 9008;                F2.name = "Changkang cereal peony cake";                                F2.price = 5.6;                Fruititem F3 = new Fruititem ();                F3.id = 9879;  F3.name = "Xinjiang Origin cantaloupe";              F3.price = 599.6;                Created 3 fruititem type variables, stored in the collection Array.add (F1);                Array.add (F2);            Array.add (F3);                            }                    }
15 User Selection function
* A: User Selection function * A: Case code import java.util.ArrayList;        Import Java.util.Scanner; /* * Supermarket Management System Master * implementation: * 1. Initialization of commodity data * 2. User's menu selection * 3.       Perform different functions depending on the selection * 3.1 Read view item * 3.2 Create Add Item * 3.3 Delete Delete Item *        3.4 Update Modify Item * * * All functions must be defined method implementation * Main method main Call function */ public class Shopp {public static void main (string[] args) {//Create ArrayList collection, store commodity type, store data type                Fruititem type arraylist<fruititem> array = new arraylist<fruititem> ();                Invokes the product initialization method, passing the collection init (array);                    while (true) {//Call menu Method MainMenu ();                    Call the user to select the ordinal method int choose = Choosefunction ();   Switch (choose) {Case 1://Call 1: Goods List                     Showfruitlist (array);                                        Break                    Case 2://2: Add cargo addfruit (array);                                        Break                    Case 3://3: Delete goods deletefruit (array);                                        Break                    Case 4://4: Modify the goods updatefruit (array);                                        Break                    Case 5:return;                        Default:System.out.println ("No number entered");                    Break            }}//* Define method, implement accept user's keyboard input * return number */                public static int choosefunction () {Scanner sc = new Scanner (system.in);            return Sc.nextint ();              }          /* * Define the method to implement the main menu * Prompt the user which choice lets select the ordinal number * return value: no * parameter: None * *                public static void MainMenu () {System.out.println ();                SYSTEM.OUT.PRINTLN ("============ Welcome to Itcast supermarket ============");                System.out.println ("1: Goods List 2: Add goods 3: Delete Goods 4: Modify goods 5: Exit");            System.out.println ("Please enter the function number you want to operate"); }/* * Define the method to initialize the product data * The first part of the data is stored in the collection * return value: None * parameter                Number: Set * Method Name: Init */public static void init (arraylist<fruititem> array) {                Multiple Fruititem types are created, and the properties are assigned fruititem f1 = new Fruititem ();                F1.id = 9527;                F1.name = "Shaolin Cake Walnut";                                F1.price = 12.7;                Fruititem F2 = new Fruititem ();                F2.id = 9008;                F2.name = "Changkang cereal peony cake"; F2.price =5.6;                Fruititem F3 = new Fruititem ();                F3.id = 9879;                F3.name = "Xinjiang Origin cantaloupe";                                F3.price = 599.6;                Created 3 fruititem type variables, stored in the collection Array.add (F1);                Array.add (F2);            Array.add (F3); }                    }
16 List of items function
* A: 商品的清单功能    * a: 案例代码(显示商品清单的showFruitList(ArrayList<FruitItem>)方法的代码如下)        /*         *  定义方法,实现显示货物清单功能         *  返回值: 无         *  参数: 集合         *  遍历集合,获取集合中的每个FruitItem变量,变量,调用属性         */        public static void showFruitList(ArrayList<FruitItem> array){            System.out.println();            System.out.println("================商品库存清单================");            System.out.println("商品编号         商品名称                商品单价");            //遍历集合            for(int i = 0 ; i < array.size(); i++){                //集合get方法,获取出每个FruitItem变量,可以使用FruitItem接受get结果                FruitItem item = array.get(i);                //变量item调用类中属性                System.out.println(item.ID+"   "+item.name+"        "+item.price);            }        }
17 Add function of product
* A: Product add function * A: Case code (the Code of the Addfruit (arraylist<fruititem>) method of the product add function is as follows)/* * Define the method to implement the product add function * return value: None * Parameter: Set * Prompts the user to choose the function of adding a product * * Prompt user to enter what is * * * Create Fruititem variable, variable call Property * Assigns each commodity attribute entered */public static void Addfruit (arraylist<fruititem> array) {Sy            Stem.out.println ("option to add Product function");            Create Scanner variable Scanner sc = new Scanner (system.in);            System.out.print ("Please enter the number of the new product:");            Enter the product's number int id = sc.nextint ();            Enter the name of the product System.out.print ("Please enter the name of the new product:");            String name = Sc.next ();            Enter the price of the product System.out.print ("Please enter the price of the new product:");            Double price = Sc.nextdouble ();            Create Fruititem variable Fruititem item = new Fruititem ();            Item. Property assignment item.id = ID;            Item.name = name;            Item.price = Price;            Array.add (item); SysteM.OUT.PRINTLN ("product added successfully"); }
18 Product Deletion function
* A: The product deletion function (the code to delete the product Deletefruit (arraylist<fruititem>) method is as follows) * A: Case code/* * Definition method, implement the product deletion function * Return value: no * parameter: Collection * * Delete depends on the item number * Prompt user to select the Delete function * Keyboard input Product number * Traversal set The Fruititem variable calls the property ID, and the user's input number, in contrast, is deleted */public static void Deletefruit (arraylist& Lt            Fruititem> array) {System.out.println ("select Delete function");            System.out.print ("Please enter the product number:");                        Scanner sc = new Scanner (system.in);            int ID = Sc.nextint (); Traversal set for (int i = 0; i < array.size (); i++) {//get to each Fruititem variable Fruititem it                EM = Array.get (i);                     Variable, call property ID, and user-entered number comparison if (item.id = = ID) {//Remove the elements in the collection//collection method Remove implementation                    Array.remove (i);                    System.out.println ("delete succeeded");                Return }            }           System.out.println ("The number you entered does not exist"); }
19 Product Modification function
* A: Product modification function * A: Case code (the code to modify the product Updatefruit (arraylist<fruititem>) method is as follows)/* * Define the method to implement the product modification function          * Return value: None * Parameter: Set * * Prompt user to select Modify function * Prompt user to enter product number to be modified * Traverse collection, get each fruititem variable * Variable Call ID property, attribute and user input number comparison * If same: * Modify the attribute value in the Fruititem * keyboard input */publ            IC static void Updatefruit (arraylist<fruititem> array) {System.out.println ("select Modify function");                        System.out.print ("Please enter the number of the item you want to modify:");            Scanner sc = new Scanner (system.in);            int ID = Sc.nextint ();                 Iterate through the collection, get each fruititem variable for (int i = 0; i < array.size (); i++) {Fruititem item = array.get (i); Gets the Fruititem property ID, and the user-entered ID compared to the IF (item.id = = ID) {System.out.print ("Enter new quotient                    Product number: ");                                        Item.id = Sc.nextint ();             System.out.print ("Enter a new product name:");       Item.name = Sc.next ();                    System.out.print ("Enter a new commodity price:");                    Item.price = Sc.nextdouble ();                    SYSTEM.OUT.PRINTLN ("Successful product modification");                return;        }} System.out.println ("The number entered does not exist"); }

08_java Basic Syntax _ 8th day (Eclipse) _ Handouts

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.