Answer to Question #182403 in Java | JSP | JSF for John

Question #182403

Write a program that reads and records magazine sales for 5 students. Record a

student’s name, the magazine sold, and the number sold. Information should be read

in one record at a time – that is to say, read one student, magazine, and number before

getting the next set. (Similar to the example in the notes.) Produce a table that

displays the recorded information.

Note: use multiple arrays


1
Expert's answer
2021-04-17T01:29:38-0400
package q182284;


import java.util.Scanner;


public class Q182403 {
    /***
     * Main method
     * @param args 
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        final int totalStudents=5;
        String [][]studentsData=new String[totalStudents][3];
        for (int st = 0; st < totalStudents; st++) {
            System.out.print("Enter the student's name: ");
            studentsData[st][0]=input.nextLine();
            System.out.print("Enter the magazine sold: ");
            studentsData[st][1]=input.nextLine();
            System.out.print("Enter the number sold: ");
            studentsData[st][2]=input.nextLine();
            System.out.println();
        }
        System.out.println(String.format("\n%-30s%-30s%-30s","Student name","Magazine sold","Number sold"));
        for (int st = 0; st < totalStudents; st++) {
            System.out.println(String.format("%-30s%-30s%-30s",studentsData[st][0],studentsData[st][1],studentsData[st][2]));
        }
        input.close();  
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog