Question: The program first reads integer lessonCount from input, representing the number of pairs of inputs to be read. Each pair has a string and a
The program first reads integer lessonCount from input, representing the number of pairs of inputs to be read. Each pair has a string and a character, representing the lesson's topic and discount, respectively. One Lesson object is created for each pair and added to ArrayList lessonList. If a Lesson object's discount status is equal to N call the Lesson object's print method.import java.util.Scanner;
import java.util.ArrayList;
public class Lessons
public static void mainString args
Scanner scnr new ScannerSystemin;
ArrayList lessonList new ArrayList;
Lesson currLesson;
String currTopic;
char currDiscount;
int lessonCount;
int i;
lessonCount scnrnextInt;
for i ; i lessonCount; i
currTopic scnrnext;
currDiscount scnrnextcharAt;
currLesson new Lesson;
currLesson.setTopicAndDiscountcurrTopic currDiscount;
lessonList.addcurrLesson;
public class Lesson
private String topic;
private char discount;
public void setTopicAndDiscountString newTopic, char newDiscount
topic newTopic;
discount newDiscount;
public char getDiscount
return discount;
public void print
System.out.printlnLesson: topic Discount: discount;
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
