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

Create the following program using java, or anything to compare what i have been

ID: 3926806 • Letter: C

Question

Create the following program using java, or anything to compare what i have been doing. Thanks

Name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail():String +setEmail(email:String):void +getGender():char +toString():String Three private instance variables: name (String), email (string), and gender (char of either 'm' or 'f'); One constructor to initialize the name, email and gender with the given values; public Author (String name, String email, char gender) {....} (There is no default constructor for Author, as there are no defaults for name, email and gender.) public getters/setters: getName(), getEmail(), setEmail(), and eretGender (); (There are no setters for name and gender, as these attributes cannot be changed.) A toString () method that returns "author-name (gender) at email", e.g., "Tan Ah Teck (m) at ahTeck@somewhere.com". Write the Author class. Also write a test program called TestAuthor to test the constructor and public methods. Try changing the email of an author, e.g. Author anAuthor = new Author("Tan Ah Teck", ahteok@ somewhere.com", 'm'); System.out.printIn(anAuthor);//Call toString() anAuthor.setEmail ("paul@nowhere. com"); System, out .printIn (anAuthor);

Explanation / Answer

TestAuthor.java


public class TestAuthor {

   public static void main(String[] args) {  
       Author anAuthor = new Author("Tan Ah Teck", "ahteck@somewhere.com", 'm');
       System.out.println(anAuthor.toString());
       anAuthor.setEmail("paul@nowhere.com");
       System.out.println(anAuthor.toString());
   }

}

Author.java


public class Author {
   private String name;
   private String email;
   private char gender;
   public Author(String n, String e, char c){
       name = n;
       email = e;
       gender = c;
   }
   public String getName() {
       return name;
   }
   public String getEmail() {
       return email;
   }
   public void setEmail(String email) {
       this.email = email;
   }
   public char getGender() {
       return gender;
   }
   public String toString(){
       return "Name: "+name+" Email: "+email+" Gender: "+gender;
   }
  
}

Output:

Name: Tan Ah Teck Email: ahteck@somewhere.com Gender: m
Name: Tan Ah Teck Email: paul@nowhere.com Gender: m

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