最好用的OCR实时翻译工具:Bob for Mac

Bob Mac中文版是mac上一款非常好用的菜单栏翻译软件,也是小编目前用过的最好用的mac翻译软件,Bob翻译软件支持划词翻译,截图翻译和手动输入翻译,支持的翻译源有道翻译、百度翻译和谷歌翻译,使用起来非常不错,有需要翻译软件的朋友,欢迎前来安装体验!!

原文链接:https://mac.orsoon.com/Mac/175821.html

bob for mac中文版功能介绍

功能 描述 预览
划词翻译 选中需要翻译的文本之后,按下划词翻译快捷键即可(默认 ⌥ + D
截图翻译 按下截图翻译快捷键(默认 ⌥ + S),截取需要翻译的区域
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Action 4: increasing the number of books of a given user. When the user of the software specifies action 4, your program must ask the user to type the name of a user, and a number of books, and the program then uses that number to increase the number of books lent or borrowed by the user. Then the program goes back to the main menu. For example: Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3 Enter the name of the user: Anna Anna borrows -5 book(s). Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 4 Enter the name of the user: Anna Enter the number of books: 2 Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3 Enter the name of the user: Anna Anna borrows -7 book(s). Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3 Enter the name of the user: Bob Bob borrows 10 book(s). Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 4 Enter the name of the user: Bob Enter the number of books: 2 Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3 Enter the name of the user: Bob Bob borrows 12 book(s). Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): If the name of the user is wrong, then an UnknownUserException exception will be thrown by the Library object. The code of the main method of your CLI class must catch this exception, print the error message from the exception object, and then it just goes back to printing the menu of actions (by just going back to the beginning of the while loop). For example (where 4, aaaa, and 2 are inputs from the user): Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 4 Enter the name of the user: aaaa Enter the number of books: 2 User aaaa unknown. Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): Note that, even if a consumer is a borrower, the readPosInt method prevents the typed number of books from being negative. This means a borrower will never throw a NotALenderException. Nevertheless the code of the main method of your CLI class must handle this exception by printing the error message "BUG! This must never happen!" and immediately terminating the program using System.exit(1). For example (where 3, Bob, 4, Bob, and -15 are inputs from the user): Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 3 Enter the name of the user: Bob Bob borrows 12 book(s). Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 4 Enter the name of the user: Bob Enter the number of books: -15 Positive integers only! Enter the number of books:
05-24
Sure, here's the updated code for the CLI class: ``` import java.util.Scanner; public class CLI { private Library library; private Scanner scanner; public CLI(Library library) { this.library = library; this.scanner = new Scanner(System.in); } public void run() { while (true) { System.out.print("Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): "); int action = readPosInt(); switch (action) { case 1: System.out.println("Total number of books: " + library.getTotal()); break; case 2: System.out.print("Enter the number of books to add: "); int add = readPosInt(); library.add(add); System.out.println("Total number of books: " + library.getTotal()); break; case 3: System.out.print("Enter the name of the user: "); String borrower = scanner.nextLine(); try { int borrowed = library.get(borrower); System.out.println(borrower + " borrows " + borrowed + " book(s)."); } catch (UnknownUserException e) { System.out.println(e.getMessage()); } break; case 4: System.out.print("Enter the name of the user: "); String lender = scanner.nextLine(); System.out.print("Enter the number of books: "); int books = readPosInt(); try { library.more(lender, books); System.out.println(lender + " now lends " + library.get(lender) + " book(s)."); } catch (UnknownUserException e) { System.out.println(e.getMessage()); } break; case 5: System.out.print("Enter the name of the user: "); String borrower2 = scanner.nextLine(); System.out.print("Enter the number of books: "); int books2 = readPosInt(); try { library.less(borrower2, books2); System.out.println(borrower2 + " now borrows " + library.get(borrower2) + " book(s)."); } catch (UnknownUserException e) { System.out.println(e.getMessage()); } catch (NotALenderException e) { System.out.println("BUG! This must never happen!"); System.exit(1); } break; case 6: System.out.println("Goodbye!"); return; default: System.out.println("Invalid action."); break; } } } private int readPosInt() { while (true) { try { int num = Integer.parseInt(scanner.nextLine()); if (num < 0) { throw new NumberFormatException(); } return num; } catch (NumberFormatException e) { System.out.print("Positive integers only! Enter a number again: "); } } } } ``` I added a new case for action 4, where we prompt the user for the name of the user and the number of books to add. Then we call the `more` method on the library object with those parameters, catch any `UnknownUserException` exceptions that may be thrown, and print the appropriate message. I also added an additional catch block for the `NotALenderException` that may be thrown in the `less` method. In this case, we print an error message and immediately terminate the program using `System.exit(1)`. Let me know if you have any questions or concerns!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值