Question: zyDE 4 . 3 . 1 : Class generics. The following program uses a generic class ItemCount to count the number of times the same
zyDE : 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 # Complete the incrementIfDuplicate method and update the main method within the DuplicateCounter class to use the incrementIfDuplicate method.
Build # 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
public void setItemType newItemVal
itemVal newItemVal;
itemCount ;
Get item value
public Type getItem
return itemVal;
Get item count
public int getCount
return itemCount;
Reset item count to
public void resetCount
itemCount ;
Increment item count
public void incrementCount
itemCount;
Increments the item count if compareVal argument
is equal to item value.
public void incrementIfDuplicateType 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 mainString args
Scanner scnr new ScannerSystemin;
ItemCount integerCounter new ItemCount;
int inputInteger;
integerCounter.setItem;
System.out.printlnEnter values at end:;
Read first word
inputInteger scnrnextInt;
Keep reading until word read equals
whileinputInteger
integerCounter.incrementIfDuplicateinputInteger;
inputInteger scnrnextInt;
Display final word count
System.out.printlnThe 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
