The Boolean object's properties and methods

博客主要介绍了布尔对象的属性和方法。给出了属性和方法的语法,通过代码示例展示了不同值转换为布尔值的结果,如0、空字符串、null、NaN为false,1和字符串'false'为true,还展示了toString方法的使用。

The Boolean object's properties and methods are described below:

NN: Netscape, IE: Internet Explorer

Properties

Syntax: object.property_name

PropertyDescriptionNNIE 
constructorContains the function that created an object's prototype44
prototypeAllows addition of properties and methods to the object34

Methods

Syntax: object.method_name()

MethodDescriptionNNIE
toString()Converts a Boolean value to a string. This method is called by JavaScript automatically whenever a Boolean object is used in a situation requiring a string44
valueOf()Returns a primitive value ("true" or "false") for the Boolean object44

<script type="text/javascript">
var b1=new Boolean( 0)
var b2=new Boolean(1)
var b3=new Boolean("")
var b4=new Boolean(null)
var b5=new Boolean(NaN)
var b6=new Boolean("false")

document.write("0 is boolean "+ b1 +"<br />")
document.write("1 is boolean "+ b2 +"<br />")
document.write("An empty string is boolean "+ b3 + "<br />")
document.write("null is boolean "+ b4+ "<br />")
document.write("NaN is boolean "+ b5 +"<br />")
document.write("The string 'false' is boolean "+ b6 +"<br />")
document.write("b1.toString()" + b1.toString() +"<br />")
document.write("b2.toString()" + b2.toString() +"<br />")
document.write("b3.toString()" + b3.toString() +"<br />")
document.write("b4.toString()" + b4.toString() +"<br />")
document.write("b5.toString()" + b5.toString() +"<br />")
document.write("b6.toString()" + b6.toString() +"<br />")
</script>

-----------------------------------------------------------------------------------------

0 is boolean false
1 is boolean true
An empty string is boolean false
null is boolean false
NaN is boolean false
The string 'false' is boolean true
b1.toString()false
b2.toString()true
b3.toString()false
b4.toString()false
b5.toString()false
b6.toString()true

Part 2: Java You are going to make a system that represents the seats in a venue, such as a theatre or a cinema, and a process for booking seats at events that are held in that venue. The tasks will get harder as you progress, and build on each other, so try to ensure that you complete each stage before moving on. We have provided initial versions of Seat.java and SeatType.java which you should use to complete the tasks. You can add any additional fields, methods, or modifiers to these classes as needed, and can also write and submit any additional classes that are needed, but please do not change the provided packages, class names, or method names. Here are the initial versions of the two files -- you should download these and use them to create your solution. SeatType.java Seat.java All classes you create should be in the boxOffice package. Java Task 2a: Representing individual seats (8 Marks) For our purposes, a seat has four core properties: The row, which must be a single character representing a capital letter A through Z The seat number, which must be a positive integer The seat type, which is represented by the provided SeatType enumerated type The availability, which is a Boolean value indicating whether the seat has been reserved 1. Write code to represent individual seats using the above properties. The full details of the implementation are up to you, but you must use the provided Seat.java file as a starting point for representing the core properties. A seat should be initially available when it is created, while the other properties should be set in the constructor. [4 marks] 2. Be sure that your constructor validates that the values of all core properties are valid: that is, the row and seat number are in range. If an attempt is made to create a seat object with invalid values, your constructor should throw an IllegalArgumentException with a descriptive message. [2 marks] 3. Include getter methods for all core properties, as well as a setter method for the availability property only. [1 mark] Java Task 2b: Representing a venue (8 Marks) A venue is a location such as a theatre which has a number of rows, each of which has a number of seats. The row letters always start at A, and the seat numbers always start at 1. Note that the number and distribution of seats may be different in each row. There can be at most 26 rows. For example, the following might be the seat configuration in a very small venue: Row/Seat 1 2 3 4 5 6 A Standard Deluxe Deluxe Standard B Deluxe Deluxe Deluxe C Standard Standard Standard Standard Standard Standard A venue configuration can be given by a string of the following format: - First line: number of rows - Remaining lines: seat configuration in each row, separated by spaces For example, the above venue would be specified by the following string: 3 S D D S D D D S S S S S S In Java, you could specify this string like this: “3\nS D D S\nD D D\nS S S S S S” 1. Create a class called Venue to represent the seats in a venue as described above, using your Seat class from Task 2a. You can use whatever internal representation you choose. Your class should have one constructor which should take a string like above and create the necessary Seat objects. You can assume that the string is well-formed and do not need to do any error checking. [4 marks] 2. Add a method to the Venue class with the following signature: public Seat getSeat (char row, int seatNum) This method should return the Seat object corresponding to the given row and seat number. If the row or seat number is invalid, this method should throw an IllegalArgumentException with a descriptive message. [2 marks] 3. Add a method to the Venue class with the following signature: public void printDetails() This method should print out the details of all seats in all rows of the venue in a human-readable form. The details are up to you, but simply using toString() on the internal representation will not be sufficient for full marks. [2 marks] Java Task 2c: Representing an event (8 Marks) An Event is a particular show that takes place at a venue. The details of an event include: The venue where the event will take place A price structure for tickets – that is, the price in pounds of each ticket type. For example, this might be: Standard tickets: £10 Deluxe tickets: £20 An event also allows seats to be reserved – a customer can request one or more seats of a given type (Standard or Deluxe). If a customer is booking more than one seat, the seats must be adjacent – that is, the seats must have consecutive numbers and be in the same row. Once a seat has been reserved by a customer, it cannot be reserved by another unless the seat is returned. 1. Create an Event class to represent the details of an event, using the classes from the previous tasks. You can assume that all ticket prices can be represented as integers. [2 marks] 2. Add a method reserveSeats to the Event class with the following signature: public int reserveSeats (int numSeats, SeatType seatType) This method should attempt to find the indicated number of adjacent seats of the given type that are available. If enough seats are found, they should all be reserved, and the total price of the seats returned. If enough seats are not found, no seats should be reserved and the method should return -1. [4 marks] 3. Add a method returnSeat to the Event class with the following signature: public void returnSeat (char row, intSeatNum) If the indicated seat is reserved, it should be made available again. If the indicated seat is already available, or if the row and seat number are invalid, this method should throw an IllegalArgumentException with appropriate information. [2 marks] Java submission Be sure that your classes are named as above, and that all classes are in the boxOffice package. You must submit all the .java files you wrote, including the final versions of Seat.java and SeatType.java. 按照题目中给的变量和参数执行
12-10
内容概要:本文档是一份关于交换路由配置的学习笔记,系统地介绍了网络设备的远程管理、交换机与路由器的核心配置技术。内容涵盖Telnet、SSH、Console三种远程控制方式的配置方法;详细讲解了VLAN划分原理及Access、Trunk、Hybrid端口的工作机制,以及端口镜像、端口汇聚、端口隔离等交换技术;深入解析了STP、MSTP、RSTP生成树协议的作用与配置步骤;在路由部分,涵盖了IP地址配置、DHCP服务部署(接口池与全局池)、NAT转换(静态与动态)、静态路由、RIP与OSPF动态路由协议的配置,并介绍了策略路由和ACL访问控制列表的应用;最后简要说明了华为防火墙的安全区域划分与基本安全策略配置。; 适合人群:具备一定网络基础知识,从事网络工程、运维或相关技术岗位1-3年的技术人员,以及准备参加HCIA/CCNA等认证考试的学习者。; 使用场景及目标:①掌握企业网络中常见的交换与路由配置技能,提升实际操作能力;②理解VLAN、STP、OSPF、NAT、ACL等核心技术原理并能独立完成中小型网络搭建与调试;③通过命令示例熟悉华为设备CLI配置逻辑,为项目实施和故障排查提供参考。; 阅读建议:此笔记以实用配置为主,建议结合模拟器(如eNSP或Packet Tracer)动手实践每一条命令,对照拓扑理解数据流向,重点关注VLAN间通信、路由选择机制、安全策略控制等关键环节,并注意不同设备型号间的命令差异。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值