Add a class Borrower that extends User. The constructor of the Borrower class takes a name and a number of books borrowed by the borrower. If the number of books given as argument is strictly less than zero, then the constructor must throw a NotALenderException with the message "A new borrower cannot lend books.". The borrower class does not have any instance variable.java代码

时间: 2024-01-20 08:02:18 浏览: 209
Sure, here's your Java code: ```java public class Borrower extends User { public Borrower(String name, int numBooksBorrowed) throws NotALenderException { super(name); if(numBooksBorrowed < 0) { throw new NotALenderException("A new borrower cannot lend books."); } } } ``` Here, we have defined a `Borrower` class that extends the `User` class. The constructor of the `Borrower` class takes a name and a number of books borrowed by the borrower. If the number of books given as argument is strictly less than zero, then the constructor throws a `NotALenderException` with the message "A new borrower cannot lend books.". Note that we are calling the constructor of the parent `User` class using the `super` keyword, passing in the `name` argument. The `Borrower` class does not have any instance variables.
阅读全文

相关推荐

Also create a ControllerCreate class that extends Controller.The create method takes as arguments the name of a new library user, a number of books (as a string), and an integer representing the role of user to create (where the integer 0 means a lender and the integer 1 means a borrower). The create method of the controller then transforms the book number from a string to an integer (using the Integer.parseInt static method), creates an object from the correct class (based on the role specified by the user input: lender or borrower) and calls the addUser method of the library to add the new user object to the library. • If no exception occurs then the create method of the controller returns the empty string. • If the constructor of the Borrower class throws a NotALenderException then the create method of the controller must catch this exception and return as result the error message from the exception object. • If the parseInt method of the Integer class throws a NumberFormatException (because the user typed something which is not an integer) then the create method of the controller must catch this exception and return as result the error message from the exception object. Modify the run method of the GUI class to add a ViewCreate view that uses a ControllerCreate controller and the same model as before (not a new model!) Do not delete the previous views. Note: if at the end of Question 7 you had manually added to your library (model object) some users for testing, then you must now remove those users from the run method of the anonymous class inside the GUI class. You do not need these test users anymore because you have now a graphical user interface to create new users! Run your GUI and check that you can correctly use the new view to create different users for your library, with different types of roles. • Check that, when you create a new user, the simple view is automatically correctly updated to show the new total number of books borrowed by all users. • Also use the “get book” view to check that the users are correctly created with the correct names and correct number of books. • Also check that trying to create a borrower with a negative number of books correctly shows an error message. Also check that trying to create a user with a number of books which is not an integer correctly shows an error message (do not worry about the content of the error message). After you created a new user, you can also check whether it is a lender or a borrower using the “more book” view to increase the number of books of the user by a big negative number: • if the new user you created is a lender, then increasing the number of books by a big negative value will work and the number of books borrowed by the user will just become a larger value (you can then check that using the “get book” view); • if the new user you created is a borrower, then increasing the number of books by a big negative value will fail with an error message and the number of books borrowed by the user will not change (you can then check that using the “get book” view). 完成符合以上要求的java代码

Also create a ControllerMoreBook class that extends Controller.The moreBook method takes the name of a user and a number of books (as a string) as arguments. The moreBook method of the controller then transforms the number of books from a string to an integer (using the Integer.parseInt static method) and calls the moreBook method of the library to increase the number of books borrowed or lent by the user (depending on what kind of user it is) of a specific user, by the given argument. • If no exception occurs then the moreBook method of the controller returns the empty string. • If the moreBook method of the library throws an UnknownUserException then the moreBook method of the controller must catch this exception and return as result the error message from the exception object. • If the moreBook method of the library throws a NotALenderException then the moreBook method of the controller must catch this exception and return as result the error message from the exception object. • If the parseInt method of the Integer class throws a NumberFormatException (because the user typed something which is not an integer) then the moreBook method of the controller must catch this exception and return as result the error message from the exception object. Note: to keep things simple, it is allowed for a user of your system to increase the number of books of a user by a negative number, so there is no need to check for that. Modify the run method of the GUI class to add a ViewMoreBook view that uses a ControllerMoreBook controller and the same model as before (not a new model!) Do not delete the previous views. Run your GUI and check that you can correctly use the new view to increase the number of books for different users of your library (obviously your library must have some users in it to test this: see the last paragraph of Question 7). • Check that, when you increase a user’s book, the simple view is automatically correctly updated to show the new total number of borrowed books for all users of the library. • Also use the “get book” view to check that the user’s book value correctly changed. • Also check that increasing the book number of an unknown user correctly shows an error message.Also check that increasing the book of a user by a large negative number correctly shows an error message. Also check that trying to increase the book of a user by a number which is not an integer correctly shows an error message (do not worry about the content of the error message). 完成符合以上要求的java代码

Action 2: adding a new user to the library. When the user of the software specifies action 2, your program must add a new user to the library. To add a new user, your program needs to ask the user three things: the role of user (an integer read using readPosInt: the integer 1 represents lender, the integer 2 represents borrower, any other integer must result in an error message "Unknown user role!" being printed and the software going immediately back to the main menu), the name of the user (a string read using readLine), and the initial number of books that the user lends (for a lender) or borrows (for a borrower). You program must then create the correct user, add it to the library, and print an information message. The program then goes back to the menu. For example (where 2, 3, 2, 1, Anna, 5, 2, 2, Bob, and 10 are inputs from the user): Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 2 Type the user role (lender:1 borrower:2): 3 Unknown user role! Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 2 Type the user role (lender:1 borrower:2): 1 Enter the name of the user: Anna Enter the initial number of borrowed books: 5 Lender "Anna" lending 5 book(s) has been added. Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): 2 Type the user role (lender:1 borrower:2): 2 Enter the name of the user: Bob Enter the initial number of borrowed books: 10 Borrower "Bob" borrowing 10 book(s) has been added. Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): Note that the readPosInt method prevents the initial number of books from being negative, so the constructor for the Borrower class will never throw a NotALenderException when you create a borrower object. 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);

use java language ,In this project you need to write a book lending system for a Library. The system has different roles for registered users. There are two types of user roles: borrower and lender. Write an IUser interface for library users, with the following UML specification: +----------------------------------+ | <<interface>> | | IUser | +----------------------------------+ | + getName(): String | | + getBook(): int | | + moreBook(int number): void | +----------------------------------+ and a User class that implements IUser and has the following UML specification: +-----------------------------------+ | User | +-----------------------------------+ | - name: String | | - book: int | +-----------------------------------+ | + User(String name, int book) | | + getName(): String | | + getBook(): int | | # setBook(int book): void | | + moreBook(int number): void | | + testUser(): void | +-----------------------------------+ The name instance variable indicates the user name. The book instance variable indicates the number of books borrowed by the user. The setBook method changes the number of books borrowed by the user. The setBook method is protected, not public. This means that only subclasses of the User class can use the setBook method. All the other classes in the system cannot use the setBook method, so they cannot change the number of books borrowed by a user. The purpose of the moreBook method is to increase the number of books borrowed or lent by the user (depending on what kind of user it is) by the number given as argument to the method. The moreBook method of the User class is abstract, since we do not know what kind of role the user is (a borrower borrows books from other users and a lender lend books to other users). Also add to your program a Test class to test your User class. public class Test { public static void main(String[] args) { User.testUser(); } }

帮我修改一下我的代码错误:帮我看看我这段代码有什么错误:int choice = readPosInt("Type an action (total:1 add:2 get:3 more:4 less:5 quit:6): "); // Perform the selected action while (choice != 6) { switch (choice) { case 1: System.out.println("Total number of borrowed books: " + Library.totalBorrowedBooks(null)); break; case 2: System.out.print("Type the user role (lender:1 borrower:2): "); int role = readPosInt(null); if (role == 1) { System.out.print("Enter the name of the user: "); String name = readLine(name); System.out.print("Enter the initial number of lent books: "); int numBooks = readPosInt(null); Lender lender = new Lender(name, numBooks); Library.addUser(lender); System.out.println("Lender "" + name + "" lending " + numBooks + " book(s) has been added."); } else if (role == 2) { System.out.print("Enter the name of the user: "); String name = readLine(name); System.out.print("Enter the initial number of borrowed books: "); int numBooks = readPosInt(null); Borrower borrower = new Borrower(name, numBooks); Library.addUser(borrower); System.out.println("Borrower "" + name + "" borrowing " + numBooks + " book(s) has been added."); } else { System.out.println("Unknown user role!"); } break; case 3: System.out.print("Enter the name of the user: "); String username = input.nextLine(); try { int numBorrowed = Library.totalBorrowedBooks(username); System.out.println(username + " borrows " + numBorrowed + " book(s)."); } catch (UnknownUserException e) { System.out.println("User " + username + " unknown."); } break; case 4: try { System.out.print("Enter the name of the user: "); String name = input.nextLine(); System.out.print("Enter the number of books: "); int num = input.nextInt(); input.nextLine(); library.moreBook(username, role); } catch (UnknownUserException e) { System.out.println("User " + username + " unknown."); } break; case 5: System.out.print("Enter the name of the user: "); username = input.next(); System.out.print("Enter the number of books: "); int numBooks = input.nextInt(); library.moreBook(username, -numBooks); // simulate decreasing books break; case 6: System.out.println("Goodbye!"); System.exit(0); break; }

zip

大家在看

recommend-type

MS入门教程

MS入门教程,简易教程,操作界面,画图建模等入门内容。
recommend-type

一种新型三自由度交直流混合磁轴承原理及有限元分析

研究了一种新颖的永磁偏磁三自由度交直流混合磁轴承。轴向悬浮力控制采用直流驱动,径向悬浮力控制采用三相逆变器提供电流驱动,由一块径向充磁的环形永磁体同时提供轴向、径向偏磁磁通,同时引入一组二片式六极径向轴向双磁极面结构,大幅增大了径向磁极面积,提高磁轴承的径向承载力,并且在保证径向承载力的情况下,减小轴向尺寸。轴承集合了交流驱动、永磁偏置及径向-轴向联合控制等优点。理论分析和有限元仿真证明,磁轴承的结构设计更加合理,对磁悬浮传动系统向大功率、微型化方向发展具有一定意义。
recommend-type

PyGuide-working.rar

使用python编写的基于genesis2000的cam-guide软件。genesis2000接口用的python3.0 可以自己找网上的2.0改一改,很简单
recommend-type

主要的边缘智能参考架构-arm汇编语言官方手册

(3)新型基础设施平台 5G 新型基础设施平台的基础是网络功能虚拟化(NFV)和软件定义网络(SDN) 技术。IMT2020(5G)推进组发布的《5G网络技术架构白皮书》认为,通过软件 与硬件的分离,NFV 为 5G网络提供更具弹性的基础设施平台,组件化的网络功 能模块实现控制面功能可重构,并对通用硬件资源实现按需分配和动态伸缩,以 达到优化资源利用率。SDN技术实现控制功能和转发功能的分离,这有利于网络 控制平面从全局视角来感知和调度网络资源。NFV和 SDN技术的进步成熟,也给 移动边缘计算打下坚实基础。 2.3 主要的边缘智能参考架构 边缘智能的一些产业联盟及标准化组织作为产业服务机构,会持续推出边缘 计算技术参考架构,本节总结主要标准化组织的参考架构。 欧洲电信标准化协会(ETSI) 2016年 4 月 18日发布了与 MEC相关的重量级 标准,对 MEC的七大业务场景作了规范和详细描述,主要包括智能移动视频加速、 监控视频流分析、AR、密集计算辅助、在企业专网之中的应用、车联网、物联网 网关业务等七大场景。 此外,还发布了发布三份与 MEC相关的技术规范,分别涉及 MEC 术语、技术 需求及用例、MEC框架与参考架构。
recommend-type

[C#]文件中转站程序及源码

​在网上看到一款名为“DropPoint文件复制中转站”的工具,于是自己尝试仿写一下。并且添加一个移动​文件的功能。 用来提高复制粘贴文件效率的工具,它会给你一个临时中转悬浮框,只需要将一处或多处想要复制的文件拖拽到这个悬浮框,再一次性拖拽至目的地文件夹,就能高效完成复制粘贴及移动文件。 支持拖拽多个文件到悬浮框,并显示文件数量 将悬浮窗内的文件往目标文件夹拖拽即可实现复制,适用于整理文件 主要的功能实现: 1、实现文件拖拽功能,将文件或者文件夹拖拽到软件上 2、实现文件拖拽出来,将文件或目录拖拽到指定的位置 3、实现多文件添加,包含目录及文件 4、添加软件透明背景、软件置顶、文件计数

最新推荐

recommend-type

毕业设计基于单片机的室内有害气体检测系统源码+论文(高分毕设)

毕业设计基于单片机的室内有害气体检测系统源码+论文(高分毕设)毕业设计基于单片机的室内有害气体检测系统源码毕业设计基于单片机的室内有害气体检测系统源码+论文,含有代码注释,简单部署使用。结合毕业设计文档进行理解。 有害气体检测报警系统分为四个子系统:主控制系统,室内气体检测系统,信息交互可视化系统与信息处理识别反馈系统。有害气体检测报警系统如图2-1所示,主控系统为核心,通过控制室内检测系统采集数据之后进行数据回传。回传的数据经过信息处理识别反馈系统及预处理后进行可视化展现与指标判断,并且最终根据所得数据判断是否需要预警,完成规避风险的功能。 有害气体检测未来研究趋势: 室内有害气体检测在现代社会中变得愈发重要,关乎人们的健康和居住环境的质量。随着城市化的加速和室内空间的日益密集,有害气体如CO、CO2、甲醛等的排放成为一项不可忽视的问题。以下通过了解国内外在这一领域的最新研究,为基于单片机的室内有害气体检测报警系统的设计提供依据。 (1)数据处理与算法: 国内的研究人员致力于改进数据处理算法,以更有效地处理大量的监测数据。智能算法的引入,如机器学习和人工智能,有助于提高对室内空气质
recommend-type

mellitz_3df_elec_01_220502.pdf

mellitz_3df_elec_01_220502
recommend-type

数据库期末试卷分享,欢迎大家来看

数据库期末试卷分享,欢迎大家来看
recommend-type

建筑学领域传统中式建筑设计与施工手册

内容概要:本文档是一部关于中国传统建筑设计的指导手册,重点介绍了从设计构思到具体施工过程中所需的关键技术和步骤。文中详细阐述了中式建筑设计的基本原则,如对称布局、比例协调、细节处理等方面的内容。此外,还涉及到了材料选择、构件加工以及装饰工艺等相关细节。每个章节都配以相应的图示和实例,旨在为相关从业人员提供实用的技术支持。同时,对于如何保持古建筑的特色,在现代社会中发挥传统建筑的独特魅力也进行了深入探讨。 适合人群:建筑设计专业人士及对此感兴趣的初学者。 使用场景及目标:作为建筑设计及施工单位的专业指南,本手册主要用于帮助设计师理解和掌握传统中式建筑设计的各项规范和技术要点,适用于各种规模的传统建筑项目的设计与实施。 其他说明:本文档提供了丰富案例和详实的数据图表,便于读者直观理解和应用相关知识点。
recommend-type

素质教育背景下小学语文微课教学面临的问题及解决方案

内容概要:文章旨在通过对小学语文微课教学存在问题及其对策的研究,探讨微课教学模式在当前素质教育下的适配性和优化方向。首先介绍了素质教育的背景及其在小学语文教学中的应用情况,分析了当前微课教学面临的教师掌控能力、学生自制力以及管理机制等方面的挑战。接着提出了一系列改进措施,包括增加微课使用率、强化学生管理和扩展微课内容,从而促进小学语文微课教学质量的提升。此外,作者还结合实例阐述了微课教学的重要性和迫切性。 适用人群:中小学教育工作者、研究人员、行政管理者等,特别是致力于推动微课教学创新的语文老师。 使用场景及目标:①帮助一线教师了解并改进小学语文微课教学中存在的问题;②为教育部门制定相关政策提供参考;③鼓励教师和学生探索新型学习方式,提高教学效果。 其他说明:文中引用了大量的国内外研究成果和实证数据,为提出的对策提供了扎实的理论基础。
recommend-type

易语言例程:用易核心支持库打造功能丰富的IE浏览框

资源摘要信息:"易语言-易核心支持库实现功能完善的IE浏览框" 易语言是一种简单易学的编程语言,主要面向中文用户。它提供了大量的库和组件,使得开发者能够快速开发各种应用程序。在易语言中,通过调用易核心支持库,可以实现功能完善的IE浏览框。IE浏览框,顾名思义,就是能够在一个应用程序窗口内嵌入一个Internet Explorer浏览器控件,从而实现网页浏览的功能。 易核心支持库是易语言中的一个重要组件,它提供了对IE浏览器核心的调用接口,使得开发者能够在易语言环境下使用IE浏览器的功能。通过这种方式,开发者可以创建一个具有完整功能的IE浏览器实例,它不仅能够显示网页,还能够支持各种浏览器操作,如前进、后退、刷新、停止等,并且还能够响应各种事件,如页面加载完成、链接点击等。 在易语言中实现IE浏览框,通常需要以下几个步骤: 1. 引入易核心支持库:首先需要在易语言的开发环境中引入易核心支持库,这样才能在程序中使用库提供的功能。 2. 创建浏览器控件:使用易核心支持库提供的API,创建一个浏览器控件实例。在这个过程中,可以设置控件的初始大小、位置等属性。 3. 加载网页:将浏览器控件与一个网页地址关联起来,即可在控件中加载显示网页内容。 4. 控制浏览器行为:通过易核心支持库提供的接口,可以控制浏览器的行为,如前进、后退、刷新页面等。同时,也可以响应浏览器事件,实现自定义的交互逻辑。 5. 调试和优化:在开发完成后,需要对IE浏览框进行调试,确保其在不同的操作和网页内容下均能够正常工作。对于性能和兼容性的问题需要进行相应的优化处理。 易语言的易核心支持库使得在易语言环境下实现IE浏览框变得非常方便,它极大地降低了开发难度,并且提高了开发效率。由于易语言的易用性,即使是初学者也能够在短时间内学会如何创建和操作IE浏览框,实现网页浏览的功能。 需要注意的是,由于IE浏览器已经逐渐被微软边缘浏览器(Microsoft Edge)所替代,使用IE核心的技术未来可能面临兼容性和安全性的挑战。因此,在实际开发中,开发者应考虑到这一点,并根据需求选择合适的浏览器控件实现技术。 此外,易语言虽然简化了编程过程,但其在功能上可能不如主流的编程语言(如C++, Java等)强大,且社区和技术支持相比其他语言可能较为有限,这些都是在选择易语言作为开发工具时需要考虑的因素。 文件名列表中的“IE类”可能是指包含实现IE浏览框功能的类库或者示例代码。在易语言中,类库是一组封装好的代码模块,其中包含了各种功能的实现。通过在易语言项目中引用这些类库,开发者可以简化开发过程,快速实现特定功能。而示例代码则为开发者提供了具体的实现参考,帮助理解和学习如何使用易核心支持库来创建IE浏览框。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

STM32F407ZG引脚功能深度剖析:掌握引脚分布与配置的秘密(全面解读)

![STM32F407ZG引脚功能深度剖析:掌握引脚分布与配置的秘密(全面解读)](https://tapit.vn/wp-content/uploads/2019/01/cubemx-peripheral-1024x545.png) # 摘要 本文全面介绍了STM32F407ZG微控制器的引脚特性、功能、配置和应用。首先概述了该芯片的引脚布局,然后详细探讨了标准外设、高级控制以及特殊功能引脚的不同配置和使用方法。在此基础上,文章深入分析了引脚模式配置、高级配置技巧,并提供了实际应用案例,如LED控制和串口通信。在设计方面,阐述了引脚布局策略、多层板设计及高密度引脚应用的解决方案。最后,介绍
recommend-type

给出文档中问题的答案代码

您提到的是需要编写MATLAB代码来实现文档中的实验任务。以下是根据文档内容编写的MATLAB代码示例: ```matlab % 上机2 实验代码 % 读取输入图像 inputImage = imread('your_face_image.jpg'); % 替换为您的图像文件路径 if size(inputImage, 1) < 1024 || size(inputImage, 2) < 1024 error('图像尺寸必须大于1024x1024'); end % 将彩色图像转换为灰度图像 grayImage = rgb2gray(inputImage); % 调整图像大小为5
recommend-type

Docker构建与运行Next.js应用的指南

资源摘要信息:"rivoltafilippo-next-main" 在探讨“rivoltafilippo-next-main”这一资源时,首先要从标题“rivoltafilippo-next”入手。这个标题可能是某一项目、代码库或应用的命名,结合描述中提到的Docker构建和运行命令,我们可以推断这是一个基于Docker的Node.js应用,特别是使用了Next.js框架的项目。Next.js是一个流行的React框架,用于服务器端渲染和静态网站生成。 描述部分提供了构建和运行基于Docker的Next.js应用的具体命令: 1. `docker build`命令用于创建一个新的Docker镜像。在构建镜像的过程中,开发者可以定义Dockerfile文件,该文件是一个文本文件,包含了创建Docker镜像所需的指令集。通过使用`-t`参数,用户可以为生成的镜像指定一个标签,这里的标签是`my-next-js-app`,意味着构建的镜像将被标记为`my-next-js-app`,方便后续的识别和引用。 2. `docker run`命令则用于运行一个Docker容器,即基于镜像启动一个实例。在这个命令中,`-p 3000:3000`参数指示Docker将容器内的3000端口映射到宿主机的3000端口,这样做通常是为了让宿主机能够访问容器内运行的应用。`my-next-js-app`是容器运行时使用的镜像名称,这个名称应该与构建时指定的标签一致。 最后,我们注意到资源包含了“TypeScript”这一标签,这表明项目可能使用了TypeScript语言。TypeScript是JavaScript的一个超集,它添加了静态类型定义的特性,能够帮助开发者更容易地维护和扩展代码,尤其是在大型项目中。 结合资源名称“rivoltafilippo-next-main”,我们可以推测这是项目的主目录或主仓库。通常情况下,开发者会将项目的源代码、配置文件、构建脚本等放在一个主要的目录中,这个目录通常命名为“main”或“src”等,以便于管理和维护。 综上所述,我们可以总结出以下几个重要的知识点: - Docker容器和镜像的概念以及它们之间的关系:Docker镜像是静态的只读模板,而Docker容器是从镜像实例化的动态运行环境。 - `docker build`命令的使用方法和作用:这个命令用于创建新的Docker镜像,通常需要一个Dockerfile来指定构建的指令和环境。 - `docker run`命令的使用方法和作用:该命令用于根据镜像启动一个或多个容器实例,并可指定端口映射等运行参数。 - Next.js框架的特点:Next.js是一个支持服务器端渲染和静态网站生成的React框架,适合构建现代的Web应用。 - TypeScript的作用和优势:TypeScript是JavaScript的一个超集,它提供了静态类型检查等特性,有助于提高代码质量和可维护性。 - 项目资源命名习惯:通常项目会有一个主目录,用来存放项目的源代码和核心配置文件,以便于项目的版本控制和团队协作。 以上内容基于给定的信息进行了深入的分析,为理解该项目的构建、运行方式以及技术栈提供了基础。在实际开发中,开发者应当参考更详细的文档和指南,以更高效地管理和部署基于Docker和TypeScript的Next.js项目。