answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
MrMuchimi
2 years ago
4

Here are the steps. (1) Create a Student class containing an ID, a last name, and a list of course names such as "COP2210" or "C

OP2250". This should not be a string of multiple courses. The ID should be an integer which is printed with leading zeros. (2) Create a class named StudentTest that contains a List of students. Do not use the list provided here. In the class constructor, create 15 students and add them to the list. Each student's ID must be different. Each student you add to the list must contain 2-4 different course names. At least one should have two course names and at least one should have four course names. Make sure the students do not all have the same courses, although there should be some overlap (see the sample below). The student names must be inserted into the list in random order (not sorted). (3) Sort the list in ascending order by student last name and display the list. For each student, display the ID with leading zeros, last name, and list of courses on a single line. Here is sample output. Note how the tab character is inserted after the name to line up the next column containing courses. Be sure there is no trailing comma at the end of the list of courses.
Computers and Technology
1 answer:
d1i1m1o1n [39]2 years ago
5 0

Answer:

Java code is given below with appropriate comments

Explanation:

import java.util.*;

public class Student

{

String ID, lastName;

//Arraylist to store courses

ArrayList courses = new ArrayList();

public Student()

{

//Default constructor

ID = "";

lastName = "";

}

public Student(String I, String l)

{

//Parameterized Constructor to initialize

ID = I;

lastName = l;

int i, n;

String temp;

Scanner sc = new Scanner(System.in);

System.out.print("\nHow many courses you want to add: ");

n = Integer.parseInt(sc.nextLine());

if(n < 3){ //Cannot choose less than 3 courses

System.out.println("\nNumber of courses must be at least 3.");

return;

}

for(i = 1; i <= n; i++)

{

System.out.print("\nEnter course name: ");

temp = sc.nextLine();

if(courses.contains(temp))//If course already present

{

System.out.println("\nCourse already present. Try another.");

i--;

}

else

{

courses.add(temp); //Adding course

}

}

}

//Accessors

public String getID()

{

return ID;

}

public String getName()

{

return lastName;

}

public ArrayList getCourses()

{

return courses;

}

//Mutators

public void setID(String i)

{

ID = i;

}

public void setName(String n)

{

lastName = n;

}

public void setCourses(ArrayList c)

{

courses.clear();

courses.addAll(c);

}

}

class StudentTest

{

//To store 10 students

Student[] list = new Student[10];

public StudentTest(){

int i, j, flag;

Scanner sc = new Scanner(System.in);

for(i = 0; i < 10; i++)

{

String temp, l;

System.out.print("\nEnter student ID: ");

temp = sc.nextLine();

flag = 1;

for(j = 0; j < i; j++)

{

if(list[j].getID().equals(temp))//If ID already exists

{

System.out.println("\nID already exists. Try another.");

flag = 0;

i--;

break;

}

}

if(flag == 1)

{

System.out.print("\nEnter student Last name: ");

l = sc.nextLine();

list[i] = new Student(temp, l); //Initializing student

}

}

}

public void sort()

{

//To sort and display

int i, j;

String temp;

ArrayList t = new ArrayList();

for(i = 0; i < 9; i++)

{

for(j = 0; j < 9 - i; j++)

{

if(list[j].getName().compareTo(list[j + 1].getName()) > 0)//If list[j + 1].lastName needs to come before list[j].lastName

{

//Swapping IDs

temp = list[j].getID();

list[j].setID(list[j + 1].getID());

list[j + 1].setID(temp);

//Swapping last names

temp = list[j].getName();

list[j].setName(list[j + 1].getName());

list[j + 1].setName(temp);

//Swapping courses

t.clear();

t.addAll(list[j].getCourses());

list[j].setCourses(list[j + 1].getCourses());

list[j + 1].setCourses(t);

}

}

}

//Display

System.out.println();

for(i = 0; i < 10; i++)

{

System.out.print(list[i].getID() + ", " + list[i].getName());

//Using fencepost loop to print with comma before

System.out.print(" " + list[i].getCourses().get(0));

for(j = 1; j < list[i].getCourses().size(); j++)

System.out.print(", " + list[i].getCourses().get(j));

System.out.println();

}

}

public static void main(String args[])

{

StudentTest S = new StudentTest();

S.sort();

}

}

You might be interested in
A laptop gets replaced if there's a hardware issue. Which stage of the hardware lifecycle does this scenario belong to?
Ilya [14]

Answer: Maintenance. This is the stage where software is updated and hardware issues are fixed if and when they occur. Retirement. In this final stage, hardware becomes unusable or no longer needed and it needs to be properly removed from the fleet

Explanation:

3 0
2 years ago
Ethan is a systems developer. He is working on a system where he will implement independent solutions for different processes. W
Igoryamba
The correct answer for this question is this one: " c.huge initial investment"
<span>Ethan is a systems developer. He is working on a system where he will implement independent solutions for different processes. The possible drawback of using such a system is that </span><span><u>huge initial investment</u>
</span>
Hope this helps answer your question and have a nice day ahead.
8 0
2 years ago
B2B partners often connect to each other on the Internet through special __________ designed to facilitate information exchanges
Alenkasestr [34]

Answer:

web portals

Explanation:

B2B (business-to-business) is a marketing strategy that deals with meeting the needs of other businesses, by selling products or services to the organizations for resale to other consumers, used in production of goods or for the operation of an organisation.

B2B (business-to-business) model focuses on facilitating sales transactions between businesses.

Under the B2B, the producer sells its products directly to other businesses such as wholesalers or retailers and not the end consumers.

B2B partners often connect to each other on the Internet through special web portals that are designed to facilitate exchange of information and simplified business transactions.

Additionally, a popular application of the seller-side marketplace model, which is a major business-to-business (B2B) e-commerce model, is e-procurement of goods through the use of web portals over the internet and as such eliminating the option of physical buying or procurement.

3 0
1 year ago
Describe how the process of sampling, RGB pixels, and binary sequences work together to display a digital color image
Rina8888 [55]

Explanation:

Sampling and RBG (red blue green) pixels and also the binary sequences working together such that it display any digitally colored image by allowing the computer system know where the Red Blue Green pixel is going to be placed and also what the opacity would be for that pixel. The combination of these components is what gives you a digital color image.

5 0
2 years ago
When Russ opened a website on his browser, he saw an error that the site was not compatible with the browser version he was runn
Umnica [9.8K]

Answer:

Patch finders.

Explanation:

Once Russ accessed a webpage on his computer, he had seen an issue that the page was not associated with the browser variant on which he was executing it, although it was important to use patch finders tool to fix the following problems because patch finder is only the software that can resolve the following issues.

3 0
2 years ago
Other questions:
  • In cell B16, enter a function to calculate the total attendance for the years 2014 through 2018 using the totals in the range B1
    10·1 answer
  • In a graphical user interface, which is a small symbol on the screen whose location and shape changes as a user moves a pointing
    10·1 answer
  • Your reputation and credibility will be immediately destroyed if your website contains?
    8·2 answers
  • Leena needs to manually update the TOC and would prefer not to change the styles in the document.
    9·2 answers
  • Type two statements that use rand() to print 2 random integers between (and including) 100 and 149. End with a newline. Ex:
    8·2 answers
  • A network router connects multiple computers together and allows them to send messages to each other. If two or more computers s
    7·1 answer
  • In this exercise we look at memory locality properties of matrix computation. Th e following code is written in C, where element
    9·1 answer
  • In a system where Round Robin is used for CPU scheduling, the following is TRUE when a process cannot finish its computation dur
    13·1 answer
  • Given positive integer n, write a for loop that outputs the even numbers from n down to 0. If n is odd, start with the next lowe
    8·1 answer
  • What temperature is most commonly used in autoclaves to sterilize growth media and other devices prior to experimentation
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!