In: Computer Science
My apologies, This is actually the question I was referring too.. It wants the pseudocode aswell as the flowchart which I am having trouble with the psedocode and what responses I have seen to the question has not made a ton of sense. Any help woudl be apprecitated. Thank you
a. Registration workers at a conference for authors of children’s books have collected data about conference participants, including the number of books each author has written and the target age of their readers. The participants have written from 1 to 40 books each, and target readers’ages range from 0 through 16. Design a program that continuously accepts the number of books written until a sentinel value is entered, and then displays a list of how many participants have written each number of books (1 through 40). b. Modify the author registration program so that a target age for each author’s audience is input until a sentinel value is entered. The output is a count of the number of books written for each of the following age groups: under 3, 3 through 7, 8 through 10, 11 through 13, and 14 and older.
Included both a and b solutions....
import java.util.*;
public class Author {
// class variables
String name;
int age;
ArrayList<String> books = new ArrayList<>();
// constructor
public Author(String name, int age,String book) {
books.add(book);
this.name = name;
this.age = age;
}
// add book
public void addBook(String book) {
books.add(book);
}
// get books
public int totalBooks() {
return books.size();
}
// print books
public void printAuthorBooks() {
System.out.println("Author books are: ");
for(int i=0;i<books.size();i++) {
System.out.println(books.get(i));
}
}
// main
public static void main(String args[]) {
//reading author data
int[] ageBooks = new int[40];
// initalizing array elements to zero
for(int i=0;i<40;i++) {
ageBooks[i] = 0;
}
Scanner sc = new Scanner(System.in);
Scanner sc1 = new Scanner(System.in);
while(true) {
// printing menu
System.out.println("1.Register new author 2.Get count of books of
each age 3.exit");
//reading input
int choice = sc.nextInt();
if(choice == 1) {
System.out.println("Enter name: ");
String name = sc1.nextLine();
System.out.println("Enter age: ");
int age = sc.nextInt();
ageBooks[age-1]++;
System.out.println("Add book :");
String book = sc1.nextLine();
// creating object
Author obj = new Author(name,age,book);
// displaying anoher menu
while(true) {
System.out.println("1.Add more book 2.display books 3.exit
");
int choice2 = sc.nextInt();
if(choice2 == 1) {
System.out.println("Add book :");
String book1 = sc1.nextLine();
ageBooks[age-1]++;
obj.addBook(book);
}
else if(choice == 2){
obj.printAuthorBooks();
}
else{
System.out.println("Good bye");
break;
}
}
}
else if(choice == 2){
// diaplaying number of books as per age
for(int i=0;i<40;i++) {
if(ageBooks[i] > 0){
System.out.println("Age: "+i+" -> "+ageBooks[i]);
}
}
}
else {
System.out.println("Good bye");
break;
}
}
}
}
OUTPUT