Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab submissions-IT11121Agic ITI 1121 Laborary 5 (2019) e HomelChegg.com Not secure l www.site.uottawa.ca/~JY/Courses/IT11121/lectures/labs/lab5-2019.html In this first part, we are going to create a simple class

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Lab submissions-IT11121Agic ITI 1121 Laborary 5 (2019) e HomelChegg.com Not secure l www.site.uottawa.ca/~JY/Courses/IT11121/lectures/labs/lab5-2019.html In this first part, we are going to create a simple class Book. This class is quite minimal. It contains the following: .An instance variable author of type String .An instance variable title of type String An instance variable year of type int (the publication year of that book); .A contructor Book(String author, String title, int year), which receives that new instance's author, title and publication year as paramters; .A method toString), which returns a String representation of that instance, using the format "author: title (yearl; .A method equals(Object o) We want our implementation to be as robust as possible. In particular, the method equals should handle every particular case you can think about. To help you with this, we have created the class TestBook.java: public class TestBook f public static void main(String] args) Book b1-new Book("D. Knuth", "TAOCP", 1978); Book b2new Book("D. Knuth", "TAOCP", 1971); Book b3new Book ("D. IAmNotKnuth", "TAOCP, 197e); Book b4new Book ("D. Knuth", "TAOCP v2", 1978); Book bs- new Book("D. Knuth", "TAOCP", 1978) 4:01 PM Type here to search 2/16/2019 Lab submissions-IT11121Agic ITI 1121 Laborary 5(2019) e HomelChegg.com Not secure l www.site.uottawa.ca/~JY/Courses/IT11121/lectures/labs/lab5-2019.html System.out.println(bi"equals"b2 + ":"+ b1.equals (b2)) System.out.println(bi "equals"b3":"b1.equals (b3)); System.out.println(bl" equals "b4 ":" b1.equals (b4)) System.out.println(b1" equals "b5b1.equals (b5) Book b6 new Book (nul1, "TAOCP", 1971); Book b7new Book("D. IAmNotKnuth", null, 197e); System.out.printin(b1equals "+b6 ":"b1.equals(b6)); System.out.println(bi"equalsb7":"b1.equals(b7)); System.out.println(bl"equals "null + ": " + b1.equals (null)) System.out.println (b6 "equals"b1 + ":"+ b6.equals (b1)) System.out.printin(b7equals "+b1":"b7.equals (b1)); System.out.println(b6 " equals b6":"+b6.equals (b6)) System.out.println (b7 equals b7b7.equals(b7) Executing the code above generates the following output: javac TestBook.java java TestBook D. Knuth: TAOCP (197e) equals D. Knuth: TAOCP (1971): false D. Knuth: TAOCP (197) equals D. IAmNotknuth TAOCP (1976): false D. Knuth TAOCP (197e) equals D. Knuth: TAOCP v2 (197e) false D. Knuth: TAOCP (197e) equals D. Knuth: TAOCP (1970): true D. Knuth: TAOCP (1976) equals nul1: TAOCP (1971): false D. Knuth: TAOCP (197) equals D. IAmNotknuth nul1 (1970): false 4:01 PM Type here to search 2/16/2019 Lab submissions-IT11121Agic ITI 1121 Laborary 5 (2019) e HomelChegg.com Not secure l www.site.uottawa.ca/~JY/Courses/IT11121/lectures/labs/lab5-2019.html Executing the code above generates the following output: javac TestBook.java java TestBook D. Knuth: TAOCP (197e) equals D. Knuth: TAOCP (1971): false D. Knuth: TAOCP (197) equals D. IAmNotknuth TAOCP (1976): false D. Knuth TAOCP (197e) equals D. Knuth: TAOCP v2 (197e) false D. Knuth: TAOCP (197e) equals D. Knuth: TAOCP (1970): true D. Knuth: TAOCP (1976) equals nul1: TAOCP (1971): false D. Knuth: TAOCP (197) equals D. IAmNotknuth nul1 (1970): false D. Knuth TAOCP (197e) equals null: false null: TAOCP (1971) equals D. Knuth: TAOCP (197e): false D. IAmNotknuth: null (1978) equals D. Knuth: TAOCP (1978): false null: TAOCP (1971) equals null: TAOCP (1971): true D. IAmNotKnuth: null (1970) equals D. IAmNotKnuth: null (197e) true Question 1.1 Provide an implementation of the class Book. Use the provided template as a starting point. At minimum, you should make sure that the program TestBook.java works and provides the expected output with your implementation. 4:01 PM Type here to search 2/16/2019 Bookjava Sublime Text (UNREGISTERED) File Edit Selection Find View Goto Tools Project Preferences Help x Bookcomparatorjava xibrary AbstractSeries.java xGeometric-java Book.java Arithmetic)ava // Your variables declaration here public Book (String author, String title, int year) // Your code here public String getAuthor() // Your code here 10 12 13 14. 15 16 17 18 19 20 21 public String getTitle) // Your code here public int getYear) // Your code here public boolean equals (Object other) // Your code here 23 24 25 26 27 28 public String toString) // Your code here Line 28, Column 2 Spaces: 4 4:01 PM Type here to search 2/16/2019

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 11G SQL

Authors: Joan Casteel

2nd Edition

1133947360, 978-1133947363

More Books

Students also viewed these Databases questions