Take the code shell below and build a console program: Write the code in main to
ID: 3764207 • Letter: T
Question
Take the code shell below and build a console program: Write the code in main to declare any needed local variables, take entries for the first name, last name and raw pay. Create a myPayfile object, passing as arguments to the constructor the first name, last name and raw pay entered from the console. Call the adjustPay class method. Display the class object data to the console. The outline of the class is given as follows: class myPayfile { //declare the class variables private string last_name; private string first_name; private double gross_pay; //no argument constructor (not used) public myPayfile() { } //three-argument constructor to set the values input to the console public myPayfile(string fname, string lname, double pay) { } //public class method to return the individual value public string getLast_Name() { } //public class method to return the individual value public string getFirst_Name() { } //public class method to return the individual value public double getGross_Pay() { } //public class method to recompute the pay value public void adjustPay() { //adjust the pay by multiplying it by a factor of 1.2 } } The output should look something like this: Enter the first name Richard Enter the last name Stutte Enter the raw pay 50000 The adjusted pay is $60,000.00 for Richard Stutte Press any key to continue . . .
Explanation / Answer
import java.util.Scanner;
class myPayfile {
String first_name;
String last_name;
double gross_pay;
public myPayfile()
{
first_name = "";
last_name = "";
gross_pay = 0;
}
public myPayfile(String first, String last, double pay)
{
first_name = first;
last_name = last;
gross_pay = pay;
}
public String getLast_Name()
{
return last_name;
}
public String getFirst_Name()
{
return first_name;
}
public double getGross_Pay()
{
return gross_pay;
}
public void adjustPay()
{
gross_pay = gross_pay * 1.2;
}
}
class TestClass {
public static void main(String args[] ) throws Exception {
Scanner in = new Scanner(System.in);
String first,last,wait;
double pay;
System.out.println("enter first name");
first = in.next();
System.out.println("enter last name");
last = in.next();
System.out.println("enter raw pay");
pay = in.nextDouble();
myPayfile file1 = new myPayfile(first,last,pay);
file1.adjustPay();
System.out.println("Adjusted pay is $"+file1.getGross_Pay()+" For "+file1.getFirst_Name()+" "+file1.getLast_Name());
System.out.println("press any key to continue..");
}
}
output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.