JAVA PROGRAMMING-LMS INTEG.MINDTAP
JAVA PROGRAMMING-LMS INTEG.MINDTAP
8th Edition
ISBN: 9781337091503
Author: FARRELL
Publisher: Cengage Learning
Expert Solution & Answer
Book Icon
Chapter 3, Problem 2GZ

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...

Blurred answer
Students have asked these similar questions
in java language  You will write a method that will take a file name (String) as a parameter that is a file of numbers and will return the sum of the numbers in the file. You will then create a GUI with the following:   1. Some way for the user to specify a file name. 2. A mechanism for the user to begin processing the file. 3. Some place to display the sum of the numbers. keep everything in one class and andinclude the method that processes the file as a static method.
Creating Enumerations In this section, you create two enumerations that hold colors and car model types. You will use them as field types in a Car class and write a demonstration program that shows how the enumerations are used.   1. Open a new file in your text editor, and type the following Color enumeration: enum Color {BLACK, BLUE, GREEN, RED, WHITE, YELLOW};   2. Save the file as Color.java.   3. Open a new file in your text editor, and create the following Model enumeration: enum Model {SEDAN, CONVERTIBLE, MINIVAN};   4. Save the file as Model.java. Next, open a new file in your text editor, and start to define a Car class that holds three fields: a year, a model, and a color.  public class Car {  private int year;  private Model model;  private Color color;   5. Add a constructor for the Car class that accepts parameters that hold the values for year, model, and color as follows:  public Car(int yr, Model m, Color c) {  year = yr;  model = m;  color = c;  }   6. Add a display()…
Variables name: Choose meaningful and descriptive names. No x, y … etc. Use lowercase. If the name consists of several words, concatenate all in one, uselowercase for the first word, and capitalize the first letter of each subsequent word inthe name. For example, the variables radius and area, and the method computeArea.3. File type: only JAVA file is allowed. Name it as Assignment2. Java5. Please add the appropriate comments for each step you add. In the top of the program, addyour name, time of starting writing the code and title of the assignment. Extra informationwould be great
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
    Text book image
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
    Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781305480537
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT