如何制作我的程序的 JAVADOC?
How to make a JAVADOC of my program?
这是我的代码:
public class Client
{
protected int cod;
protected String name;
public void setCod(int cod) throws Exception
{
if(cod==null)
throw new Exception("Invalid code!");
this.cod = cod;
}
public int getCod()
{
return this.cod;
}
public void setName(String name) throws Exception
{
if(name==null || name.equals("")
throw new Exception("Invalid name!");
this.name = name;
}
public String getName()
{
return this.name;
}
public Client(int cod, String name) throws Exception
{
this.setCod(cod);
this.setName(name);
}
public boolean equals(Object obj)
{
if(this==obj)
return true;
if(obj==null)
return false;
if(!(obj instanceof Client))
return false;
Client client = (Client)obj;
if(this.cod!=client.cod)
return false;
if(this.name!=client.name)
return false;
return true;
}
public String toString()
{
return "Code: " + this.cod + "\n" +
"Name: " + this.name;
}
public int hashCode()
{
int ret = 444;
ret += ret*7 + new Integer (this.cod).hashCode();
ret += ret*7 + (this.name).hashCode();
return ret;
}
public Object clone()
{
Client ret = null;
try
{
ret = new Client(this);
}
catch(Exception error)
{
// this is never null
}
return ret;
}
public Client(Client model) throws Exception
{
if(model==null)
throw new Exception("Inexistent model!");
this.cod = model.cod;
this.name = model.name;
}
}
我知道,要发表评论,您必须输入“//”或“/*”和“*/”。但是我如何按照 JAVADOC 规则发表评论呢?
如果你知道怎么做,你能复制我的代码并把它和 JAVADOC 一起放在你的答案中吗?谢谢:)
请告诉我,什么是 JAVADOC,它有什么用?有什么简单的方法吗?
Javadoc 是您在程序中使用的一种注释,用于组织程序,使程序更友好,并创建包含您注释的所有内容的页面 HTML,如下所示:
因此,要创建 javadoc,您需要将 /**
替换为 /*
。
创建 javadoc 时需要了解一些命令类型。
@author - who created the program
@throws - for exceptions
@param - the method parameters
@return - what the method returns
所以,你的 javadoc 代码将是这样的:
/**
* @author IncredibleCoding
*/
public class Client
{
protected int cod;
protected String name;
/**
* instance the code passed
*/
public void setCod(int cod) throws Exception
{
if(cod==null)
throw new Exception("Invalid code!");
this.cod = cod;
}
/**
* @returns the code
*/
public int getCod()
{
return this.cod;
}
/**
* instance the name passed
* @param name, that is the name passed
* @throws Exception, if the name is in invalid format
*/
public void setName(String name) throws Exception
{
if(name==null || name.equals("")
throw new Exception("Invalid name!");
this.name = name;
}
/**
* @returns the name
*/
public String getName()
{
return this.name;
}
/**
* the constructor
* @param cod, that is the code passed
* @param name, that is the name passed
*/
public Client(int cod, String name) throws Exception
{
this.setCod(cod);
this.setName(name);
}
/**
* @param obj, that is the object that will be compared
* @returns true if the object is equal to this, false if the object isn't equal
*/
public boolean equals(Object obj)
{
if(this==obj)
return true;
if(obj==null)
return false;
if(!(obj instanceof Client))
return false;
Client client = (Client)obj;
if(this.cod!=client.cod)
return false;
if(this.name!=client.name)
return false;
return true;
}
/**
* returns the formatted variable like String
*/
public String toString()
{
return "Code: " + this.cod + "\n" +
"Name: " + this.name;
}
/**
* returns the hashCode of a variable
*/
public int hashCode()
{
int ret = 444;
ret += ret*7 + new Integer (this.cod).hashCode();
ret += ret*7 + (this.name).hashCode();
return ret;
}
/**
* clone the object
*/
public Object clone()
{
Client ret = null;
try
{
ret = new Client(this);
}
catch(Exception error)
{
// this is never null
}
return ret;
}
/**
* "copy" the variables
* @param model, that is the object that will be copied
* @throws Exception, if the model is inexistent
*/
public Client(Client model) throws Exception
{
if(model==null)
throw new Exception("Inexistent model!");
this.cod = model.cod;
this.name = model.name;
}
}
您应该考虑看看这个 ORACLE 的页面,这对您也有帮助:
https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javadoc.html
这是我的代码:
public class Client
{
protected int cod;
protected String name;
public void setCod(int cod) throws Exception
{
if(cod==null)
throw new Exception("Invalid code!");
this.cod = cod;
}
public int getCod()
{
return this.cod;
}
public void setName(String name) throws Exception
{
if(name==null || name.equals("")
throw new Exception("Invalid name!");
this.name = name;
}
public String getName()
{
return this.name;
}
public Client(int cod, String name) throws Exception
{
this.setCod(cod);
this.setName(name);
}
public boolean equals(Object obj)
{
if(this==obj)
return true;
if(obj==null)
return false;
if(!(obj instanceof Client))
return false;
Client client = (Client)obj;
if(this.cod!=client.cod)
return false;
if(this.name!=client.name)
return false;
return true;
}
public String toString()
{
return "Code: " + this.cod + "\n" +
"Name: " + this.name;
}
public int hashCode()
{
int ret = 444;
ret += ret*7 + new Integer (this.cod).hashCode();
ret += ret*7 + (this.name).hashCode();
return ret;
}
public Object clone()
{
Client ret = null;
try
{
ret = new Client(this);
}
catch(Exception error)
{
// this is never null
}
return ret;
}
public Client(Client model) throws Exception
{
if(model==null)
throw new Exception("Inexistent model!");
this.cod = model.cod;
this.name = model.name;
}
}
我知道,要发表评论,您必须输入“//”或“/*”和“*/”。但是我如何按照 JAVADOC 规则发表评论呢?
如果你知道怎么做,你能复制我的代码并把它和 JAVADOC 一起放在你的答案中吗?谢谢:)
请告诉我,什么是 JAVADOC,它有什么用?有什么简单的方法吗?
Javadoc 是您在程序中使用的一种注释,用于组织程序,使程序更友好,并创建包含您注释的所有内容的页面 HTML,如下所示:
因此,要创建 javadoc,您需要将 /**
替换为 /*
。
创建 javadoc 时需要了解一些命令类型。
@author - who created the program
@throws - for exceptions
@param - the method parameters
@return - what the method returns
所以,你的 javadoc 代码将是这样的:
/**
* @author IncredibleCoding
*/
public class Client
{
protected int cod;
protected String name;
/**
* instance the code passed
*/
public void setCod(int cod) throws Exception
{
if(cod==null)
throw new Exception("Invalid code!");
this.cod = cod;
}
/**
* @returns the code
*/
public int getCod()
{
return this.cod;
}
/**
* instance the name passed
* @param name, that is the name passed
* @throws Exception, if the name is in invalid format
*/
public void setName(String name) throws Exception
{
if(name==null || name.equals("")
throw new Exception("Invalid name!");
this.name = name;
}
/**
* @returns the name
*/
public String getName()
{
return this.name;
}
/**
* the constructor
* @param cod, that is the code passed
* @param name, that is the name passed
*/
public Client(int cod, String name) throws Exception
{
this.setCod(cod);
this.setName(name);
}
/**
* @param obj, that is the object that will be compared
* @returns true if the object is equal to this, false if the object isn't equal
*/
public boolean equals(Object obj)
{
if(this==obj)
return true;
if(obj==null)
return false;
if(!(obj instanceof Client))
return false;
Client client = (Client)obj;
if(this.cod!=client.cod)
return false;
if(this.name!=client.name)
return false;
return true;
}
/**
* returns the formatted variable like String
*/
public String toString()
{
return "Code: " + this.cod + "\n" +
"Name: " + this.name;
}
/**
* returns the hashCode of a variable
*/
public int hashCode()
{
int ret = 444;
ret += ret*7 + new Integer (this.cod).hashCode();
ret += ret*7 + (this.name).hashCode();
return ret;
}
/**
* clone the object
*/
public Object clone()
{
Client ret = null;
try
{
ret = new Client(this);
}
catch(Exception error)
{
// this is never null
}
return ret;
}
/**
* "copy" the variables
* @param model, that is the object that will be copied
* @throws Exception, if the model is inexistent
*/
public Client(Client model) throws Exception
{
if(model==null)
throw new Exception("Inexistent model!");
this.cod = model.cod;
this.name = model.name;
}
}
您应该考虑看看这个 ORACLE 的页面,这对您也有帮助:
https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javadoc.html