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.

时间: 2023-11-22 14:55:08 浏览: 69
Here is the code for adding a new user to the library: ``` def add_user(library): role = readPosInt("Enter the role of the user (1 for lender, 2 for borrower): ") if role == 1: user_role = "Lender" elif role == 2: user_role = "Borrower" else: print("Unknown user role!") return name = readLine("Enter the name of the user: ") num_books = readPosInt(f"Enter the initial number of books {name} lends (for a lender) or borrows (for a borrower): ") if user_role == "Lender": user = Lender(name, num_books) else: user = Borrower(name, num_books) library.add_user(user) print(f"User {name} ({user_role}) added to the library.") ``` Here, we first ask the user for the role of the new user, their name, and the initial number of books they lend or borrow. If the role is not 1 or 2, we print an error message and return to the main menu. Otherwise, we create a new user object based on their role and add it to the library. We print a message confirming the addition of the new user to the library and return to the main menu.
阅读全文

相关推荐

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);

A random number of Rabbit images ranging from 1 to 10 are displayed for each operand and the user is expected to enter the values of the two operands and the result of adding the two operands, in the given text fields. When the user clicks on the button ‘Check!’, one of two things can happen: Case 1: all three input values are correct i) the text changes to ‘"Correct! Have another go?"’. ii) the number of Rabbit images displayed for each of the two operands changes. See Figure 2 for an example. iii) the three text fields are reset (i.e. they are made empty). 2/5 Case 2: at least one of the input values entered is incorrect i) the text changes to ‘Wrong! Try again!’. ii) the number of Rabbit images displayed does NOT change. iii) the text fields do NOT change.Implement SumItUp as a Java application. You application must satisfy ALL the specific requirements given below: a) The title of the top-level container must be ‘Welcome to SumItUp!’. b) The initial text should be ‘Enter two operands, result and click on 'Check!'’. See Figure 1. c) There should be no more than 4 Rabbit images per row. See Hint 1. d) The text fields should be wide enough to display at least TWO characters. e) The button ‘Check!’ must not resize when the GUI is resized. See Hint 2 and Figure 3. f) The ‘plus sign’ icon should appear vertically centered between the two sets of Rabbit images and must not resize when the GUI is resized. See Hint 2 and Figure 3. g) When first launched and whenever a correct answer is given, the number of displayed Rabbit images for each operand should change to any number between 1 and 10 (inclusive). See Hint 3 and Hint 4. Note: It is possible for the next number(s) to be the same as the current number(s). h) Nothing should happen if the user clicks the ‘Check!’ button while at least one of the text fields are empty, i.e. no errors should be thrown in this case. Note: You can assume that only a numeric value will be entered into the text fields.

用代码解决这个问题The program committee of the school programming contests, which are often held at the Ural State University, is a big, joyful, and united team. In fact, they are so united that the time spent together at the university is not enough for them, so they often visit each other at their homes. In addition, they are quite athletic and like walking. Once the guardian of the traditions of the sports programming at the Ural State University decided that the members of the program committee spent too much time walking from home to home. They could have spent that time inventing and preparing new problems instead. To prove that, he wanted to calculate the average distance that the members of the program committee walked when they visited each other. The guardian took a map of Yekaterinburg, marked the houses of all the members of the program committee there, and wrote down their coordinates. However, there were so many coordinates that he wasn't able to solve that problem and asked for your help. The city of Yekaterinburg is a rectangle with the sides parallel to the coordinate axes. All the streets stretch from east to west or from north to south through the whole city, from one end to the other. The house of each member of the program committee is located strictly at the intersection of two orthogonal streets. It is known that all the members of the program committee walk only along the streets, because it is more pleasant to walk on sidewalks than on small courtyard paths. Of course, when walking from one house to another, they always choose the shortest way. All the members of the program committee visit each other equally often. Input The first line contains the number n of members of the program committee (2 ≤ n ≤ 105). The i-th of the following n lines contains space-separated coordinates xi, yi of the house of the i-th member of the program committee (1 ≤ xi, yi ≤ 106). All coordinates are integers. Output Output the average distance, rounded down to an integer, that a member of the program committee walks from his house to the house of his colleague.

最新推荐

recommend-type

iOS版微信抢红包Tweak.zip小程序

iOS版微信抢红包Tweak.zip小程序
recommend-type

毕业设计&课设_篮球爱好者网站,含前后台管理功能及多种篮球相关内容展示.zip

该资源内项目源码是个人的课程设计、毕业设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过严格测试运行成功才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。
recommend-type

基于springboot社区停车信息管理系统.zip

基于springboot社区停车信息管理系统.zip
recommend-type

基于springboot南皮站化验室管理系统源码数据库文档.zip

基于springboot南皮站化验室管理系统源码数据库文档.zip
recommend-type

全国江河水系图层shp文件包下载

资源摘要信息:"国内各个江河水系图层shp文件.zip" 地理信息系统(GIS)是管理和分析地球表面与空间和地理分布相关的数据的一门技术。GIS通过整合、存储、编辑、分析、共享和显示地理信息来支持决策过程。在GIS中,矢量数据是一种常见的数据格式,它可以精确表示现实世界中的各种空间特征,包括点、线和多边形。这些空间特征可以用来表示河流、道路、建筑物等地理对象。 本压缩包中包含了国内各个江河水系图层的数据文件,这些图层是以shapefile(shp)格式存在的,是一种广泛使用的GIS矢量数据格式。shapefile格式由多个文件组成,包括主文件(.shp)、索引文件(.shx)、属性表文件(.dbf)等。每个文件都存储着不同的信息,例如.shp文件存储着地理要素的形状和位置,.dbf文件存储着与这些要素相关的属性信息。本压缩包内还包含了图层文件(.lyr),这是一个特殊的文件格式,它用于保存图层的样式和属性设置,便于在GIS软件中快速重用和配置图层。 文件名称列表中出现的.dbf文件包括五级河流.dbf、湖泊.dbf、四级河流.dbf、双线河.dbf、三级河流.dbf、一级河流.dbf、二级河流.dbf。这些文件中包含了各个水系的属性信息,如河流名称、长度、流域面积、流量等。这些数据对于水文研究、环境监测、城市规划和灾害管理等领域具有重要的应用价值。 而.lyr文件则包括四级河流.lyr、五级河流.lyr、三级河流.lyr,这些文件定义了对应的河流图层如何在GIS软件中显示,包括颜色、线型、符号等视觉样式。这使得用户可以直观地看到河流的层级和特征,有助于快速识别和分析不同的河流。 值得注意的是,河流按照流量、流域面积或长度等特征,可以被划分为不同的等级,如一级河流、二级河流、三级河流、四级河流以及五级河流。这些等级的划分依据了水文学和地理学的标准,反映了河流的规模和重要性。一级河流通常指的是流域面积广、流量大的主要河流;而五级河流则是较小的支流。在GIS数据中区分河流等级有助于进行水资源管理和防洪规划。 总而言之,这个压缩包提供的.shp文件为我们分析和可视化国内的江河水系提供了宝贵的地理信息资源。通过这些数据,研究人员和规划者可以更好地理解水资源分布,为保护水资源、制定防洪措施、优化水资源配置等工作提供科学依据。同时,这些数据还可以用于教育、科研和公共信息服务等领域,以帮助公众更好地了解我国的自然地理环境。
recommend-type

管理建模和仿真的文件

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

Keras模型压缩与优化:减小模型尺寸与提升推理速度

![Keras模型压缩与优化:减小模型尺寸与提升推理速度](https://dvl.in.tum.de/img/lectures/automl.png) # 1. Keras模型压缩与优化概览 随着深度学习技术的飞速发展,模型的规模和复杂度日益增加,这给部署带来了挑战。模型压缩和优化技术应运而生,旨在减少模型大小和计算资源消耗,同时保持或提高性能。Keras作为流行的高级神经网络API,因其易用性和灵活性,在模型优化领域中占据了重要位置。本章将概述Keras在模型压缩与优化方面的应用,为后续章节深入探讨相关技术奠定基础。 # 2. 理论基础与模型压缩技术 ### 2.1 神经网络模型压缩
recommend-type

MTK 6229 BB芯片在手机中有哪些核心功能,OTG支持、Wi-Fi支持和RTC晶振是如何实现的?

MTK 6229 BB芯片作为MTK手机的核心处理器,其核心功能包括提供高速的数据处理、支持EDGE网络以及集成多个通信接口。它集成了DSP单元,能够处理高速的数据传输和复杂的信号处理任务,满足手机的多媒体功能需求。 参考资源链接:[MTK手机外围电路详解:BB芯片、功能特性和干扰滤波](https://wenku.csdn.net/doc/64af8b158799832548eeae7c?spm=1055.2569.3001.10343) OTG(On-The-Go)支持是通过芯片内部集成功能实现的,允许MTK手机作为USB Host与各种USB设备直接连接,例如,连接相机、键盘、鼠标等
recommend-type

点云二值化测试数据集的详细解读

资源摘要信息:"点云二值化测试数据" 知识点: 一、点云基础知识 1. 点云定义:点云是由点的集合构成的数据集,这些点表示物体表面的空间位置信息,通常由三维扫描仪或激光雷达(LiDAR)生成。 2. 点云特性:点云数据通常具有稠密性和不规则性,每个点可能包含三维坐标(x, y, z)和额外信息如颜色、反射率等。 3. 点云应用:广泛应用于计算机视觉、自动驾驶、机器人导航、三维重建、虚拟现实等领域。 二、二值化处理概述 1. 二值化定义:二值化处理是将图像或点云数据中的像素或点的灰度值转换为0或1的过程,即黑白两色表示。在点云数据中,二值化通常指将点云的密度或强度信息转换为二元形式。 2. 二值化的目的:简化数据处理,便于后续的图像分析、特征提取、分割等操作。 3. 二值化方法:点云的二值化可能基于局部密度、强度、距离或其他用户定义的标准。 三、点云二值化技术 1. 密度阈值方法:通过设定一个密度阈值,将高于该阈值的点分类为前景,低于阈值的点归为背景。 2. 距离阈值方法:根据点到某一参考点或点云中心的距离来决定点的二值化,距离小于某个值的点为前景,大于的为背景。 3. 混合方法:结合密度、距离或其他特征,通过更复杂的算法来确定点的二值化。 四、二值化测试数据的处理流程 1. 数据收集:使用相应的设备和技术收集点云数据。 2. 数据预处理:包括去噪、归一化、数据对齐等步骤,为二值化处理做准备。 3. 二值化:应用上述方法,对预处理后的点云数据执行二值化操作。 4. 测试与验证:采用适当的评估标准和测试集来验证二值化效果的准确性和可靠性。 5. 结果分析:通过比较二值化前后点云数据的差异,分析二值化效果是否达到预期目标。 五、测试数据集的结构与组成 1. 测试数据集格式:文件可能以常见的点云格式存储,如PLY、PCD、TXT等。 2. 数据集内容:包含了用于测试二值化算法性能的点云样本。 3. 数据集数量和多样性:根据实际应用场景,测试数据集应该包含不同类型、不同场景下的点云数据。 六、相关软件工具和技术 1. 点云处理软件:如CloudCompare、PCL(Point Cloud Library)、MATLAB等。 2. 二值化算法实现:可能涉及图像处理库或专门的点云处理算法。 3. 评估指标:用于衡量二值化效果的指标,例如分类的准确性、召回率、F1分数等。 七、应用场景分析 1. 自动驾驶:在自动驾驶领域,点云二值化可用于道路障碍物检测和分割。 2. 三维重建:在三维建模中,二值化有助于提取物体表面并简化模型复杂度。 3. 工业检测:在工业检测中,二值化可以用来识别产品缺陷或确保产品质量标准。 综上所述,点云二值化测试数据的处理是一个涉及数据收集、预处理、二值化算法应用、效果评估等多个环节的复杂过程,对于提升点云数据处理的自动化、智能化水平至关重要。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依