day12
package com.atguigu.java;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

/*

  • 1.补全代码的声明:alt + /
    2.快速修复: ctrl + 1
    3.批量导包:ctrl + shift + o
    4.使用单行注释:ctrl + /
    5.使用多行注释: ctrl + shift + /
    6.取消多行注释:ctrl + shift +
    7.复制指定行的代码:ctrl + alt + down 或 ctrl + alt + up
    8.删除指定行的代码:ctrl + d
    9.上下移动代码:alt + up 或 alt + down
    10.切换到下一行代码空位:shift + enter
    11.切换到上一行代码空位:ctrl + shift + enter
    12.如何查看源码:ctrl + 选中指定的结构 或 ctrl + shift + t
    13.退回到前一个编辑的页面:alt + left
    14.进入到下一个编辑的页面(针对于上面那条来说的):alt + right
    15.光标选中指定的类,查看继承树结构:ctrl + t
    16.复制代码: ctrl + c
    17.撤销: ctrl + z
    18.反撤销: ctrl + y
    19.剪切:ctrl + x
    20.粘贴:ctrl + v
    21.保存: ctrl + s
    22.全选:ctrl + a
    23.格式化代码: ctrl + shift + f
    24.选中数行,整体往后移动:tab
    25.选中数行,整体往前移动:shift + tab
    26.在当前类中,显示类结构,并支持搜索指定的方法、属性等:ctrl + o
    27.批量修改指定的变量名、方法名、类名等:alt + shift + r
    28.选中的结构的大小写的切换:变成大写: ctrl + shift + x
    29.选中的结构的大小写的切换:变成小写:ctrl + shift + y
    30.调出生成getter/setter/构造器等结构: alt + shift + s
    31.显示当前选择资源(工程 or 文件)的属性:alt + enter
    32.快速查找:参照选中的Word快速定位到下一个 :ctrl + k
    33.关闭当前窗口:ctrl + w
    34.关闭所有的窗口:ctrl + shift + w
    35.查看指定的结构使用过的地方:ctrl + alt + g
    36.查找与替换:ctrl + f
    37.最大化当前的View:ctrl + m
    38.直接定位到当前行的首位:home
    39.直接定位到当前行的末位:end
    */
    public class EclipsceKeys {

    public static void main(String[] args) {

    String s = new String();
    String str = new String();
    char c =  str.charAt(0);
    int num = 1;
    
    ArrayList list = new ArrayList();
    list.add(123);
    HashMap map = null;
    Date date = new Date(32323232344L);
    System.out.println();
    

    }
    }

//方法的设置
package com.atguigu.p2.bean;

public class Customer {
	public static void main(String[] args) {
		Customer customer = new Customer();

	}

	private String name;// :客户姓名
	private char gender;// :性别
	private int age; // :年龄
	private String phone;// :电话号码
	private String email;// :电子邮箱
	
	public Customer() {
		
	} 
	public Customer(String name, char gender, int age, String phone, String email) {
		this.name = name;
		this.gender = gender;
		this.age = age;
		this.phone = phone;
		this.email = email;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public char getGender() {
		return gender;
	}
	public void setGender(char gender) {
		this.gender = gender;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}

}
//方法列表的设置
package com.atguigu.p2.service;

import com.atguigu.p2.bean.Customer;

public class CustomerList {
	   private	Customer[] customers;//用来保存客户对象的数组
	   private 	int total;//记录已保存客户对象的数量
       
	   /**
	    * 用来初始化customres数组的构造器
	    * @param totalCustomer:指定数组的长度
	    */
	   public CustomerList(int totalCustomer) {
		   customers = new Customer[totalCustomer];
	   }
	   /**
	    * @Description 将指定的客户添加到数组中
	    * @author wmcstart
	    * @date 2025年10月21日下午15:02:11
	    * @param customer
	    * @return true:添加成功 false:添加失败
	    */
	   public boolean addCustomer(Customer customer) {
		   if(total >= customers.length) {
			   return false;
		   }
		   
//		   customer[total] = customer;
//		   total++;
		   //或
		   customers[total++] = customer;
		   return true;
	   }
	   /**	     
	    * @Description 修改指定索引位置的客户信息
	    * @author wmcstart
	    * @date 2025年10月21日下午15:02:11
	    * @param index
	    * @return true:添加成功 false:添加失败
	    */
	   public boolean replaceCustomer(int index, Customer cust) {
		   
		   if(index < 0 || index >= total) {
			   return false;
		   }
		   
		   customers[index] = cust;
		   return true;
	   }
	   /**	     
	    * @Description 删除指定索引位置的客户信息
	    * @author wmcstart
	    * @date 2025年10月21日下午15:02:11
	    * @param index
	    * @return true:添加成功 false:添加失败
	    */
	   public boolean deleteCustomer(int index) {
		   if(index > 0 || index >= total) {
			   return false;
		   }
		   for(int i = index;i < total - 1;i++) {
			   customers[i] = customers[i + 1];
		   }
		   
		   customers[--total] = null;
		   return true;
	   }
	   /**	     
	    * @Description 获取所有的客户信息
	    * @author wmcstart
	    * @date 2025年10月21日下午15:02:11
	    * @return 
	    */
	   public Customer[] getAllCustomers() {
//		   return cusomers;
		   
		   Customer[] custs = new Customer[total];
		   for(int i = 0;i < total;i++) {
			   custs[i] = customers[i];
		   }
		   return custs;
	   }
	   /**	     
	    * @Description 获取指定索引位置的客户
	    * @author wmcstart
	    * @date 2025年10月21日下午15:02:11
	    * @param index
	    * @return 如果找到了元素,则返回,如果没有找到,则返回null
	    */
	   public Customer getCustomer(int index) {
		   if(index < 0 || index >= total) {
			   return null;
		   }
		   return customers[index];
	   }
        /**
         * 
         * @return
         */
		public int getTotal() {
//            return total;
			return customers.length;//错误的
		}

}
// 调用方法的视图操作
package com.atguigu.p2.ui;
import java.util.*;

import com.atguigu.p2.service.CustomerList;
import com.atguigu.p2.util.CMUtility;
/**
 * @Description CustomerView为主模块,负责菜单的显示和处理用户操作
 * @author wmcstart
 * @date 2025年10月21日下午15:02:11
 */
public class CustomerView {

	private CustomerList customerList = new CustomerList(10);

	/**
	 * @Description 修改指定索引位置的客户信息
	 * @author wmcstart
	 * @date 2025年10月21日下午15:02:11
	 * @param index
	 * @return true:添加成功 false:添加失败
	 */
	public void enterMainMenu() {
		boolean isFlag = true;
		while(isFlag) {
		System.out.println("\n-----------------客户信息管理软件-----------------\n");
		System.out.println("                   1 添 加 客 户");
		System.out.println("                   2 修 改 客 户");
		System.out.println("                   3 删 除 客 户");
		System.out.println("                   4 客 户 列 表");
		System.out.println("                   5 退  出\n");
		System.out.print("                   请选择(1-5):");
		
		char menu = CMUtility.readMenuSelection();
		switch(menu){
		case '1':
			addNewCustomer();
			break;
		case '2':
			modifyCustomer();
			break;
		case '3':
			deleteCustomer();
			break;
		case '4':
			listAllCustomers();
			break;
		case '5':
			System.out.println("退出");
			
		}
//		isFlag = false;
		}
	}

	/**
	 * @Description 添加客户的列表操作
	 * @author wmcstart
	 * @date 2025年10月21日下午15:02:11
	 * @param index
	 * @return true:添加成功 false:添加失败
	 */
	private void addNewCustomer() {
        System.out.println("添加客户的操作");
	}

	/**
	 * @Description 修改客户的列表操作
	 * @author wmcstart
	 * @date 2025年10月21日下午15:02:11
	 * @param index
	 * @return true:添加成功 false:添加失败
	 */
	private void modifyCustomer() {
		System.out.println("修改客户的列表操作");           
	}

	/**
	 * @Description 删除客户的列表操作
	 * @author wmcstart
	 * @date 2025年10月21日下午15:02:11
	 * @param index
	 * @return true:添加成功 false:添加失败
	 */
	private void deleteCustomer() {
		System.out.println("删除客户的列表操作");
	}

	/**
	 * @Description 客户的列表操作
	 * @author wmcstart
	 * @date 2025年10月21日下午15:02:11
	 * @param index
	 * @return true:添加成功 false:添加失败
	 */
	private void listAllCustomers() {
		System.out.println("客户的列表操作");
	}

	/**
	 * @Description 修改指定索引位置的客户信息
	 * @author wmcstart
	 * @date 2025年10月21日下午15:02:11
	 * @param index
	 * @return true:添加成功 false:添加失败
	 */
	public static void main(String[] args) {
        CustomerView view = new CustomerView();
        view.enterMainMenu();
	}
}

//调用的方法
package com.atguigu.p2.util;

import java.util.*;
	/**
	CMUtility工具类:
	将不同的功能封装为方法,就是可以直接通过调用方法使用它的功能,而无需考虑具体的功能实现细节。
	*/
	public class CMUtility {
	    private static Scanner scanner = new Scanner(System.in);
	    /**
		用于界面菜单的选择。该方法读取键盘,如果用户键入’1’-’5’中的任意字符,则方法返回。返回值为用户键入字符。
		*/
		public static char readMenuSelection() {
	        char c;
	        for (; ; ) {
	            String str = readKeyBoard(1, false);
	            c = str.charAt(0);
	            if (c != '1' && c != '2' && 
	                c != '3' && c != '4' && c != '5') {
	                System.out.print("选择错误,请重新输入:");
	            } else break;
	        }
	        return c;
	    }
		/**
		从键盘读取一个字符,并将其作为方法的返回值。
		*/
	    public static char readChar() {
	        String str = readKeyBoard(1, false);
	        return str.charAt(0);
	    }
		/**
		从键盘读取一个字符,并将其作为方法的返回值。
		如果用户不输入字符而直接回车,方法将以defaultValue 作为返回值。
		*/
	    public static char readChar(char defaultValue) {
	        String str = readKeyBoard(1, true);
	        return (str.length() == 0) ? defaultValue : str.charAt(0);
	    }
		/**
		从键盘读取一个长度不超过2位的整数,并将其作为方法的返回值。
		*/
	    public static int readInt() {
	        int n;
	        for (; ; ) {
	            String str = readKeyBoard(2, false);
	            try {
	                n = Integer.parseInt(str);
	                break;
	            } catch (NumberFormatException e) {
	                System.out.print("数字输入错误,请重新输入:");
	            }
	        }
	        return n;
	    }
		/**
		从键盘读取一个长度不超过2位的整数,并将其作为方法的返回值。
		如果用户不输入字符而直接回车,方法将以defaultValue 作为返回值。
		*/
	    public static int readInt(int defaultValue) {
	        int n;
	        for (; ; ) {
	            String str = readKeyBoard(2, true);
	            if (str.equals("")) {
	                return defaultValue;
	            }

	            try {
	                n = Integer.parseInt(str);
	                break;
	            } catch (NumberFormatException e) {
	                System.out.print("数字输入错误,请重新输入:");
	            }
	        }
	        return n;
	    }
		/**
		从键盘读取一个长度不超过limit的字符串,并将其作为方法的返回值。
		*/
	    public static String readString(int limit) {
	        return readKeyBoard(limit, false);
	    }
		/**
		从键盘读取一个长度不超过limit的字符串,并将其作为方法的返回值。
		如果用户不输入字符而直接回车,方法将以defaultValue 作为返回值。
		*/
	    public static String readString(int limit, String defaultValue) {
	        String str = readKeyBoard(limit, true);
	        return str.equals("")? defaultValue : str;
	    }
		/**
		用于确认选择的输入。该方法从键盘读取‘Y’或’N’,并将其作为方法的返回值。
		*/
	    public static char readConfirmSelection() {
	        char c;
	        for (; ; ) {
	            String str = readKeyBoard(1, false).toUpperCase();
	            c = str.charAt(0);
	            if (c == 'Y' || c == 'N') {
	                break;
	            } else {
	                System.out.print("选择错误,请重新输入:");
	            }
	        }
	        return c;
	    }

	    private static String readKeyBoard(int limit, boolean blankReturn) {
	        String line = "";

	        while (scanner.hasNextLine()) {
	            line = scanner.nextLine();
	            if (line.length() == 0) {
	                if (blankReturn) return line;
	                else continue;
	            }

	            if (line.length() < 1 || line.length() > limit) {
	                System.out.print("输入长度(不大于" + limit + ")错误,请重新输入:");
	                continue;
	            }
	            break;
	        }

	        return line;
	    }
	}

//关于如何写CustomerList类的搭建
1.构造器:customer = new Customer[totalCustomer];
2.方法1(将指定客户添加到数组中):通过形参(int index,int cust);而后如果不满足条件的话(index < 0 || index >= total)customer[index] = cust
3.删除此类)难点:数组是有序的:for循环的思路:想将删除的数据删除后,由后面的数据+1位置数据顶上去。如何构造这个数组?而后:还需要将内存置空,同时还需要--索引完成。
4.获取值:我们只想要创建的数据,
5.getCustomer(int index)获取get索引位置,同时返回指定索引的数字。
6.获取存储的客户数量:直接return 来返回total;

关于如何使用CustomerView
使用的方法:想要调用方法就需要先创建该类的方法的引用,然后选择需要调用的方法。
如何去构建视图逻辑?
CustomerView为主模块,负责菜单的显示和处理用户操作
本类封装以下信息:
CustomerList customerList = new CustomerList(10);
	创建最大包含10个客户对象的CustomerList 对象,供以下各成员方法使用。
该类至少提供以下方法:
/**
	 * 显示《客户信息管理软件》界面的方法
	 * @Description
	 * @author wmcstart
	 * @date 2025年10月24日17:32:12
	 */
public void enterMainMenu() 
/**
	 * 
	 * @Description 添加客户的操作
	 * @author wmcstart
	 * @date 2025年10月24日17:44:13
	 */
private void addNewCustomer() 
	/**
	 * 
	 * @Description 修改客户的操作
	 * @author wmcstart
	 * @date 2025年10月24日17:44:13
	 */
private void modifyCustomer()
/**
	 * 
	 * @Description 删除客户的操作
	 * @author wmcstart
	 * @date 2025年10月24日17:44:13
	 */
private void deleteCustomer()
/**
	 * 
	 * @Description 显示客户列表的操作
	 * @author wmcstart
	 * @date 2025年10月24日17:44:13
	 */
private void listAllCustomers()
/*
* 引用入口的使用
*/
public static void main(String[] args)

import java.util.Scanner;

/*
 * 今天(去超市买香蕉)
 * 一把香蕉价格是(20)
 * 我身上有(10.5)
 * 我去ATM机上取钱
 * ATM机提示(请输入您要取的金额)
 * 我输入了(100)
 * ATM机提示:取钱成功,是否打印凭条
 * 我选择了(true)
 */
public class Xianjiao {
	public static void main(String[] args) {
    	String jiaohua = "去超市买香蕉";
    	int salary = 20;
    	double q = 10.5;
    	String jinge = "请输入您要取的金额";
    	boolean t = false;
		System.out.println("今天"+ jiaohua);
		System.out.println("一把香蕉价格是"+ salary);
		System.out.println("我身上有"+ q);
		System.out.println("我去ATM机上取钱");
		System.out.println("ATM机提示"+jinge);
		System.out.println("ATM机提示:取钱成功,是否打印凭条");
		System.out.println("我选择了"+ t);
		
		//现在我想要实现的是:
		/*
        * (我去)ATM机上取钱:
	    * ATM机提示(请输入您要取的金额)
	    * 我输入了(100)
	    * ATM机提示:取钱成功,是否打印凭条
	    * 我选择了(true)
		 */
		String li = "(小李)";
		boolean ss = true;
	    System.out.println(li+"想去银行ATM机取钱");
	    
		System.out.println(li+"来到银行后"+"\r"+"ATM机:(请输入您要取的金额)注:\r1.查询:\r2.业务:\r3.其他:\r4.取款:(请输入您要取得金额)");
		Scanner scan = new Scanner(System.in);
		int s = scan.nextInt();
		while(s == 4){
			switch (s){
			case 1:
				System.out.println("1.查询");
				break;
			case 2:
				System.out.println("2.业务");
				break;
			case 3:
				System.out.println("3.其他");
				break;
			case 4:
				System.out.println("请输入金额:");
				int i = scan.nextInt();
				System.out.println("我输入了"+ i);
				System.out.println("请输入是否打印凭条:是/1,否/0");
				int ll = scan.nextInt();
				if(ll == 1 ? ss: t) {
					System.out.println("取钱成功,是否打印凭条" + ss);
				}else {
					System.out.println("取钱成功,是否打印凭条" + t);
				}
				break;
			default:
				System.out.println("输入有误,重新插卡");
			}
			s--;
		}
		
	}
}

继承性的理解:(extends)继承性、多态性
一、继承性的好处
① 减少了代码的冗余,提高了代码的复用性
② 便于功能的 扩展
③ 为之后多态性的使用,提供了前提
一、 继承性的格式:class A extends B{}A继承B,``A只需要再添加新的属性方法。``
A:子类、派生类、subclass
B:父类、超类、基类、superclass

体现:一旦子类A继承父类B以后,子类A种就获取了父类B中声明的结构:属性、方法

再次学习后决定尝试自己写项目,明天开始着手写

posted on 2025-10-20 18:01  超哥进阶之路  阅读(15)  评论(0)    收藏  举报