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

I am very inexperienced at writing code and need some help writing the code for

ID: 670221 • Letter: I

Question

I am very inexperienced at writing code and need some help writing the code for this pseudocode. Please help.

/** * actionPerformed()

*

* Called when one of the JButtons is clicked. Detects which button was clicked and handles it.

*

* PSEUDOCOODE:

* If the source of the event was the Search button Then

* lastName = retrieve the text from the mSearchText text field.

* If lastName is the empty string Then

* Call messageBox() to display "Please enter the student's last name."

* Else * student = Call mMain.search(lastName) * If student is null Then * Call messageBox() to display "Student not found. Try again."

* Else

* Call displayStudent(student)

* End if

* End If

* Else if the source of the event was the Save button Then

* If mStudent is not null Then Call saveStudent(mStudent)

* Else if the source of the event was the Clear button Then

* Call clear()

* Else if the source of the event was the Exit button Then

* If mStudent is not null Then Call saveStudent(mStudent)

* Call mMain.exit() to terminate the application

* End If

*/

Explanation / Answer

import java.awt.event.ActionEvent;

import javax.swing.JButton;
import javax.swing.JTextField;

public class test{
   public void actionPerformed(ActionEvent e){
       JTextField mSearchText = new JTextField();
       JButton button = new JButton();
       if(e.getSource() == searchButton){
           String lastName = mSearchText.getText();
           if(lastName.length() == 0){
               messageBox("Please enter the student's last name.");
           }
           else{
               student = mMain.search(lastName);
               if(student == null){
                   messageBox("Student not found. Try again.");
               }
               else{
                   displayStudent(student);
               }
           }
       }
       else if(e.getSource() == saveButton){
           if(!mStudent){
               saveStudent(mStudent);
           }
       }
       else if(e.getSource() == clearButton){
           clear();
       }
       else if(e.getSource() == exitButton){
           if(!mStudent){
               saveStudent(mStudent);
           }
           mMain.exit();
       }      
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote