public class Item { private String itemName; private double value; } // one argument constructor using...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
public class Item { private String itemName; private double value; } // one argument constructor using value attribute public Item(double value) { this.value = value; } // two argument constructor public Item(String name, double value) { this.itemName = name; this.value = value; } public String getItemName() { return itemName; } public void setItemName(String itemName) { this.itemName = itemName; } public double getValue() { return value; } public void setValue(double value) { this.value = value; } this.value; } public String toString() { "I String result = "Item name: + this.itemName + " Item value: + return result; 1 11 O ZOOM + import java.util.ArrayList; // This class CANNOT be instantiated. // (You can not create objects of this class.) public interface ItemCollection { } // Abstract Methods // (Their implementations are not specified.) public double returnCollectionValue(); public void printItemList(); public void add(Item e); public void combineCollections (ArrayList newItems); 3 public class CollectionDriver1 { public static void main(String[] args) { System.out.println("This is a record of all the items of value I own:"); } } Item item1 = new Item("Computer", 500); System.out.println(item1.toString()); Item item2 = new Item("Bike", 300); System.out.println(item2.toString()); Item item3 = new Item("Phone", 200); System.out.println(item3.toString()); Item item4 = new Item("Guitar", 500); System.out.println(item4.toString()); Item item5 = new Item("Book", 10); System.out.println(item5.toString()); // For PART 1: Add some more items here! 2 import java.util.ArrayList; public class MyItemCollection implements ItemCollection{ private ArrayList items; } public MyItemCollection() { } @Override public double returnCollectionValue() { double collectionValue = 0; for (Item i: this.items) { } this.items = new ArrayList (); } @Override // This method should print the names of the items in the collection, // with one item name per line. public void printItemList() { } collectionValue += i.getValue(); } return collectionValue; @Override public void add(Item e) { this.items.add(e); } // PART 2.1: YOUR CODE HERE! @Override public void combineCollections (ArrayList newItems) { for (Item i: newItems) { this.items.add(i); } } public ArrayList getItems() { return items; public void setItems (ArrayList items) { this.items - items; 4 public class CollectionDriver2 { public static void main(String[] args) { MyItemCollection myBooks = new MyItemCollection(); Book book1 = new Book ("The Phantom Tollbooth", "Juster"); Book book2 = new Book ("Where the Wild Things Are", "Maurice", 5 "Sendak"); } } Book book3 = book2; myBooks.add(book1); myBooks.add(book2); myBooks.add(book3); myBooks.printItemList(); System.out.println(book3 == book2); System.out.println(book3.equals(book2)); // This class inherits from the Item superclass. public class Book extends Item{ private String title; private String authorLast; private String authorFirst; private int numPages; public Book (String title, String authorFirst, String authorLast, double value, int numPages) { super (value); // Note the use of super here this.title = title; this.author First = author First; this.author Last = = author Last; this.numPages = numPages; } public value) { } public Book (String title, String authorFirst, String author Last) { super (0); Book (String title, String authorFirst, String authorLast, double super (value); this.title = title; this.author First = author First; this.author Last = author Last; this.setNumPages(-1); } } public Book(String title, String authorLast) { super (0); this.title = title; this.author First = author First; this.author Last = author Last; this.setNumPages (-1); } this.title = title; this.author First = "unknown"; this.author Last = author Last; this.setNumPages(-1); public String getTitle() { return title; 6A } public void setAuthorLast(String authorLast) { this.author Last = author Last; } } public String getAuthorFirst() { return author First; } public void setAuthor First(String author First) { this.author First = author First; } public int getNumPages() { return numPages; } public void setNumPages(int numPages) { this.numPages = numPages; } // HW Problem 2.2 // Override the equals() method below I have the determination based on the following: For 2 book objects to be equal, the following must be true: // 1) The two books must have the same title AND // 2) The two book authors must have the same author LAST NAME. // Write your method so that the titles and author names do not have to match upper/lower case exactly. ---- } 6C ---- //(i.e. Ignore case) public boolean equals(Book b) { // PART 2.2: YOUR CODE HERE! return false; import java.util.ArrayList; public class CollectionDriver3 { public static void main(String[] args) { "Sendak"); } } MyItemCollection myBooks = new MyItemCollection(); Book book1 = new Book ("The Phantom Tollbooth", "Juster"); Book book2 = new Book ("Where the Wild Things Are", "Maurice", Book book3 = book2; Book book4= new Book ("Where the Wild Things Are", "Sendak"); myBooks.add(book1); myBooks.add(book2); myBooks.add(book3); myBooks.add(book4); System.out.println(book3 == book2); System.out.println(book3.equals(book2)); System.out.println(book3.equals(book4)); System.out.println(book3 == book4); 7 import java.util.ArrayList; public class CollectionDriver4 { public static void main(String[] args) { "Sendak"); "Herriot"); } } MyItemCollection myBooks = new MyItemCollection(); Book book1 = new Book ("The Phantom Tollbooth", "Juster"); Book book2 = new Book ("Where the Wild Things Are", "Maurice", Book book3 = new Book ("All Creatures Great and Small", "James", myBooks.add(book1); myBooks.add(book2); myBooks.add(book3), // Add more books! ArrayList currentList = myBooks.getItems(); currentList.sort(null); myBooks.setItems(currentList); myBooks.printItemList(); 8 public Book (String title, String authorLast) { super (0); } public String getTitle() { return title; this.title = title; this.author First = "unknown"; this.author Last = author Last; this.setNumPages (-1); } // Override the Item class method // the book title as the item name. public String getItemName() { return title; } public void setTitle(String title) { this.title = title; } public String getAuthorLast() { return author Last; } } since we want to use public void setAuthor Last(String author Last) { this.author Last = author Last; 6b import java.util.ArrayList; public class CollectionDriver5 { public static void printItems (ArrayList books) { for (Book b: books) { System.out.println(b.getTitle()); } } } public static void main(String[] args) { ArrayList myBooks = new ArrayList (); Book book1 = new Book ("The Phantom Tollbooth", 'Juster"); Book book2 = new Book ("Where the Wild Things Are", "Maurice", Book book3 = new Book ("All Creatures Great and Small", "Sendak"); "Herriot"); } // Add more books! myBooks.add(book1); myBooks.add(book2); myBooks.add(book3); myBooks. sort(null); printItems(myBooks); 'James", 11 9 public class Item { private String itemName; private double value; } // one argument constructor using value attribute public Item(double value) { this.value = value; } // two argument constructor public Item(String name, double value) { this.itemName = name; this.value = value; } public String getItemName() { return itemName; } public void setItemName(String itemName) { this.itemName = itemName; } public double getValue() { return value; } public void setValue(double value) { this.value = value; } this.value; } public String toString() { "I String result = "Item name: + this.itemName + " Item value: + return result; 1 11 O ZOOM + public class Item { private String itemName; private double value; } // one argument constructor using value attribute public Item(double value) { this.value = value; } // two argument constructor public Item(String name, double value) { this.itemName = name; this.value = value; } public String getItemName() { return itemName; } public void setItemName(String itemName) { this.itemName = itemName; } public double getValue() { return value; } public void setValue(double value) { this.value = value; } this.value; } public String toString() { "I String result = "Item name: + this.itemName + " Item value: + return result; 1 11 O ZOOM + import java.util.ArrayList; // This class CANNOT be instantiated. // (You can not create objects of this class.) public interface ItemCollection { } // Abstract Methods // (Their implementations are not specified.) public double returnCollectionValue(); public void printItemList(); public void add(Item e); public void combineCollections (ArrayList newItems); 3 import java.util.ArrayList; // This class CANNOT be instantiated. // (You can not create objects of this class.) public interface ItemCollection { } // Abstract Methods // (Their implementations are not specified.) public double returnCollectionValue(); public void printItemList(); public void add(Item e); public void combineCollections (ArrayList newItems); 3 public class CollectionDriver1 { public static void main(String[] args) { System.out.println("This is a record of all the items of value I own:"); } } Item item1 = new Item("Computer", 500); System.out.println(item1.toString()); Item item2 = new Item("Bike", 300); System.out.println(item2.toString()); Item item3 = new Item("Phone", 200); System.out.println(item3.toString()); Item item4 = new Item("Guitar", 500); System.out.println(item4.toString()); Item item5 = new Item("Book", 10); System.out.println(item5.toString()); // For PART 1: Add some more items here! 2 public class CollectionDriver1 { public static void main(String[] args) { System.out.println("This is a record of all the items of value I own:"); } } Item item1 = new Item("Computer", 500); System.out.println(item1.toString()); Item item2 = new Item("Bike", 300); System.out.println(item2.toString()); Item item3 = new Item("Phone", 200); System.out.println(item3.toString()); Item item4 = new Item("Guitar", 500); System.out.println(item4.toString()); Item item5 = new Item("Book", 10); System.out.println(item5.toString()); // For PART 1: Add some more items here! 2 import java.util.ArrayList; public class MyItemCollection implements ItemCollection{ private ArrayList items; } public MyItemCollection() { } @Override public double returnCollectionValue() { double collectionValue = 0; for (Item i: this.items) { } this.items = new ArrayList (); } @Override // This method should print the names of the items in the collection, // with one item name per line. public void printItemList() { } collectionValue += i.getValue(); } return collectionValue; @Override public void add(Item e) { this.items.add(e); } // PART 2.1: YOUR CODE HERE! @Override public void combineCollections (ArrayList newItems) { for (Item i: newItems) { this.items.add(i); } } public ArrayList getItems() { return items; public void setItems (ArrayList items) { this.items - items; 4 import java.util.ArrayList; public class MyItemCollection implements ItemCollection{ private ArrayList items; } public MyItemCollection() { } @Override public double returnCollectionValue() { double collectionValue = 0; for (Item i: this.items) { } this.items = new ArrayList (); } @Override // This method should print the names of the items in the collection, // with one item name per line. public void printItemList() { } collectionValue += i.getValue(); } return collectionValue; @Override public void add(Item e) { this.items.add(e); } // PART 2.1: YOUR CODE HERE! @Override public void combineCollections (ArrayList newItems) { for (Item i: newItems) { this.items.add(i); } } public ArrayList getItems() { return items; public void setItems (ArrayList items) { this.items - items; 4 public class CollectionDriver2 { public static void main(String[] args) { MyItemCollection myBooks = new MyItemCollection(); Book book1 = new Book ("The Phantom Tollbooth", "Juster"); Book book2 = new Book ("Where the Wild Things Are", "Maurice", 5 "Sendak"); } } Book book3 = book2; myBooks.add(book1); myBooks.add(book2); myBooks.add(book3); myBooks.printItemList(); System.out.println(book3 == book2); System.out.println(book3.equals(book2)); public class CollectionDriver2 { public static void main(String[] args) { MyItemCollection myBooks = new MyItemCollection(); Book book1 = new Book ("The Phantom Tollbooth", "Juster"); Book book2 = new Book ("Where the Wild Things Are", "Maurice", 5 "Sendak"); } } Book book3 = book2; myBooks.add(book1); myBooks.add(book2); myBooks.add(book3); myBooks.printItemList(); System.out.println(book3 == book2); System.out.println(book3.equals(book2)); // This class inherits from the Item superclass. public class Book extends Item{ private String title; private String authorLast; private String authorFirst; private int numPages; public Book (String title, String authorFirst, String authorLast, double value, int numPages) { super (value); // Note the use of super here this.title = title; this.author First = author First; this.author Last = = author Last; this.numPages = numPages; } public value) { } public Book (String title, String authorFirst, String author Last) { super (0); Book (String title, String authorFirst, String authorLast, double super (value); this.title = title; this.author First = author First; this.author Last = author Last; this.setNumPages(-1); } } public Book(String title, String authorLast) { super (0); this.title = title; this.author First = author First; this.author Last = author Last; this.setNumPages (-1); } this.title = title; this.author First = "unknown"; this.author Last = author Last; this.setNumPages(-1); public String getTitle() { return title; 6A // This class inherits from the Item superclass. public class Book extends Item{ private String title; private String authorLast; private String authorFirst; private int numPages; public Book (String title, String authorFirst, String authorLast, double value, int numPages) { super (value); // Note the use of super here this.title = title; this.author First = author First; this.author Last = = author Last; this.numPages = numPages; } public value) { } public Book (String title, String authorFirst, String author Last) { super (0); Book (String title, String authorFirst, String authorLast, double super (value); this.title = title; this.author First = author First; this.author Last = author Last; this.setNumPages(-1); } } public Book(String title, String authorLast) { super (0); this.title = title; this.author First = author First; this.author Last = author Last; this.setNumPages (-1); } this.title = title; this.author First = "unknown"; this.author Last = author Last; this.setNumPages(-1); public String getTitle() { return title; 6A } public void setAuthorLast(String authorLast) { this.author Last = author Last; } } public String getAuthorFirst() { return author First; } public void setAuthor First(String author First) { this.author First = author First; } public int getNumPages() { return numPages; } public void setNumPages(int numPages) { this.numPages = numPages; } // HW Problem 2.2 // Override the equals() method below I have the determination based on the following: For 2 book objects to be equal, the following must be true: // 1) The two books must have the same title AND // 2) The two book authors must have the same author LAST NAME. // Write your method so that the titles and author names do not have to match upper/lower case exactly. ---- } 6C ---- //(i.e. Ignore case) public boolean equals(Book b) { // PART 2.2: YOUR CODE HERE! return false; } public void setAuthorLast(String authorLast) { this.author Last = author Last; } } public String getAuthorFirst() { return author First; } public void setAuthor First(String author First) { this.author First = author First; } public int getNumPages() { return numPages; } public void setNumPages(int numPages) { this.numPages = numPages; } // HW Problem 2.2 // Override the equals() method below I have the determination based on the following: For 2 book objects to be equal, the following must be true: // 1) The two books must have the same title AND // 2) The two book authors must have the same author LAST NAME. // Write your method so that the titles and author names do not have to match upper/lower case exactly. ---- } 6C ---- //(i.e. Ignore case) public boolean equals(Book b) { // PART 2.2: YOUR CODE HERE! return false; import java.util.ArrayList; public class CollectionDriver3 { public static void main(String[] args) { "Sendak"); } } MyItemCollection myBooks = new MyItemCollection(); Book book1 = new Book ("The Phantom Tollbooth", "Juster"); Book book2 = new Book ("Where the Wild Things Are", "Maurice", Book book3 = book2; Book book4= new Book ("Where the Wild Things Are", "Sendak"); myBooks.add(book1); myBooks.add(book2); myBooks.add(book3); myBooks.add(book4); System.out.println(book3 == book2); System.out.println(book3.equals(book2)); System.out.println(book3.equals(book4)); System.out.println(book3 == book4); 7 import java.util.ArrayList; public class CollectionDriver3 { public static void main(String[] args) { "Sendak"); } } MyItemCollection myBooks = new MyItemCollection(); Book book1 = new Book ("The Phantom Tollbooth", "Juster"); Book book2 = new Book ("Where the Wild Things Are", "Maurice", Book book3 = book2; Book book4= new Book ("Where the Wild Things Are", "Sendak"); myBooks.add(book1); myBooks.add(book2); myBooks.add(book3); myBooks.add(book4); System.out.println(book3 == book2); System.out.println(book3.equals(book2)); System.out.println(book3.equals(book4)); System.out.println(book3 == book4); 7 import java.util.ArrayList; public class CollectionDriver4 { public static void main(String[] args) { "Sendak"); "Herriot"); } } MyItemCollection myBooks = new MyItemCollection(); Book book1 = new Book ("The Phantom Tollbooth", "Juster"); Book book2 = new Book ("Where the Wild Things Are", "Maurice", Book book3 = new Book ("All Creatures Great and Small", "James", myBooks.add(book1); myBooks.add(book2); myBooks.add(book3), // Add more books! ArrayList currentList = myBooks.getItems(); currentList.sort(null); myBooks.setItems(currentList); myBooks.printItemList(); 8 import java.util.ArrayList; public class CollectionDriver4 { public static void main(String[] args) { "Sendak"); "Herriot"); } } MyItemCollection myBooks = new MyItemCollection(); Book book1 = new Book ("The Phantom Tollbooth", "Juster"); Book book2 = new Book ("Where the Wild Things Are", "Maurice", Book book3 = new Book ("All Creatures Great and Small", "James", myBooks.add(book1); myBooks.add(book2); myBooks.add(book3), // Add more books! ArrayList currentList = myBooks.getItems(); currentList.sort(null); myBooks.setItems(currentList); myBooks.printItemList(); 8 public Book (String title, String authorLast) { super (0); } public String getTitle() { return title; this.title = title; this.author First = "unknown"; this.author Last = author Last; this.setNumPages (-1); } // Override the Item class method // the book title as the item name. public String getItemName() { return title; } public void setTitle(String title) { this.title = title; } public String getAuthorLast() { return author Last; } } since we want to use public void setAuthor Last(String author Last) { this.author Last = author Last; 6b public Book (String title, String authorLast) { super (0); } public String getTitle() { return title; this.title = title; this.author First = "unknown"; this.author Last = author Last; this.setNumPages (-1); } // Override the Item class method // the book title as the item name. public String getItemName() { return title; } public void setTitle(String title) { this.title = title; } public String getAuthorLast() { return author Last; } } since we want to use public void setAuthor Last(String author Last) { this.author Last = author Last; 6b import java.util.ArrayList; public class CollectionDriver5 { public static void printItems (ArrayList books) { for (Book b: books) { System.out.println(b.getTitle()); } } } public static void main(String[] args) { ArrayList myBooks = new ArrayList (); Book book1 = new Book ("The Phantom Tollbooth", 'Juster"); Book book2 = new Book ("Where the Wild Things Are", "Maurice", Book book3 = new Book ("All Creatures Great and Small", "Sendak"); "Herriot"); } // Add more books! myBooks.add(book1); myBooks.add(book2); myBooks.add(book3); myBooks. sort(null); printItems(myBooks); 'James", 11 9 import java.util.ArrayList; public class CollectionDriver5 { public static void printItems (ArrayList books) { for (Book b: books) { System.out.println(b.getTitle()); } } } public static void main(String[] args) { ArrayList myBooks = new ArrayList (); Book book1 = new Book ("The Phantom Tollbooth", 'Juster"); Book book2 = new Book ("Where the Wild Things Are", "Maurice", Book book3 = new Book ("All Creatures Great and Small", "Sendak"); "Herriot"); } // Add more books! myBooks.add(book1); myBooks.add(book2); myBooks.add(book3); myBooks. sort(null); printItems(myBooks); 'James", 11 9
Expert Answer:
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date:
Students also viewed these programming questions
-
Data set Theory Assume an informational record with one association parent including matches (a, b) where a can't try not to be a parent of b. (a) Write a Datalog demand which gives the graph of...
-
Below is the code and the output from the code running. I need help with the Subscription list class. More specifcally the add method. This code created an arraylist of objects and i am not sure how...
-
A yo-yo moves downward until it reaches the end of its string, where it "sleeps." As it sleeps-that is, spins in place-its angular speed decreases from 35 rad/s to 25 rad/s. During this time it...
-
Backus Inc. makes and sells many consumer products. The firm's average contribution margin ratio is 35%. Management is considering adding a new product that will require an additional $15.000 per...
-
Now that we are at the midpoint of the course, it is important to pause and reflect on your course experience thus far. In your initial reply, answer the following questions: 1. What are you doing to...
-
Lisa Sheraton, accountant for Chase Home Finance, was injured in a boating accident. Another employee prepared the accompanying income statement for the year ended December 31, 2008. The individual...
-
The yield of a chemical process is being studied. From previous experience yield is known to be normally distributed and = 3. The past five days of plant operation have resulted in the following...
-
Relating to a project about starting a commercial cleaning business, answer these questions: Why: What is the problem this project will solve? What is the purpose for it? Why is it important? When:...
-
Keeper Corporations income statement for the year ended June 30, 2014, and its comparative balance sheets for June 30, 2014 and 2013 follow. Keeper Corporation Income Statement For the Year Ended...
-
A host in an IPv6 subnet is to be assigned an IPv6 address. The global routing prefix (aka network id ) assigned to this subnet is 3A00:006E:C000/48. The subnet id assigned to this subnet is A2. The...
-
You work for a specialty precision parts firm that has a 30% market share in the industry. According to your market research, the total demand for the product you manufacture will be around 200,000....
-
Cullumber Modernas of Juarez, Mexico, is contemplating a major change in its cost structure. Currently, all of its drafting work is performed by skilled draftsmen. Rafael Jiminez, Cullumber's owner,...
-
Develop a Handout on Ways to Increase Employee Engagement and Organizational Commitment. Explore the concepts of employee engagement and organizational commitment. Specifically, you will develop a...
-
The shareholders' equity of ILP Industries includes the items shown below. The board of directors of ILP declared cash dividends of $14 million, $30 million, and $170 million in its first three years...
-
The following budget information is available for the Arch Company for January Year 2 Sales $860,000 Cost of goods sold 540,000 Utilities expense 2,800 Administrative salaries 100,000 Sales...
-
25. Stanford-Binet IQ scores have a mean of 100 and a standard deviation of 16. Dmitri has an estimated IQ of 79. Given this information, answer the following: a. What is Dmitri's raw IQ score...
-
Which of the followingcarbocations is the least stable? CH3CH2 . CH3CHCH3 CH3 I . CH3C0 T CH3 IV. V. CH3 CH3CCH2 CH3
-
Write an application based on the application in Exercise 14.11 that inputs a line of text and uses String method indexOf to determine the total number of occurrences of each letter of the alphabet...
-
Each of the counter-controlled for loops we used in this chapters examples can be implemented using IntStreams rangeClosed method to produce a range of values, then using IntStreams forEach method to...
-
Explain two usages of the super keyword, and state some of the advantages of each type of usage.
-
What is the difference between a primary beneficiary relationship and a foreseen party relationship?
-
What is the difference between a privity relationship and a primary beneficiary relationship?
-
What is the difference between a foreseen party relationship and a foreseeable party relationship?
Study smarter with the SolutionInn App