Question

A class called Author is designed as shown in the class diagram. (JAVA)

in java


A class called Author is designed as shown in the class diagram. 


Author 

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 


It contains 

 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) f......) 

 public getters/setters: getName(), getEmail setEmail and getGender(); (There are no setters for name and gender, as these attributes cannot be changed.) 

 AtoString method that returns "author-name (gender) at email", e.g., "Tan Ah Teck (m) at [email protected]". 



0 0
Add a comment Improve this question Transcribed image text
Answer #1

//********* Author.java ****************//


class Author

{

private String name;

private String email;

private boolean gender; //male=false; female=true;


public Author( String name, String email, boolean gender)

{

this.name = new String(name);

this.email = new String(email);

this.gender = gender;

}


public String getName() { return(name); }

public String getEmail() { return(email); }

public boolean getGender() { return(gender); }


public Author(Author author)

{

this.name = new String(author.getName());

this.email = new String(author.getEmail());

this.gender = author.getGender();

}


public void setName( String name) { this.name = new String(name); }

public void setEmail(String email) { this.email = new String(email); }

public void setGenderMale() { this.gender = false; }

public void setGenderFemale() { this.gender = true; }


@Override public String toString()

{

char chGender = (this.gender) ? 'F' : 'M';

return(

new String(

this.name + "(" + chGender + ") at " + this.email

)

);

}

}


source: database
answered by: balen muhsin
Add a comment
Know the answer?
Add Answer to:
A class called Author is designed as shown in the class diagram. (JAVA)
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram)

    Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -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 . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...

  • In Java* Please implement a class called "MyPet". It is designed as shown in the following...

    In Java* Please implement a class called "MyPet". It is designed as shown in the following class diagram. Four private instance variables: name (of the type String), color (of the type String), gender (of the type char) and weight(of the type double). Three overloaded constructors: a default constructor with no argument a constructor which takes a string argument for name, and a constructor with take two strings, a char and a double for name, color, gender and weight respectively. public...

  • Here is a sample run of the tester program: Make sure your program follows the Java...

    Here is a sample run of the tester program: Make sure your program follows the Java Coding Guidelines. Consider the following class: /** * A store superclass with a Name and Sales Tax Rate */ public class Store {      public final double SALES_TAX_RATE = 0.06;      private String name;           /**      * Constructor to create a new store      * @param newName      */      public Store(String newName)      {           name = newName;      }     ...

  • Write a class named Book containing: Two instance variables named title and author of type String....

    Write a class named Book containing: Two instance variables named title and author of type String. A constructor that accepts two String parameters. The value of the first is used to initialize the value of title and the value of the second is used to initialize author. A method named toString that accepts no parameters. toString returns a String consisting of the value of title, followed by a newline character, followed by the value of author.

  • JAVA /** * This class stores information about an instructor. */ public class Instructor { private...

    JAVA /** * This class stores information about an instructor. */ public class Instructor { private String lastName, // Last name firstName, // First name officeNumber; // Office number /** * This constructor accepts arguments for the * last name, first name, and office number. */ public Instructor(String lname, String fname, String office) { lastName = lname; firstName = fname; officeNumber = office; } /** * The set method sets each field. */ public void set(String lname, String fname, String...

  • Please do this in C++. Thank you in advance. Note that you have to carefully create...

    Please do this in C++. Thank you in advance. Note that you have to carefully create your class using the names and capitalization shown below. Put comments into your program, make sure you indent your program properly, and use good naming conventions. Create a class called entry. It should have two private data members of type std::string. One represents a name and the other represents an email address. Make sure you give them ,meaningful names. Create public getters and setters...

  • Create a java class for an object called Student which contains the following private attributes: a...

    Create a java class for an object called Student which contains the following private attributes: a given name (String), a surname (family name) (String), a student ID number (an 8 digit number, String or int) which does not begin with 0. There should be a constructor that accepts two name parameters (given and family names) and an overloaded constructor accepting two name parameters and a student number. The constructor taking two parameters should assign a random number of 8 digits....

  • I have a java class that i need to rewrite in python. this is what i...

    I have a java class that i need to rewrite in python. this is what i have so far: class Publisher: __publisherName='' __publisherAddress=''    def __init__(self,publisherName,publisherAddress): self.__publisherName=publisherName self.__publisherAddress=publisherAddress    def getName(self): return self.__publisherName    def setName(self,publisherName): self.__publisherName=publisherName    def getAddress(self): return self.__publisherAddress    def setAddress(self,publisherAddress): self.__publisherAddress=publisherAddress    def toString(self): and here is the Java class that i need in python: public class Publisher { //Todo: Publisher has a name and an address. private String name; private String address; public Publisher(String...

  • plz finish All ToDos for java code ASAP Read and attempt the ToDos in the following...

    plz finish All ToDos for java code ASAP Read and attempt the ToDos in the following code public class ExamProblem Il ToDol: the following instance members declaration violates encapsulation principles, l also one of the names is not compatible with Java naming convention, fix these 3 problems public String studentName public String StudentAddress public ExamProblemO this.studentName this StudentAddress ToDo2: Overload the constructor with another that accepts name and /l instance members. t accepts name and address. Use the parameters to...

  • A java class named Book contains: instance data for the title, author, publisher and copyright year...

    A java class named Book contains: instance data for the title, author, publisher and copyright year a constructor to accept and initialize the instance data variables set and get methods a toString() method to return a formatted, multi-line description of the book Produce a child class that inherits from Book. The class is called Dictionary. Dictonary must include: instance data that describes the number of words in the dictionary a constructor that takes in all information needed to describe a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT