The code below is a section of a target program that just wi

The code below is a section of a target program that just will not complete it keeps starting have THREE errors. Please indicate where the errors and will what should be added, modified or deleted. Private class MyListener extends ActionListener {public void actionPerformed(ActionEvent e) {System.Out.println(\"The listener function first now executed\");}} JButton myButton = new Button(\"Hello\"); Addmy(); MyListener.myL = new MyListener(); myButton.addActionListener(myButton); List the following steps(1, 2, 3, 4, 5, 6) in the order needed to create a GUI: Create component Add component to the container Create a container/frame Specify the layout to be used in the container Add component to the action listener Suppose you have a file \"curr_employee.txt\" with the following data time: (the data represent the employee name, years of service and hourly rate) myName 6.22.50 Write a section of code that will declare the needed the I/O object. Then include three commands enter the fields. A string, an integer and a double. Be sure to include a command line that will close the file when done.

Solution

1. Create a container/frame.
2. Specify the layout to be used in the container.
3. Create component.
4. Create an actionlister.
5. add component to container
6. add component to the actionlister


package bookserial;

import java.io.File;
import java.util.Scanner;

public class Employee {

   private String name;
   private int yearsOfService;
   private double hourlyRate;

   /**
   * @param name
   * @param yearsOfService
   * @param hourlyRate
   */
   public Employee(String name, int yearsOfService, double hourlyRate) {
       this.name = name;
       this.yearsOfService = yearsOfService;
       this.hourlyRate = hourlyRate;
   }

   /**
   * @return the name
   */
   public String getName() {
       return name;
   }

   /**
   * @param name
   * the name to set
   */
   public void setName(String name) {
       this.name = name;
   }

   /**
   * @return the yearsOfService
   */
   public int getYearsOfService() {
       return yearsOfService;
   }

   /**
   * @param yearsOfService
   * the yearsOfService to set
   */
   public void setYearsOfService(int yearsOfService) {
       this.yearsOfService = yearsOfService;
   }

   /**
   * @return the hourlyRate
   */
   public double getHourlyRate() {
       return hourlyRate;
   }

   /**
   * @param hourlyRate
   * the hourlyRate to set
   */
   public void setHourlyRate(double hourlyRate) {
       this.hourlyRate = hourlyRate;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return \"Employee [name=\" + name + \", yearsOfService=\" + yearsOfService
               + \", hourlyRate=\" + hourlyRate + \"]\";
   }

   public static void main(String[] args) {

       Scanner scanner = null;
       try {
           File file = new File(\"curr_employees.txt\");
           scanner = new Scanner(file);
           Employee employee = new Employee(scanner.next(), scanner.nextInt(),
                   scanner.nextDouble());
           System.out.println(employee);

       } catch (Exception e) {
           // TODO: handle exception
           e.printStackTrace();
       } finally {
           if (scanner != null) {
               scanner.close();

           }

       }
   }

}

curr_employees.txt
Srinivas 6 22.50
OUTPUT:
Employee [name=Srinivas, yearsOfService=6, hourlyRate=22.5]

 The code below is a section of a target program that just will not complete it keeps starting have THREE errors. Please indicate where the errors and will what
 The code below is a section of a target program that just will not complete it keeps starting have THREE errors. Please indicate where the errors and will what
 The code below is a section of a target program that just will not complete it keeps starting have THREE errors. Please indicate where the errors and will what

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site