Idea 实操快捷键手册

Idea实操代码快捷键(亲测CV)

1.1 输出(可参考2.10) :
sout
1.2 错误打印(可参考2.10) :
serr
1.3 main主函数(可参考2.10) :
psvm
1.4 if判断:
变量.if
比如 a>0.if || true.if if前必须是一个boolean类型的变量或者表达式
1.5 switch:
变量.switch
1.6 try捕获异常:
变量.try
1.7 本身for循环:
变量.for
1.8 变量for循环 :
变量.fori
1.9 倒序的for循环:
变量.forr
1.10 判断是否为空:
变量.null
1.11 判断是否非空:
变量.notnull或者变量.nn
代码快速生产方法快捷键
2.1 选择重写或实现方法(select methods to override/implements)
ctrl + o
2.2 选择实现方法(select methods to implement)
ctrl + i
2.3 生成构造方法、toString方法、重写或实现方法及版权(generate…)
alt + insert
2.4 包围(surround with)
ctrl + alt + t
2.5 自动补全(完成,Completion)
Ctrl+Space 基本的自动补全,通过设置可以设置成和eclipse一样(Alt+/)
Ctrl+Shift+Space 智能的自动补全
2.6 折叠(folding)
Ctrl+Shift+数字键盘的-(collapse 折叠,按一次折叠全部)
Ctrl+Shift+数字键盘的+(expand展开,按一次展开一个,再按一次展开下一个)
2.7 注释(comment)
Ctrl+/ 注释行(选中的单行或多行 ,在每行的开始加上//)
Ctrl+Shift+/ 注释代码块 ( /**/)
2.8 重新格式化代码(reformat code)
Ctrl+Alt+L
2.9 优化类导入(Optimize Imports)
Ctrl+Alt+O
2.10 main方法、System.out.println()等方法的自动完成
Ctrl+j
输入psvm然后按Ctrl+J,就可以自动补全main方法
输入sout然后按Ctrl+J,就可以自动补全System.out.println()方法
2.11 类移动到其他包
F6
2.12 代码问题寻找解决方案
Al+Enter

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
2) The State pattern is a behavioral design pattern that allows an object to alter its behavior when its internal state changes. This pattern involves creating state objects that represent various states of the object and a context object whose behavior varies as its state object changes. On the other hand, the Decorator pattern is a structural design pattern that allows behavior to be added to an individual object, either statically or dynamically, without affecting the behavior of other objects from the same class. This pattern involves creating decorator objects that wrap the original object and provide additional functionality while keeping the original object's interface intact. 5) Here is the code for the classes introduced in question 2), focusing on the code for a method selectState() which changes the value that is being adjusted from years to months: ```java // Context interface interface Account { void selectState(State state); void deposit(double amount); void withdraw(double amount); double getBalance(); } // Concrete Context class class SavingsAccount implements Account { private State state; private double balance; public SavingsAccount() { this.state = new YearsSetUpState(); // default state this.balance = 0.0; } @Override public void selectState(State state) { this.state = state; } @Override public void deposit(double amount) { this.balance += state.adjustDeposit(amount); } @Override public void withdraw(double amount) { this.balance -= state.adjustWithdrawal(amount); } @Override public double getBalance() { return this.balance; } // Other methods needed public State getMonthSetUpState() { return new MonthsSetUpState(); } } // State interface interface State { double adjustDeposit(double deposit); double adjustWithdrawal(double withdrawal); } // Concrete State classes class YearsSetUpState implements State { @Override public double adjustDeposit(double deposit) { return deposit; } @Override public double adjustWithdrawal(double withdrawal) { return withdrawal; } } class MonthsSetUpState implements State { @Override public double adjustDeposit(double deposit) { return deposit / 12; } @Override public double adjustWithdrawal(double withdrawal) { return withdrawal / 12; } } ``` In the above code, the `Account` interface represents the context object, while the `State` interface represents the state objects. The `SavingsAccount` class is a concrete context class that implements the `Account` interface and keeps track of the current state object. The `YearsSetUpState` and `MonthsSetUpState` classes are concrete state classes that implement the `State` interface and provide specific behavior for each state. The `selectState()` method is implemented in the `SavingsAccount` class and allows the current state object to be changed. The `deposit()` and `withdraw()` methods use the current state object to adjust the deposit and withdrawal amounts accordingly. The `getBalance()` method returns the current balance of the account. The `getMonthSetUpState()` method is also implemented in the `SavingsAccount` class and returns a new `MonthsSetUpState` object, which can be used to change the current state object to adjust the deposit and withdrawal amounts from years to months.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值