Question: zyDE 4 . 3 . 1 : Class generics. The following program uses a generic class ItemCount to count the number of times the same

zyDE 4.3.1: Class generics.
The following program uses a generic class ItemCount to count the number of times the same word is read from the user input. Modify the program to:
Build #1- Complete the incrementIfDuplicate() method and update the main() method within the DuplicateCounter class to use the incrementIfDuplicate() method.
Build #2- Modify the program to count the number of times a specific integer value is read from the user input. Be sure to use the Integer class.
ItemCount.Java
public class ItemCount >{
private Type itemVal; // Value for item
private int itemCount; // Count for item
// Set item value, and reset item count to 0
public void setItem(Type newItemVal){
itemVal = newItemVal;
itemCount =0;
}
// Get item value
public Type getItem(){
return itemVal;
}
// Get item count
public int getCount(){
return itemCount;
}
// Reset item count to 0
public void resetCount(){
itemCount =0;
}
// Increment item count
public void incrementCount(){
++itemCount;
}
// Increments the item count if compareVal argument
// is equal to item value.
public void incrementIfDuplicate(Type compareVal){
// FIXME: Complete method
}
// Returns string for item value and count using
// the format itemVal: itemCount
@Override
public String toString(){
return ""+ itemVal +": "+ itemCount;
}
}
DuplicateCounter.java
import java.util.Scanner;
public class DuplicateCounter {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
ItemCount integerCounter = new ItemCount();
int inputInteger;
integerCounter.setItem(5);
System.out.println("Enter values (9999 at end):");
// Read first word
inputInteger = scnr.nextInt();
// Keep reading until word read equals
while(inputInteger !=9999){
integerCounter.incrementIfDuplicate(inputInteger);
inputInteger = scnr.nextInt();
}
// Display final word count
System.out.println("The integer \""+ integerCounter.getItem()+
"\" was read "+ integerCounter.getCount()+
" times.");
}
}
------------------------------------------------------------------------------------------
Please provide two sets of code (one for each build)

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!