This commit is contained in:
Orange_Dugongo 2016-10-18 12:04:36 +02:00
parent c7a6e914e2
commit 1a15f62771
4 changed files with 72 additions and 57 deletions

Binary file not shown.

View File

@ -1,71 +1,90 @@
import java.io.PrintStream;
/**
La classe Name rappresenta il nome di una persona.
include il nome, il cognome e il titolo della persona.
This class manages objects characterised by a name, a surname and a title.
*/
public class Name{
/**
Inizializza una persona settando tutti i suo parametri come vuoti
This constructor uses a default title, name and surname.
*/
public Name(){
name="";
cname="";
titolo="";
sname="";
title="";
}
/**
Inizializza una persona.
@param n nome della persona
@param c cognome della persona
*/
public Name(String n, String c){
name=n;
cname=c;
titolo="";
}
/**
Inizializza una persona.
@param n nome della persona
@param c cognome della persona
@param t titolo della persona
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.
*/
public Name(String n, String c, String t){
name=n;
cname=c;
titolo=t;
public Name(String name, String sname){
this.name=name;
this.sname=sname;
title="";
}
/**
@return Una stringa con le le iniziali
*/
public String iniziali(){
return name.substring(0, 1).concat(". ").concat(cname.substring(0,1)).concat(".");
}
/**
@return Una stringa con il nome e cognome
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
*/
public String nomeCognome(){
return name.concat(" ").concat(cname);
public Name(String name, String sname, String title){
this.name=name;
this.sname=sname;
this.title=title;
}
/**
@return Una stringa con il titolo, il cognome e il nome
*/
public String title(){
return titolo.concat(" ").concat(cname).concat(" ").concat(name);
}
/**
@param Nuovo titolo
This method returns the initials as a String object.
@return the string of the initials.
*/
public void setTitolo(String t){
titolo=t;
public String getInitials(){
return name.substring(0, 1).concat(". ").concat(sname.substring(0,1)).concat(".");
}
/**
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.
*/
public String getNameSurname(){
return name.concat(" ").concat(sname);
}
/**
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.
*/
public String getTitleNameSurname(){
return title.concat(" ").concat(name).concat(" ").concat(sname);
}
/**
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());
}
private String name;
private String cname;
private String titolo;
private String sname;
private String title;
}

Binary file not shown.

View File

@ -2,21 +2,17 @@ import java.io.*;
public class NameTester{
public static void main(String [] args){
Name persona1 = new Name();
persona1.setTitolo("Sig.");
System.out.println(persona1.title());
persona1 = new Name("Mario", "Rossi");
persona1.setTitolo("Sig.");
System.out.println(persona1.iniziali());
persona1 = new Name("Maria", "Bianchi", "Sig.na");
System.out.println(persona1.nomeCognome());
System.out.println(persona1.title());
Name persona = new Name();
persona.setTitle("Sig.");
persona.print(System.out); //We expect Sig.
persona = new Name("Mario", "Rossi");
System.out.println(persona.getInitials()); //We expect M. R.
persona = new Name("Jon", "Snow", "King in the North");
System.out.println(persona.getNameSurname()); //We expect Jon Snow
System.out.println(persona.getTitleNameSurname()); //We expect a very big spoiler
}
}