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 main(String[] args){
Scanner scnr = new Scanner(System.in);
ArrayList lessonList = new ArrayList();
Lesson currLesson;
String currTopic;
char currDiscount;
int lessonCount;
int i;
lessonCount = scnr.nextInt();
for (i =0; i < lessonCount; ++i){
currTopic = scnr.next();
currDiscount = scnr.next().charAt(0);
currLesson = new Lesson();
currLesson.setTopicAndDiscount(currTopic, currDiscount);
lessonList.add(currLesson);
}
}
}public class Lesson {
private String topic;
private char discount;
public void setTopicAndDiscount(String newTopic, char newDiscount){
topic = newTopic;
discount = newDiscount;
}
public char getDiscount(){
return discount;
}
public void print(){
System.out.println("Lesson: "+ topic +", Discount: "+ discount);
}
}

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!