Java
Submitted by:
Instructor
Question 1
Public class employee
{
//creating the members of class employee
Public float empName
Public float empHours
Public float empRate
Public float empSalary
1/17
Java
//creating method display
Public float Display (float empHour, empRate, empSalary, empName)
{
system.out.println (“set the values to”+” display method”);
sytem.out.println (“”)
}
}
//Save files as employee. Java
Test program
2/17
Java
Public class employee
{
Public static void main (string [] args)
{
//creating objects e1 and e2
employee e1=new employee ();
employee e2=new employee ();
//setting values to the members and calling the display method
empName=”NOINPUT”
empHours= “NOINPUT”
empRate= “NOINPUT”
3/17
Java
empSalary= “NOINPUT”
system.out.println (“setting the values to”+” display method”);
empName.Display
empHours.Display
empRate.Display
empSalary.Display
system.out.println (“NOINPUT”)
//Save files as test employee. Java
Question2
Public class employee2
{
4/17
Java
//Creating class members
Private float empName
Private float empSalary
Private float empHour
Private float empRate
//Creating a display method
Public float Display (float empHour, empRate, empSalary, empName)
{
system.out.println (“set the values to”+” display method”);
sytem.out.println (“”)
Public void display ()
5/17
Java
//Creating get and set method
empName=Name
empRate=Rate
empHour=Hour
Public float getempName ();
{
Return empName;
}//end the get method
Public void setempName (float Name)
{
6/17
Java
empName=Name
}//end the set method
Public float getEmpRate()
{
Return empRate;
}
Public void Set empRate (float Rate);
{
empRate=Rate
}
Public float getEmpHour ()
{
7/17
Java
Return empHour;
}
Public void Set empHour(float Hour);
{
empHour=Hour
}
//Save as employee2.java
Test program
Import java.util.scanner
Public class scanner
Public class employee2
8/17
Java
{
Public static void main (string [] args)
Scanner scanner =new scanner(system.in)
{
//creating objects
Employee2 e1=new employee2 ();
Employee2 e2=new employee2 ();
Employee2 e3= new employee2 ();
//promoting the user to enter input
System.out.print (“enter empName, empHour, empRate, empSalary :”) ;
9/17
Java
Name=scanner. Next line ( );
System.out.println (“name”)
Hour=scanner. Next line ( );
System.out.println (“Hour”)
Rate=scanner. Next line ( );
System.out.println (“Rate”)
Salary=scanner. Next line ( );
System.out.println (“Salary”)
}
}
//Calling out display method
system.out.println (“set the values to”+” display method”);
Name. Display();
10/17
Java
Hours. Display();
Rate. Display();
system.out.println (“Name, Hour, Rate”);
}
//Save the file as testemployee2.java
Question 3
Public class employee3
{
Private float empName
Private float empSalary
11/17
Java
Private float empHour
Private float empRate
Public Employee3 ()//default constructor
empName=Name;
empSalary=Salary
empHour=Hour
empRate=Rate
{
}
Public Employee3 (float, Name, salary, hours, rate)
{
12/17
Java
EmpName=Name;
EmpSalary=Salary
EmpHour=Hour
EmpRate=Rate
}
//creating get and set method
Public float getSalary ( )
{
Return Salary
}
Public void setSalary ();
13/17
Java
{
Salary=hours * rate
}
}
//save the file as employee3.java
Test program
Import java.util.scanner
Public class scanner
Public class employee3
{
Public static void main (string [] args)
14/17
Java
Scanner scanner =new scanner(system.in)
{
//creating objects
Employee3 e1=new employee3();// created using the default constructor
Employee3 e2=new employee3 ( );
//promoting the user to enter input
System.out.print (“enter empName, empHour, empRate, empSalary :”);
Name=scanner. Next line ();
System.out.println (“Name”)
Rate=scanner. Next line ();
15/17
Java
System.out.println (“Rate ”)
Salary=scanner. Next line ();
System.out.println (“Salary”)
}
}
//Calling out display method
system.out.println (“set the values to”+” display method”);
Name.Display();
Hours.Display();
Rate.Display();
system.out.println (“Name, Hour, Rate”);
//Save the file as testemployee3.java
16/17
Java
Reference
Malik, D., & Burton, R.(2008).Java Programming: Guided Learning with Early Objects.Cengage Learning EMEA
17/17
- Academic Writing
- Accounting
- Anthropology
- Article
- Blog
- Business
- Career
- Case Study
- Critical Thinking
- Culture
- Dissertation
- Education
- Education Questions
- Essay Tips
- Essay Writing
- Finance
- Free Essay Samples
- Free Essay Templates
- Free Essay Topics
- Health
- History
- Human Resources
- Law
- Literature
- Management
- Marketing
- Nursing
- other
- Politics
- Problem Solving
- Psychology
- Report
- Research Paper
- Review Writing
- Social Issues
- Speech Writing
- Term Paper
- Thesis Writing
- Writing Styles