Reference no: EM132648944
Assignment task
Write a java console application that allows the user to read, validate, store, display, sort and search COVID-19 vaccine data (vaccine name - String type, vaccine id - int type, trial phase -int type and cost - double type) for N vaccines. N should be declared as a constant and it should be equal to the largest digit of your student id number (e.g. if your id number is S382112 then N should be equal to 8 and you can declare it as final int N=8;). If largest digit is less than 3 then N should be equal to 3.
The vaccine name, vaccine id, trial phase and predicted cost must be read from the keyboard and must be stored in an Array or ArrayList (index 0 for vaccine 1 and index N-1 for vaccine N). The minimum and maximum cost which can be stored are $10 and $220. A validation for minimum and maximum values must be done during the reading of vaccine cost.
Your application should display and execute a menu with the following options. A switch statement must be used to execute the following menu options.
1. Read, validate and store vaccine data for N vaccines
2. Calculate and store the real cost for each vaccine
3. Display all vaccines
4. Display all vaccines in trial phase 3
5. Search a vaccine by id
6. Sort and display vaccines by name
7. Exit from the application
1. Read, validate and store vaccine data for N vaccines
This option reads vaccine name, vaccine id, trial phase and predicted cost for N vaccines from the keyboard and stores them in an Array or ArrayList. If the trial phase is less than 1 and greater than 4 then an appropriate message should be displayed and the user should be asked to enter the trial phase again. Similarly if the predicted cost is less than $10 and greater than $220 then an appropriate message should be displayed and the user should be asked to enter the cost again.
2. Calculate and store the real cost for each vaccine
This option calculates the real cost for each vaccine and then stores the real cost in Array or ArrayList. The formula to calculate the real cost is as follows: real cost = predicted cost - government rebate; where government rebate can be declared as a constant.
3. Display all vaccines
This option displays the vaccine data (vaccine name, vaccine id, trial phase, predicted cost and real cost) for all vaccines.
4. Display all vaccines in trial phase 3
This option displays the vaccine name and vaccine id of all vaccines in trial phase 3. If there is no vaccine in trial phase 3 then it displays an appropriate message.
5. Search a vaccine by id
This option asks user to enter the vaccine id and searches for it. If the id is found then it displays vaccine name, vaccine id, trial phase, predicted cost and real cost. If vaccine is not found then it displays an appropriate message "vaccine with given id is not found". If there is more than one vaccine with the given id then it displays all of them. A built-in search algorithm is not allowed in this assignment.
6. Sort and display vaccines
This option sorts (by name) all vaccines stored in Array or ArrayList in ascending order and displays all sorted vaccines (vaccine name, vaccine id, trial phase, predicted cost and real cost). You can use any sorting algorithm. A built-in sort algorithm for sorting is not allowed in this assignment.
7. Exit from the application
The application should display an appropriate message with student id and then exit from the application.
The application should work in a loop to enable the user to read, validate and store vaccine data for N vaccines, calculate and store the real cost for each vaccine, display all vaccines, display all vaccines in trial phase 3, search a vaccine by id, sort and display vaccines by name and exit from the application.
Program design
You may use any design that meets the specification. However, a good design will adhere to the following guidelines:
• be logically correct
• be easy to read and maintain
• be well-designed
• use a flowchart/UML activity diagram
• use appropriate classes, methods and fields
Your design MUST use the classes as listed below. public class Vaccine
{
//fields to store vaccine name, vaccine id, trial phase, predicted cost and real cost
//relevant methods including set and get methods
}
public class VaccineTest
{
public static void main(String[] args)
{
//menu options using switch statement
//data reading, Vaccine object creation, data storing in array/arrayList, etc.
}
//other static methods
}
You may add/use methods, parameters, fields/variables, constants, etc. which you need to complete the application.
Testing
Testing is important. You should test your application using many different types of test cases before you submit it for marking.
What to submit
You should submit online the following files.
• Vaccine.java (this file contains java code for class Vaccine)
• Vaccine Test.java (this file contains java code for class VaccineTest).
• Report.docx (this file contains a brief report that includes student name, student ID, unit name, unit code, UML activity diagram for menu option 2 (calculate and store real cost for all vaccines) and test results (screenshots for different test cases with results to show that your application is correctly working)).
Attachment:- Java assignment.rar