Question: Find errors and fix: //package it313.thf; public class Coin extends Collectable { private int denomination; private int year; public Coin(int id, String desc, double price,

Find errors and fix:

//package it313.thf; public class Coin extends Collectable { private int denomination; private int year; public Coin(int id, String desc, double price, int denom, int year) { //super shoyuld be the first statement super(id, desc, price); this.denomination = denom; this.year = year; } //@override was missing "@" @Override public String toString( ) { return String.format("%d %d %d", super.toString( ), denomination, year); } } 

// collectable

//package Partb; public class Collectable { private int id; private String description; private double price; public Collectable(int id, String desc, double price) { this.id = id; this.description = desc; this.price = price; } private int getId( ) { return id; } @Override //toSting method was missing "()" public String toString(){ return String.format("%s %s %.2f", id, description, price); } }

// CollectiblesStore

///package it313.thf; import java.util.*; //incorrect syntax for iterator. // the class should be public not private public class CollectablesStore implements Iterator { private HashMap hm; public void CollectablesStore() { hm = new HashMap(); } @Override //incorrect syntax for iterator public Iterator iterator() { return hm.values().iterator(); } public void store(Integer key, Collectable item) { hm.put(key, item); } public Collectable retrieve(Integer theKey) { return hm.get(theKey); } public String toString() { String returnValue = ''; for (Collectable c : hm.values()) { returnValue += c + " "; return returnValue; } } // incomplete "{" }

// test

//import it313.thf; public class Test { public static void main(String args) { Collectable c1 = new Collectable(1111, "Book", 5500.00); Collectable c2 = new Collectable(2222, Baseball Card, 2700.00); Coin c3 = new Coin(3333, "Quarter", 10.50, 25, 1932); Coin c4 = new Coin(4444, "Silver Dollar", 38.00, 100, 1901); CollectablesStore s = CollectablesStore.new( ); s.store(c1.getId( ), c1); s.store(c2.getId( ), c2); s.store(c3.getId( ), c3); s.store(c4.getId( ), c4); for(Collectable c in s) { System.out.println(c); } System.out.println(s.retrieve(2222)); System.out.println(s.retrieve(4444)); } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!