Question: The program first reads integer lectureCount from input, representing the number of pairs of inputs to be read. Each pair has a string and an
The program first reads integer lectureCount from input, representing the number of pairs of inputs to be read. Each pair has a string and an integer, representing the lecture's topic and duration, respectively. One Lecture object is created for each pair and added to ArrayList lectureList. Write the findAverageLectureDuration method in the Inventory class to return the average duration of all the Lecture objects as an integer.
Ex: If the input is:
Music Fashion Culture
then the output is:
Average lecture duration:
Note: The ArrayList has at least one element. Inventory.java: import java.util.Scanner;
import java.util.ArrayList;
public class Inventory
private ArrayList lectureList new ArrayList;
public void inputLecturesScanner scnr
Lecture currLecture;
String currTopic;
int currDuration;
int lectureCount;
int i;
lectureCount scnrnextInt;
for i ; i lectureCount; i
currTopic scnrnext;
currDuration scnrnextInt;
currLecture new Lecture;
currLecture.setTopicAndDurationcurrTopic currDuration;
lectureList.addcurrLecture;
Your code goes here
Lecture.java: public class Lecture
private String topic;
private int duration;
public void setTopicAndDurationString newTopic, int newDuration
topic newTopic;
duration newDuration;
public int getDuration
return duration;
LectureSystem.java: import java.util.Scanner;
import java.util.ArrayList;
public class LectureSystem
public static void mainString args
Scanner scnr new ScannerSystemin;
Inventory inventory new Inventory;
inventory.inputLecturesscnr;
System.out.printlnAverage lecture duration: inventory.findAverageLectureDuration;
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
