Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

March 2018 ITI 1121 Page 2 of 17 Question 1 (35 marks) This question is about object-oriented programming in Java. Specifically, this is a small

image text in transcribedimage text in transcribed

March 2018 ITI 1121 Page 2 of 17 Question 1 (35 marks) This question is about object-oriented programming in Java. Specifically, this is a small part of a software system that you are developing for a supermarket chain. We are focussing on 2 types of goods, "books" and "baskets of nuts", and the part of the software system that computes the price of good and services after taxes for all items sold by the chain, in every province. GoodsAndServices + getPrice: double TaxedPrice Book - year: int - title : String - author : String - price : double Nuts Basket - Weight : int - nutsType : String + ON. + OC ... + toString: String + price Taxes Included: double + equals : boolean + toString : String In our software system, every object representing a good or a service, which includes objects of the classes Book and Nuts Basket, can be seen as a GoodsAndServices. A GoodsAndServices has a method called getPrice, which returns a double value that is the price of that good or service before taxes. Book has 4 instance variables: the price before taxes of the book, of type double, the year of pub- lication, of type int, and then two instances of String for the title and the author of the book. The constructor of the class receives these 4 elements of information as parameters. You need to also include three methods in Book: first, the instance method toString, which should behave as shown in the example below. Second, the instance method equals. Two books should be considered the same if they have the same title and author, and are published the same year. Finally, for getPrice, the price before tax of a book has been received as a parameter to the constructor. Nuts Basket has 2 instance variables, the nutsType, of type String, and the weight in grams, which is an int. The constructor of the class receives these 2 elements of information as parameters. The class will also need an implementation of the instance method toString. In the case of a Nuts Basket, the price before taxes is 0.1$ per gram. The Java source code below shows the intended use of the classes and their methods. March 2018 ITI 1121 Page 3 of 17 Book bl, b2, 63: b1 = new Book (1996, "John Smith", "Java for durmies". 85.0); b2 = new Book (1996. "John Smith", "Java for dummies". 40.0); b3 = new Book (2010. "Jane Adam", "Python for dummies", 50.0): System.out.println (1): System.out.println (b2): System.out.println(63): System.out.println(bl.equals(2)): System.out.println (bl.equals (63)); Nuts Basket nl, n2; n1 = new Nuts Basket ("Pistachios", 150); n2 = new Nuts Basket ("Almonds". 400): System.out.println(nl): System.out.println (n2): The execution of the above program should produce the following output on the console. "Java for dummies" by John Smith, sold for 85.0$ plus taxes "Java for dummies" by John Smith, sold for 40.0$ plus taxes "Python for dummies" by Jane Adam, sold for 50.0$ plus taxes true false basket of Pistachios costing 15.0$ plus taxes basket of Almonds costing 40.0$ plus taxes In the boxes next pages, you need to provide all the code necessary for this to work as described. March 2018 ITI 1121 Page 2 of 17 Question 1 (35 marks) This question is about object-oriented programming in Java. Specifically, this is a small part of a software system that you are developing for a supermarket chain. We are focussing on 2 types of goods, "books" and "baskets of nuts", and the part of the software system that computes the price of good and services after taxes for all items sold by the chain, in every province. GoodsAndServices + getPrice: double TaxedPrice Book - year: int - title : String - author : String - price : double Nuts Basket - Weight : int - nutsType : String + ON. + OC ... + toString: String + price Taxes Included: double + equals : boolean + toString : String In our software system, every object representing a good or a service, which includes objects of the classes Book and Nuts Basket, can be seen as a GoodsAndServices. A GoodsAndServices has a method called getPrice, which returns a double value that is the price of that good or service before taxes. Book has 4 instance variables: the price before taxes of the book, of type double, the year of pub- lication, of type int, and then two instances of String for the title and the author of the book. The constructor of the class receives these 4 elements of information as parameters. You need to also include three methods in Book: first, the instance method toString, which should behave as shown in the example below. Second, the instance method equals. Two books should be considered the same if they have the same title and author, and are published the same year. Finally, for getPrice, the price before tax of a book has been received as a parameter to the constructor. Nuts Basket has 2 instance variables, the nutsType, of type String, and the weight in grams, which is an int. The constructor of the class receives these 2 elements of information as parameters. The class will also need an implementation of the instance method toString. In the case of a Nuts Basket, the price before taxes is 0.1$ per gram. The Java source code below shows the intended use of the classes and their methods. March 2018 ITI 1121 Page 3 of 17 Book bl, b2, 63: b1 = new Book (1996, "John Smith", "Java for durmies". 85.0); b2 = new Book (1996. "John Smith", "Java for dummies". 40.0); b3 = new Book (2010. "Jane Adam", "Python for dummies", 50.0): System.out.println (1): System.out.println (b2): System.out.println(63): System.out.println(bl.equals(2)): System.out.println (bl.equals (63)); Nuts Basket nl, n2; n1 = new Nuts Basket ("Pistachios", 150); n2 = new Nuts Basket ("Almonds". 400): System.out.println(nl): System.out.println (n2): The execution of the above program should produce the following output on the console. "Java for dummies" by John Smith, sold for 85.0$ plus taxes "Java for dummies" by John Smith, sold for 40.0$ plus taxes "Python for dummies" by Jane Adam, sold for 50.0$ plus taxes true false basket of Pistachios costing 15.0$ plus taxes basket of Almonds costing 40.0$ plus taxes In the boxes next pages, you need to provide all the code necessary for this to work as described

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

Database Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions