Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started