Eclipse快捷键
Eclipse中的快捷键:
* 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
项目二



Customer
package com.atguigu.java.cust;
public class 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;
}
}
CustomerList
package com.atguigu.java.custlist;
import com.atguigu.java.cust.Customer;
public class CustomerList {
private Customer[] customers;
private int total = 0;
public CustomerList() {
}
public CustomerList(int totalCustomer) {
customers = new Customer[totalCustomer];
}
public boolean addCustomer(Customer customer) {
if (total >= customers.length) {
return false;
}
customers[total++] = customer;
return true;
}
public boolean replaceCustomer(int index, Customer cust) {
if (index <= 0 || index > total) {
return false;
}
customers[index - 1] = cust;
return true;
}
public boolean deleteCustomer(int index) {
if (index <= 0 || index > total) {
return false;
}
for (int i = index - 1; i < customers.length - 1; i++) {
customers[i] = customers[i + 1];
}
customers[customers.length - 1] = null;
return true;
total--;
}
public Customer[] getAllCustomers() {
return customers;
}
public Customer getCustomer(int index) {
if (index <= 0 || index > total) {
return null;
}
return customers[index - 1];
}
public int getTotal() {
return total;
}
}
CustomerView
package com.atguigu.java.custview;
import com.atguigu.java.cust.Customer;
import com.atguigu.java.custlist.CustomerList;
import com.atguigu.p2.CMUtility;
public class CustomerView {
CustomerList customerList = new CustomerList(10);
public CustomerView() {
String name = "华东";
char gender = '男';
int age = 19;
String phone = "13012341234";
String email = "1234@qq.com";
customerList.addCustomer(new Customer(name, gender, age, phone, email));
customerList.addCustomer(new Customer(name, gender, age, phone, email));
customerList.addCustomer(new Customer(name, gender, age, phone, email));
customerList.addCustomer(new Customer(name, gender, age, phone, email));
customerList.addCustomer(new Customer(name, gender, age, phone, email));
customerList.addCustomer(new Customer(name, gender, age, phone, email));
customerList.addCustomer(new Customer(name, gender, age, phone, email));
customerList.addCustomer(new Customer(name, gender, age, phone, email));
customerList.addCustomer(new Customer(name, gender, age, phone, email));
customerList.addCustomer(new Customer(name, gender, age, phone, email));
}
public void enterMainMenu() {
while (true) {
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 custSelected = CMUtility.readMenuSelection();
switch (custSelected) {
case '1':
addNewCustomer();
break;
case '2':
modifyCustomer();
break;
case '3':
deleteCustomer();
break;
case '4':
listAllCustomers();
break;
case '5':
System.out.print("确认是否退出(Y/N): ");
char confirmResult = CMUtility.readConfirmSelection();
if (confirmResult == 'Y') {
System.out.println("\nBye~~");
return;
}
}
}
}
private void addNewCustomer() {
if(customerList.getAllCustomers().length == customerList.getTotal()){
System.out.println("当前人数已满");
return;
}
System.out.println("\n---------------------添加客户--------------------");
System.out.print("姓名: ");
String name = CMUtility.readString(10);
System.out.print("性别: ");
char gender = CMUtility.readChar();
System.out.print("年龄: ");
int age = CMUtility.readInt();
System.out.print("电话: ");
String phone = CMUtility.readString(11);
System.out.print("邮箱: ");
String email = CMUtility.readString(30);
boolean isFlag = customerList.addCustomer(new Customer(name, gender, age, phone, email));
if (isFlag) {
System.out.println("---------------------添加完成--------------------");
} else {
System.out.println("---------------------添加失败--------------------");
}
}
private void modifyCustomer() {
System.out.println("\n---------------------修改客户---------------------");
Customer temporary;
int isResult;
for (;;) {
System.out.print("请选择待修改客户编号(-1退出): ");
isResult = CMUtility.readInt();
if (isResult == -1) {
return;
}
if (customerList.getCustomer(isResult) == null) {
System.out.println("指定的索引不存在");
continue;
}
temporary = customerList.getCustomer(isResult);
break;
}
System.out.print("姓名(" + temporary.getName() + "): ");
String name = CMUtility.readString(10, temporary.getName());
System.out.print("性别(" + temporary.getGender() + "): ");
char gender = CMUtility.readChar(temporary.getGender());
System.out.print("年龄(" + temporary.getAge() + "): ");
int age = CMUtility.readInt(temporary.getAge());
System.out.print("电话(" + temporary.getPhone() + "): ");
String phone = CMUtility.readString(11, temporary.getPhone());
System.out.print("邮箱(" + temporary.getEmail() + "): ");
String email = CMUtility.readString(30, temporary.getEmail());
boolean isFlag = customerList.replaceCustomer(isResult, new Customer(name, gender, age, phone, email));
if (isFlag) {
System.out.println("---------------------修改完成---------------------");
} else {
System.out.println("---------------------修改失败---------------------");
}
}
private void deleteCustomer() {
System.out.println("---------------------删除客户---------------------");
int isResult;
for (;;) {
System.out.print("请选择待删除客户编号(-1退出): ");
isResult = CMUtility.readInt();
if (isResult == -1) {
return;
}
System.out.print("确认是否删除(Y/N): ");
char confirmSelect = CMUtility.readConfirmSelection();
if (confirmSelect == 'N') {
return;
}
break;
}
boolean isFlag = customerList.deleteCustomer(isResult);
if (isFlag) {
System.out.println("---------------------删除完成---------------------");
} else {
System.out.println("---------------------删除失败---------------------");
}
}
private void listAllCustomers() {
System.out.println("---------------------------客户列表---------------------------");
System.out.println("编号\t姓名\t性别\t年龄\t电话\t\t邮箱");
for (int i = 1; i <= customerList.getTotal(); i++) {
if (customerList.getCustomer(i) == null) {
break;
}
System.out.println(i + "\t" + customerList.getCustomer(i).getName() + "\t"
+ customerList.getCustomer(i).getGender() + "\t" + customerList.getCustomer(i).getAge() + "\t"
+ customerList.getCustomer(i).getPhone() + "\t" + customerList.getCustomer(i).getEmail() + "\t");
}
System.out.println("-------------------------客户列表完成-------------------------");
}
public static void main(String[] args) {
CustomerView customerView = new CustomerView();
customerView.enterMainMenu();
}
}
CMUtility
package com.atguigu.p2;
import java.util.*;
public class CMUtility {
private static Scanner scanner = new Scanner(System.in);
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);
}
public static char readChar(char defaultValue) {
String str = readKeyBoard(1, true);
return (str.length() == 0) ? defaultValue : str.charAt(0);
}
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;
}
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;
}
public static String readString(int limit) {
return readKeyBoard(limit, false);
}
public static String readString(int limit, String defaultValue) {
String str = readKeyBoard(limit, true);
return str.equals("")? defaultValue : str;
}
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;
}
}
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步