programmazione-java/src/Name/Name.java

91 lines
2.3 KiB
Java
Raw Normal View History

2016-10-18 10:04:36 +00:00
import java.io.PrintStream;
2016-10-13 14:13:36 +00:00
/**
2016-10-18 10:04:36 +00:00
This class manages objects characterised by a name, a surname and a title.
2016-10-13 14:13:36 +00:00
*/
public class Name{
/**
2016-10-18 10:04:36 +00:00
This constructor uses a default title, name and surname.
2016-10-13 14:13:36 +00:00
*/
public Name(){
name="";
2016-10-18 10:04:36 +00:00
sname="";
title="";
2016-10-13 14:13:36 +00:00
}
2016-10-18 10:04:36 +00:00
2016-10-13 14:13:36 +00:00
/**
2016-10-18 10:04:36 +00:00
This constructor sets the values of name and surname, and uses a default title.
@param name The value of the name.
@param sname The value of the surname.
2016-10-13 14:13:36 +00:00
*/
2016-10-18 10:04:36 +00:00
public Name(String name, String sname){
this.name=name;
this.sname=sname;
title="";
2016-10-13 14:13:36 +00:00
}
2016-10-18 10:04:36 +00:00
2016-10-13 14:13:36 +00:00
/**
2016-10-18 10:04:36 +00:00
This constructor sets the values of name, surname and title.
@param name The value of the name.
@param sname The value of the surname.
@param title The value of the title
2016-10-13 14:13:36 +00:00
*/
2016-10-18 10:04:36 +00:00
public Name(String name, String sname, String title){
this.name=name;
this.sname=sname;
this.title=title;
2016-10-13 14:13:36 +00:00
}
2016-10-18 10:04:36 +00:00
2016-10-13 14:13:36 +00:00
/**
2016-10-18 10:04:36 +00:00
This method returns the initials as a String object.
@return the string of the initials.
2016-10-13 14:13:36 +00:00
*/
2016-10-18 10:04:36 +00:00
public String getInitials(){
return name.substring(0, 1).concat(". ").concat(sname.substring(0,1)).concat(".");
2016-10-13 14:13:36 +00:00
}
2016-10-18 10:04:36 +00:00
2016-10-13 14:13:36 +00:00
/**
2016-10-18 10:04:36 +00:00
This method returns a String object that contains both name and surname, strictly in this order.
@return A string object made up by name and surname.
2016-10-13 14:13:36 +00:00
*/
2016-10-18 10:04:36 +00:00
public String getNameSurname(){
return name.concat(" ").concat(sname);
2016-10-13 14:13:36 +00:00
}
2016-10-18 10:04:36 +00:00
2016-10-13 14:13:36 +00:00
/**
2016-10-18 10:04:36 +00:00
This method returns a String object that contains title, name and surname, strictly in this order.
@return A string object made up by title,surname and name.
2016-10-13 14:13:36 +00:00
*/
2016-10-18 10:04:36 +00:00
public String getTitleNameSurname(){
return title.concat(" ").concat(name).concat(" ").concat(sname);
2016-10-13 14:13:36 +00:00
}
2016-10-18 10:04:36 +00:00
2016-10-13 14:13:36 +00:00
/**
2016-10-18 10:04:36 +00:00
This method set a new value for the title of an object.
@param title A new value for the title of the object.
**/
public void setTitle(String title){
this.title=title;
}
/**
This method prints the value of the istance variables.
@param ps The object which must print the values.
**/
public void print(PrintStream ps){
ps.println(getTitleNameSurname());
2016-10-13 14:13:36 +00:00
}
2016-10-18 10:04:36 +00:00
2016-10-13 14:13:36 +00:00
private String name;
2016-10-18 10:04:36 +00:00
private String sname;
private String title;
2016-10-13 14:13:36 +00:00
}