Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming in Java the following excersizes: You will be programming 4 separate

ID: 3561835 • Letter: P

Question

Programming in Java the following excersizes:

You will be programming 4 separate exercises.

1. (Character Class) Create a class called Character that a role-playing game might use to represent a character within the game. A character should include six stats as instance variables - strength, dexterity, constitution, intelligence, wisdom and charisma of the character (all types are int). Your class should have a constructor that initializes these six instance variables. Provide a set and a get method for each instance variable. In addition, provide a method named getStatsTotal that calculates the total of these six stats, then returns the amount as an int value. If the total is not positive, it should be set to 0. Write a test application named CharacterTest that demonstrates class Character

Explanation / Answer

package arjun;
import java.util.*;                   // For Scanner Class
class Employee

{
       String first_name=new String();
       String last_name=new String();
       double salary;
       public Employee()             //default Constructor
       {
           first_name="VIKAS";
           last_name="MAHESHWARI";
           salary=10000;
       }
       public Employee(String f_name,String l_name,double sal)             //Parameterized Constructor
       {
           first_name=f_name;
           last_name=l_name;
           salary=sal;
       }
       public void setfName(String f_name)              //Set Employee Name
       {
           first_name=f_name;
       }
       public void setlName(String l_name)              //Set Employee Name
       {
           last_name=l_name;
       }
       public void setsal(double sal)              //Set Employee Salary
       {
           if(sal>=0)
           {
               salary=sal;
           }
       }
       public void hike()
       {
           this.salary+=this.salary*10/100;
       }
       public String getfName()                           //Get name
       {
           return this.first_name;
       }
       public String getlName()                           //Get name
       {
           return this.last_name;
       }
       public double getsal()                           //Get name
       {
           return this.salary;
       }
       public void show()                       //Show complete Data
       {
           System.out.println("First Name:"+this.first_name);
           System.out.println("Last Name:"+this.last_name);
           System.out.println("Salary is:"+this.salary);
       }
}

**********************************************************************************************************

package arjun;
import java.util.*;
public class EmployeeTest {

    public EmployeeTest() {
    }
    public static void main(String args[])           //Maain Function
   {
       Employee emp=new Employee();                   // Create Instance First Employee
      
       Employee emp1=new Employee();                   // Create Instance First Employee
      
       Scanner Sc=new Scanner(System.in);           //Scanner Object Instantiation
      
       System.out.println("****************** Enter Employee Detail ****************");
      
       System.out.println("Enter Employee 1 First Name");
      
       emp.first_name=Sc.nextLine();                       //Take Input Name
      
       System.out.println("Enter Employee 1 Last Name");
      
       emp.last_name=Sc.nextLine();                       //Take Input Name
      
       System.out.println("Enter Employee 2 First Name");
      
       emp1.first_name=Sc.nextLine();                       //Take Input Name
      
       System.out.println("Enter Employee 2 Last Name");
      
       emp1.last_name=Sc.nextLine();                       //Take Input Name
              
       System.out.println("Enter Salary of Employee 1");
      
       emp.salary=Sc.nextDouble();                       //Take Input Name
      
       System.out.println("Enter Salary of Employee 2");
      
       emp1.salary=Sc.nextDouble();                       //Take Input Name
              
       emp.setfName(emp.first_name);
      
       emp.setlName(emp.last_name);
      
       emp.setsal(emp.salary);

       emp1.setfName(emp1.first_name);
      
       emp1.setlName(emp1.last_name);
      
       emp1.setsal(emp1.salary);
      
       emp.show();
  
       System.out.println("******************************************************************");
  
       emp1.show();

       System.out.println("******************After A hike of 10 % ********************");
      
       emp.hike();  
  
       emp1.hike();
  
       System.out.println("******************************************************************");
  
       emp.show();
  
       System.out.println("******************************************************************");
  
       emp1.show();

   }
  
}

******************************************************************************************************

Output:-

--------------------Configuration: <Default>--------------------
****************** Enter Employee Detail ****************
Enter Employee 1 First Name
Arjun
Enter Employee 1 Last Name
Singh
Enter Employee 2 First Name
Bhim
Enter Employee 2 Last Name
Singh
Enter Salary of Employee 1
1000
2Enter Salary of Employee 2
2000
First Name:Arjun
Last Name:Singh
Salary is:1000.0
******************************************************************
First Name:Bhim
Last Name:Singh
Salary is:2000.0
******************After A hike of 10 % ********************
******************************************************************
First Name:Arjun
Last Name:Singh
Salary is:1100.0
******************************************************************
First Name:Bhim
Last Name:Singh
Salary is:2200.0

Process completed.