Implement the class Vaccine so that it contains: 3 private instance variables: name of type...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Implement the class Vaccine so that it contains: ✓ 3 private instance variables: name of type String, doses of type integer which records the number of doses taken, and isAuthorized which is Boolean and indicates if the vaccine is proven safe or not. ✓ A default constructor which sets the numeric instance variable to zero and the String instance variable to null. ✓ A constructor with 3 parameters which sets the 3 instance variables to the corresponding values passed. ✓ Implement an accessor method for each of the 3 instance variables that will return the value of the instance variable. For example, the getX() method for the instance variable name must be called getName(). Implement a mutator method for each instance variable that will assign to the instance variable the value passed. For example, the setX() method for the instance variable type must be called setName(). ✓ An equals method: two objects of type Vaccine are equal if all the attributes of both objects have the same values. ✓ A Boolean method bothAuthorized which returns true if both vaccines are Authorized and false otherwise. ✓ A toString function must also be provided to return the vaccine information in the following format: The Vaccine of name <name> has <doses> dose(s) and is Authorized is <isAuthorized> Where <name>, <doses> and <isAuthorized> are the contents of the instance variables. If you correctly implemented all the above, running the main method will result in your program displaying exactly as in the boxes below. Your program should work for any values entered. REMEMBER in the output: is a space, → is a tab and J is a new line. Text in green is user input. The only formatting you are concerned with is the one generated by the toString method (in blue) the rest is already set in the main method which you are not to change. What is the name of this Vaccine? Polio How many needed doses of this Vaccine?°4 Is it an Authorized Vaccine? (true or false) true The two Vaccines are: The Vaccine of name null has 0°dose(s) and is Authorized is false The Vaccine of name Polio has 4°dose(s) and is Authorized is true Let's set up the 1st Vaccine°... What is the name? Polio How many doses?°4 Is it an Authorized Vaccine (true or false)? °false Vaccine 1: The Vaccine of name Polio has 4 dose(s) and is Authorized is false Are the 2 Vaccine objects equal? No Are they both Authorized Vaccine? false Now are they both Authorized Vaccine? true What is the name of this Vaccine? Cholera How many needed doses of this Vaccine?°1 Is it an Authorized Vaccine? (true or false) ofalse The two Vaccines are: The Vaccine of name null has 0°dose(s) and is Authorized is false The Vaccine of name Cholera has 1 dose(s) and is Authorized is false Let's set up the 1st Vaccine°... What is the name? Polio How many doses?°4 Is it an Authorized Vaccine (true or false)? false Vaccine 1: The Vaccine of name Polio has 4 dose(s) and is Authorized is false Are the 2°Vaccine objects equal? No Are they both Authorized Vaccine? false Now are they both Authorized Vaccine? false Note 1: You are to expect a perfect user who will always enter valid values; that is, do not verify the validity of user input. Note 2: The use of libraries other than java.util.Scanner is prohibited. Your program must work for data entered, not just the ones in the samples above. Implement the class Vaccine so that it contains: ✓ 3 private instance variables: name of type String, doses of type integer which records the number of doses taken, and isAuthorized which is Boolean and indicates if the vaccine is proven safe or not. ✓ A default constructor which sets the numeric instance variable to zero and the String instance variable to null. ✓ A constructor with 3 parameters which sets the 3 instance variables to the corresponding values passed. ✓ Implement an accessor method for each of the 3 instance variables that will return the value of the instance variable. For example, the getX() method for the instance variable name must be called getName(). Implement a mutator method for each instance variable that will assign to the instance variable the value passed. For example, the setX() method for the instance variable type must be called setName(). ✓ An equals method: two objects of type Vaccine are equal if all the attributes of both objects have the same values. ✓ A Boolean method bothAuthorized which returns true if both vaccines are Authorized and false otherwise. ✓ A toString function must also be provided to return the vaccine information in the following format: The Vaccine of name <name> has <doses> dose(s) and is Authorized is <isAuthorized> Where <name>, <doses> and <isAuthorized> are the contents of the instance variables. If you correctly implemented all the above, running the main method will result in your program displaying exactly as in the boxes below. Your program should work for any values entered. REMEMBER in the output: is a space, → is a tab and J is a new line. Text in green is user input. The only formatting you are concerned with is the one generated by the toString method (in blue) the rest is already set in the main method which you are not to change. What is the name of this Vaccine? Polio How many needed doses of this Vaccine?°4 Is it an Authorized Vaccine? (true or false) true The two Vaccines are: The Vaccine of name null has 0°dose(s) and is Authorized is false The Vaccine of name Polio has 4°dose(s) and is Authorized is true Let's set up the 1st Vaccine°... What is the name? Polio How many doses?°4 Is it an Authorized Vaccine (true or false)? °false Vaccine 1: The Vaccine of name Polio has 4 dose(s) and is Authorized is false Are the 2 Vaccine objects equal? No Are they both Authorized Vaccine? false Now are they both Authorized Vaccine? true What is the name of this Vaccine? Cholera How many needed doses of this Vaccine?°1 Is it an Authorized Vaccine? (true or false) ofalse The two Vaccines are: The Vaccine of name null has 0°dose(s) and is Authorized is false The Vaccine of name Cholera has 1 dose(s) and is Authorized is false Let's set up the 1st Vaccine°... What is the name? Polio How many doses?°4 Is it an Authorized Vaccine (true or false)? false Vaccine 1: The Vaccine of name Polio has 4 dose(s) and is Authorized is false Are the 2°Vaccine objects equal? No Are they both Authorized Vaccine? false Now are they both Authorized Vaccine? false Note 1: You are to expect a perfect user who will always enter valid values; that is, do not verify the validity of user input. Note 2: The use of libraries other than java.util.Scanner is prohibited. Your program must work for data entered, not just the ones in the samples above.
Expert Answer:
Answer rating: 100% (QA)
Here is an example implementation of the Vaccine class in Java java public class Vaccine private String name private int doses private boolean isAutho... View the full answer
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Implement the Record class. Add the following private instance variables to the Record class: A String representing the title of the record. A String representing the record artist. An int...
-
Consider the pistoncylinder arrangement shown in the sketch below. The gas forces on each side of the piston, assuming there are no frictional forces at the pistoncylinder interface, balance the...
-
The Internet has dramatically increased global e-commerce activities. Both traditional "brick and mortar" businesses and new dot-com businesses use the Internet to meet business objectives. For...
-
Molander Corporation is a distributor of a sun umbrella used at resort hotels. Data concerning the next months budget appear below: Required: 1. Compute the companys margin of safety. 2. Compute the...
-
Determine the moments of inertia and the radius of gyration of the section as shown in Figure 11.28 with respect to the \(x\) and \(y\)-axes. FIGURE 11.28: y 12 mm 12 mm 8 mm 24 mm 24 mm 6 mm 24 mm...
-
The interest rate on a $14,000 loan is 8.4% compounded semiannually. Semiannual payments will pay off the loan in seven years. a. Calculate the interest component of Payment 10. b. Calculate the...
-
Name four characteristics of Force?
-
Fawcett Institute provides one-on-one training to individuals who pay tuition directly to the business and also offers extension training to groups in off-site locations. Fawcett prepares adjusting...
-
Rita's story details how trusting your governmental officials to always act for the public good is not realistic (please watch the video Rita Crundwell Steals $53 Million from Dixon IL ). Next, use...
-
Supervised parole is a useful tool and helps with reentry into society. Why is supervised parole such an important tool and how does it help to reintegrate newly-released individuals into society? As...
-
MY OPINION ABOUT THIS Mr. Post gives a wonderful list of tips to keep in mind while performing legal research and writing. My favorite is his first tip. He describes the writing we do as a...
-
Assignment Documents Read the article, "U.S. Health Care from a Global Perspective, 2019: Higher Spending, Worse Outcomes?"(See article attached below or review the Reading and Resources for Module...
-
2. In Diffie-Hellman key exchange, each user chooses a private X, calculates a public Y, and after exchanging Y, calculates K where for user a: Y = axa mod q; Ka= Yxa mod q ; q is a prime number;...
-
Bill - "I will buy 100 watches from you for the standard price." (The last standard price is $2) Tom - "OK, great. We have a deal at $3." Tell me if you think they have an enforceable contract, and...
-
The 3-month forecasted demand of a product group consisting of X and Z models, and the number of month workdays are as follows. Months 1 2 3 Demand qty. 720 675 620 Number of workdays 20 18 22 At the...
-
Making use of the tables of atomic masses, find the velocity with which the products of the reaction B10 (n, ) Li7 come apart; the reaction proceeds via interaction of very slow neutrons with...
-
Define the following methods for the class Ledger, as described in the previous exercise: getAverageSale()returns the average value of all the sales getCountAbove(v)returns the number of sales that...
-
What output will be produced by the following code? public class Demo { public static void main(String[] args) { System.out.println("The output is:"); foo(23); System.out.println(); } public static...
-
Write a program that converts degrees from Fahrenheit to Celsius, using the formula DegreesC = 5(DegreesF 32)/9 Prompt the user to enter a temperature in degrees Fahrenheit as a whole number without...
-
A balloon is at a height of \(5.0 \mathrm{~km}\) and is descending at a constant rate. The buoyancy force is directed ; the drag force is directed A. Up, up B. Up, down C. Down, up D. Down, down...
-
Sneezing requires an increase in pressure of the air in the lungs; a typical sneeze might result in an extra pressure of \(7.0 \mathrm{kPa}\). Estimate how much force this exerts on the diaphragm,...
-
A \(20 \mathrm{~kg}\) block of aluminum sits on the bottom of a tank of water. How much force does the block exert on the bottom of the tank? Long-distance balloon flights are usually made using a...
Study smarter with the SolutionInn App