Concept explainers
JAVA PROGRAM
For this program, you are tasked to implement the Beverage class which has the following private properties:
- name - a string value
- volume - this is an integer number which represents its current remaining volume in mL
- isChilled - this is a boolean field which is set to true if the drink is chilled
It should have the following methods:
- isEmpty() - returns true if the volume is already 0
- {toString() - returns the details of the object in the following format: {name} ({volume}mL) {"is still chilled" | "is not chilled anymore"}.Example returned strings:
- Beer (249mL) is still chilled
- Water (500mL) is not chilled anymore
- A constructor method with the following signature: public Beverage(name, volume, isChilled)
- Getter methods for all the 3 properties.
Then, create two final subclasses that inherit from this Beverage class. The first one is the Water class which has the additional private property, type, which is a String and can only be either "Purified", "Regular", or "Distilled". It should have the following methods:
- 1st constructor: public Water(volume, isChilled, type) - when calling its parent class' constructor, pass "Water" as the name
- 2nd constructor: public Water(volume, isChilled) - the type will be set to "Regular" and similar to the 1st constructor, pass "Water" as the name to its parent class' constructor
- A getter for its type
The second subclass to be created is the Beer class which has the additional private property, alcoholicContent, which is the percentage of alcoholic content in the beer in percentage (0.01 to 1.00). It should have 1 constructor only which the following signature: public Beer(volume, isChilled, alcoholicContent), and you need to pass "Beer" as the name for its parent class' constructor call. There should also be a getter for the alcoholicContent. Additionally, implement the following methods:
-
String getType()
- this returns "Flavored" if the alcoholic content is below 0.03, "Regular" if the alcoholic content is 0.03 and above but below 0.06, and "Strong" if it's 0.06 and above
-
String toString()
-
calls its parent class' toString() method and appends in the end its alcoholic percentage with 1 decimal place. For example:
- Beer (249mL) is still chilled (6.0% alcoholic content)
-
For this problem, you are also in charge in creating the main. In the main, you will ask the user for the following details:
- Type (1 for Water, 2 for Beer)
- Volume
- Is Chilled ('Y' for yes while 'N' for no)
- If the type is water, ask the user if to input the type. If the type is beer, ask the user to input the alcoholic content.
Example user prompts:
Select type (1 - Water, 2 - Beer): 1
Enter volume: 249
Is chilled (Y - yes, N - no): Y
Type: Distilled
Select type (1 - Water, 2 - Beer): 2
Enter volume: 500
Is chilled (Y - yes, N - no): N
Alcoholic content: 0.04
Then, after asking for these prompts from the user, create the object using the appropriate class (i.e. if the type inputted is 1, then create a Water object. If the type inputted is 2, then create a Beer object). Finally, call the built-in Tester.test() method and pass this object you just created.
Step by stepSolved in 5 steps with 2 images
- This code is used for the question being asked at the bottom. public class AccountBalance {private long accountNumber;private String ownersName;private double balance;public AccountBalance(long accountNumber, String ownersName, double balance) {this.accountNumber = accountNumber;this.ownersName = ownersName;setBalance(balance);}public long getAccountNumber() {return accountNumber;}public void setAccountNumber(long accountNumber) {this.accountNumber = accountNumber;}public String getOwnersName() {return ownersName;}public void setOwnersName() {this.ownersName = ownersName;}public double getBalance() {return balance;}public void setBalance(double balance) {if (balance < 0) {System.out.println("Balance Cannot be Negative.");balance = 0;}this.balance = balance;}} import java.util.Scanner;public class AccountBalanceDemo {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.print("Enter the name of the account holder: ");String name =…arrow_forwardis defined as where a variable is accessible or can be used. Private Class Scope Private Method None of thesearrow_forward1. Dummy GUI Application by Codechum Admin A GUI Application is an application that has a user interface that the user can interact with. For this program, we will be simulating this behavior. First, implement another class called Checkbox which implements the Clickable interface which has only one method: public void click(). The Checkbox will have the following properties: private boolean isChecked (defaults to false upon the creation of object) private String text Additionally, it should have the following methods: the implementation of the click() method If the isChecked is currently false, this will set the isChecked to true and will then print the message "Checkbox is checked". If it is currently true, this will set the isChecked to false and will then print the message "Checkbox is unchecked". Note that the messages to be printed should have also print a new line at the end. an override of the toString() method which returns the message: "Checkbox ({text} - Clicked…arrow_forward
- class Player { protected: string name; double weight; double height; public: Player(string n, double w, double h) { name = n; weight = w; height = h; } string getName() const { return name; } virtual void printStats() const = 0; }; class BasketballPlayer : public Player { private: int fieldgoals; int attempts; public: BasketballPlayer(string n, double w, double h, int fg, int a) : Player(n, w, h) { fieldgoals = fg; attempts = a; } void printStats() const { cout << name << endl; cout << "Weight: " << weight; cout << " Height: " << height << endl; cout << "FG: " << fieldgoals; cout << " attempts: " << attempts; cout << " Pct: " << (double) fieldgoals / attempts << endl; } }; a. What does = 0 after function printStats() do? b. Would the following line in main() compile: Player p; -- why or why not? c. Could…arrow_forwardA class object can encapsulate more than one [answer].arrow_forwardpublic class ItemToPurchase { private String itemName; private int itemPrice; private int itemQuantity; // Default constructor public ItemToPurchase() { itemName = "none"; itemPrice = 0; itemQuantity = 0; } // Mutator for itemName public void setName(String itemName) { this.itemName = itemName; } // Accessor for itemName public String getName() { return itemName; } // Mutator for itemPrice public void setPrice(int itemPrice) { this.itemPrice = itemPrice; } // Accessor for itemPrice public int getPrice() { return itemPrice; } // Mutator for itemQuantity public void setQuantity(int itemQuantity) { this.itemQuantity = itemQuantity; } // Accessor for itemQuantity public int getQuantity() { return itemQuantity; }} import java.util.Scanner; public class ShoppingCartPrinter { public static void main(String[] args) { Scanner scnr = new…arrow_forward
- Java Programming Please do not change anything in Student class or Course class class John_Smith extends Student{ public John_Smith() { setFirstName("John"); setLastName("Smith"); setEmail("jsmith@jaguar.tamu.edu"); setGender("Male"); setPhoneNumber("(200)00-0000"); setJNumber("J0101459"); } class MyCourse extends Course { public MyCourse { class Course { private String courseNumber; private String courseName; private int creditHrs; public Course (String number, String name, int creditHrs){ this.courseNumber = number; this.courseName = name; this.creditHrs = creditHrs; } public String getNumber() { return courseNumber; } public String getName() { return courseName; } public int getCreditHrs() { return creditHrs; } public void setCourseNumber(String courseNumber) { this.courseNumber = courseNumber; } public void setCourseName(String…arrow_forwardJava A class always has a constructor that does not take any parameters even if there are other constructors in the class that take parameters. Choose one of the options:TrueFalsearrow_forwardSubclass toString should call include super.toString(); re-submit these codes. public class Vehicle { private String registrationNumber; private String ownerName; private double price; private int yearManufactured; Vehicle [] myVehicles = new Vehicle[100]; public Vehicle() { registrationNumber=""; ownerName=""; price=0.0; yearManufactured=0; } public Vehicle(String registrationNumber, String ownerName, double price, int yearManufactured) { this.registrationNumber=registrationNumber; this.ownerName=ownerName; this.price=price; this.yearManufactured=yearManufactured; } public String getRegistrationNumber() { return registrationNumber; } public String getOwnerName() { return ownerName; } public double getPrice() { return price; } public int getYearManufactured() { return yearManufactured; }…arrow_forward
- Java. Refer to attachment. Starter code below. public class Car{//attributesprivate String make;private String model;private int year;protected int speed; //constructorpublic Car(String make, String model, int year){this.make = make;this.model = model;this.speed = 0;this.year = year;} //Getterspublic String getMake() {return make;}public String getModel() {return model;}public int getSpeed() {return speed;}public int getYear() {return year;}//Setterspublic void setMake(String colour) {this.make = make;}public void setModel(String colour){this.model = model;}public void setSpeed(int speed) {this.speed = speed;}public void setYear(int year) {this.year = year;}public void accelerate() {speed ++;} public void brake() {speed --;if (speed < 0) {speed = 0;} }public String toString() {String carDetails = "Make: " + this.make+ "\nModel: " + this.model+ "\nYear: " + this.year+ "\nSpeed: " + this.speed; return carDetails;}} public class NissanLeaf extends Car…arrow_forwardA field has access that is somewhere between public and private. static final Opackage Oprotectedarrow_forward1. RetailItem Class Write a class named Retailltem that holds data about an item in a retail store. The class should have the following fields: • description. It is a String object that holds a brief description of the item. • unitsOnHand. It is an int variable that holds the number of units currently in inventory. • price. It is a double that holds the item's retail price. Write appropriate mutator methods that store values in these fields and accessor methods that return the values in these fields. Once you have written the class, write a separate program that creates three RetailItem objects and stores the following data in them. Units On Hold Description Designer Jeans Jacket Price 40 34.95 12 59.95 Shirt 20 24.95arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY