Explanation of Solution
Program code:
MyCharacter.java
//define a class MyCharacter
public class MyCharacter
{
//define the class member variables
private String name;
private int health;
private int power;
//constructor
public MyCharacter()
{
}
//constructor
public MyCharacter(String n, int h, int p)
{
//initialize the variables
name = n;
health = h;
power = p;
}
//define the method getName()
public String getName()
{
//return the value of name
return name;
}
//define the method setName()
public void setName(String name)
{
//set the value of name
this.name = name;
}
//define the method getHealth()
public int getHealth()
{
//return the value of health
return health;
}
//define the method setHealth()
public void setHealth(int health)
{
//set the value of health
this.health = health;
}
//define the method getPower()
public int getPower()
{
//return the value of power
return power;
}
//define the method setPower()
public void setPower(int power)
{
//set the value of power
this.power = power;
}
}
Explanation:
The above snippet of code is used to create a class “MyCharacter”. In the code,
- Import the required header files.
- Define a class “MyCharacter”
- Declare the class variables “name”, “health” and “power”.
- Define the constructor “MyCharacter”.
- Set the values of variables “name”, “health” and “power”.
- Define the “getName()” method.
- Return the value of “name”.
- Define the “setName()” method...
Trending nowThis is a popular solution!
Chapter 3 Solutions
EBK JAVA PROGRAMMING
- Create an application named SalesTransactiobDemo that declares several SalesTransaction objects and displays their values and their sum. Name - The salesperson name (as a string) sales Amount- The sales amount (as a double) commission- The commission (as a double) RATE- A readonly field that stores the commission rate (as a double). Define a getRate() avcessor method that returns the RATE Include 3 constructors for the class. One constructor accepts values for the name, sales amount, and rate, and when the sales value is set, the constructor computes the commission as sales value times commission rate. The second constructor accepts a name and sales amount, but sets the commission rate to 0 The third constructor accepts a name and sets all the other fields to 0arrow_forwardPlease create a java class that contains the following data attributes and methods: private int customerNumber - a unique number assigned to each customer private String firstName - the customer's first name private String lastName - the customer's last name private float balance - the customer's balance get/set Methods for each data attribute public String toString() - Special method to be used when printing a customer Record objectarrow_forwardYou are working in a doctors’ office and have been tasked with creating an application to maintain Patient records for each doctor in the office. Create a class to maintain a Doctor. A doctor has a name that must be stored in the Doctor class. A doctor can only treat 3 patients but could treat fewer than 3. The information for each patient should be encapsulated in a Patient class and should include the patient’s last name and up to 5 cholesterol readings for the patient. Note that less than 5 cholesterol readings may sometimes be stored. Your Doctor class should support operations to add a patient record to the end of his/her list of assigned patients (i.e., use a vector to store Patient objects in the Doctor class), and to list all patient records (name and associated cholesterol readings). Your Patient class should include operations to allow entry of the patient’s last name and up to 5 cholesterol readings, and to return the name and cholesterol readings for that patient. You…arrow_forward
- File ApplicationCentre.java, which contains classes ApplicationCentre and Student. Introduction Write a Java program to handle applications for universities admission providing a good user interface. This program should work as a Frame with the width = 500 pixels and the height = 500 pixels. The tasks of this Java program: - to enter information for a number of students - to display in a separate window the information about all the students stored - to display in another separate window the information for a selected student Your Task In this assignment class Student encapsulates the student information relevant for universities admission: student name (just the family name), high school average and 3 universities chosen. The admission is based on the high school average according to the following table: University High school average for admission Toronto 90 York 84 Brock 75 Guelph 76 Waterloo 88 McGill 90 Concordia 76 Laval 78 Macmaster 82 Western 80 Based on this table a method of…arrow_forwardUsing C# programming language (using Microsoft Visual Studio), create a class called Personthat has some properties (e.g., name, surname, age etc.). Create a method called Greetingwhich prints “Person is saying Hi!”. Now, create two classes to hold data from user input. Theconsole needs to be used to retrieve the data by asking the user to create the object.• Create a console application• Create a class and name it Student• Student class should be derived from the Person class• Create the following properties for your class: name, surname, email, ID, phonenumber, date of birth etc.• Create a parameter and constructor for your class• Use the Greeting method by overriding the base class method; your method shouldprint “Student is saying Hi!”• Create another class for validation• Create at least three methods for your validation class to validate empty entry,wrong phone number and email addressThe user needs to enter the information as an input to create a student, then the…arrow_forwardThis is the question I am stuck on - Radio station KJAVA wants a class to keep track of recordings it plays. Create a class named Recording that contains fields to hold methods for setting and getting a Recording’s title, artist, and playing time in seconds. Write an application that instantiates five Recording objects and prompts the user for values for the data fields. Then prompt the user to enter which field the Recordings should be sorted by—(S)ong title, (A)rtist, or playing (T)ime. Perform the requested sort procedure, and display the Recording objects. This is what I have so far - public class Recording { private String song; private String artist; private int playTime; public void setSong(String title) { this.song = title; } public void setArtist(String name) { this.artist = name; } public void setPlayTime(int time) { this.playTime = time; } public String getSong() { return song; } public String…arrow_forward
- Project 2 statement ANSWER IN SINGLE FILE JAVAPlease read this entire statement carefully before you start doing anything… This project involves implementing a simple university personnel management program. The program contains three kinds of objects: Staff, student and faculty. For each object, the program stores relevant information such as university ID, name, etc. Different information is stored depending on the type of the object. For example, a student has a GPA, a faculty has a title and department (professor, mathematics).For each of any class data member, your program must include the getters and the setters, and each class must include at least two constructors. The goal of this Project is to demonstrate the use of inheritance, abstract classes, abstract methods, and method overriding. For a student, we need a: full name id gpa Number of credit hours currently taken For a faculty, we need a: full name id department (mathematics, engineering or english) Rank (professor or…arrow_forwardA company accepts user orders by part numbers interactively. Users might make the following errors as they enter data: - The part number is not numeric. The quantity is not numeric. - The part number is too low (less than 0). - The part number is too high (more than 999). - The quantity ordered is too low (less than 1). - The quantity ordered is too high (more than 5,000). Create a class that stores an array of usable error messages; save the file as DataMessages.java. Create a DataException class; each object of this class will store one of the messages. Save the file as DataException.java. Create an application that prompts the user for a part number and quantity. Allow for the possibility of nonnumeric entries as well as out-of-range entries, and display the appropriate message when an error occurs. If no error occurs, display the message "Valid entry". Save the program as PartAndQuantityEntry.java.arrow_forwardUsing oop in java Create a class for Subject containing the Name of the subject and score of the subject. There should be following methods: set: it will take two arguments name and score, and set the values of the attributes. If score is less than 0 or greater than 100.0 then a message should be displayed “Incorrect score” and score should be set to Zero. set: it will take one double value as argument and set the value of score only. If score is less than 0 or greater than 100.0 then a message should be displayed “Incorrect score” and score should be set to Zero. display: it will display the name and score of the subject. Like “Name : Math, Score: 99.9” getScore: it will return the value of score. greaterThan: it will take subject’s object as argument, compare the calling object’s score with argument object’s score and return true if the calling object has greater score.arrow_forward
- This program uses Java. You will be making a general class that will be called “GeneralBusiness”. This class must have the following methods: selectSalesTax() – This method will read in a file “stateTaxInfo.txt” that has the name of a state and the tax percentage (decimal form) for that state and save them to the given arrays. It will then print a menu for the user to choose the state that the business is in and set the variables to hold the values. getCustomerName() – This method will prompt the user for the name of the person using the program calcSalesTax() – This method will be sent a subtotal and calculate the sales tax outputReceipt() – This method will output a generic receipt as follows: Subtotal $37.50 Sales Tax $2.44 Total $39.94 outputMenu() - This method will receive the number of items and output a generic menu as follows: Item 1 Item 2 Item 3 Item 4 must have the following variables: stateNames - array saleTax – array saleTaxAmount theStateName subtotal total firstName…arrow_forwardTwo part question: A : Radio station KJAVA wants a class to keep track of recordings it plays. Create a class named Recording that contains fields to hold methods for setting and getting a Recording’s title, artist, and playing time in seconds. Save the file as Recording.java. B : Write an application that instantiates five Recording objects and prompts the user for values for the data fields. Then prompt the user to enter which field the Recordings should be sorted by—song title, artist, or playing time. Perform the requested sort procedure, and display the Recording objects. Save the file as RecordingSort.java.arrow_forwardTravel Tickets Company sells tickets for airlines, tours, and other travel-related services. Because ticket agents frequently mistype long ticket numbers, Travel Tickets has asked you to write an application that indicates invalid ticket number entries. The class prompts a ticket agent to enter a six-digit ticket number. Ticket numbers are designed so that if you drop the last digit of the number, then divide the number by 7, the remainder of the division will be identical to the last dropped digit. Accept the ticket number from the agent and verify whether it is a valid number. Test the application with the following ticket numbers: . 123454; the comparison should evaluate to true . 147103; the comparison should evaluate to true . 154123; the comparison should evaluate to false Save the program as TicketNumber.java.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT