Answered step by step
Verified Expert Solution
Link Copied!

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 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Factory Active Database For Enterprise Computing

Authors: Schur, Stephen

1st Edition

0471558443, 9780471558446

More Books

Students also viewed these Databases questions