mojtaba5
پنج شنبه 13 آذر 1393, 18:48 عصر
دوستان من تازه دارم جاوا یاد میگیرم
یه برنامه نوشتم نام سن و کشور و متدها و متغیرهای دیگه ای برای حیوان داره.
مشکل اولم اینه که میخوام هر متد توی یک خط جدا چاپ بشه.
مشکل دومم هم اینه که برای ساخت جنسیت شیر باید از logical استفاده کنم بصورتی که مثلا 0 برای نر و 1 برای ماده باشه ، هر کدوم رو مقدار دهی کردیم جنسیت متناظر با اون رو چاپ کنه، چون تا حالا از logical استفاده نکردم نتونستم پیاده سازیش کنم برای همین کدهام رو میزارم تا کمکم کنید:
package tm;
public class tm {
public static void main(String[] args) {
lion tom = new lion();
tom.setName("tomy");
tom.setCountry("africa");
tom.setEat("barre");
tom.setHunt("deer");
tom.setSleep("grove");
tom.sex();
tom.setAge(5);
tom.showinfo(tom);
tom.eat(tom);
tom.hunt(tom);
tom.sleep(tom);
tom.age(tom);
tom.sex(tom);
}
}
package tm;
import javax.xml.ws.LogicalMessage;
import javax.xml.ws.handler.LogicalHandler;
public class lion {
private String name,country,eat,hunt,sleep;
private int age;
private LogicalMessage sex;
public lion() {
// TODO Auto-generated constructor stub
}
public void setSex(LogicalMessage sex) {
this.sex = sex;
}
public LogicalMessage getSex() {
return sex;
}
public void setName(String name) {
this.name = name;
}
public void setCountry(String country) {
this.country = country;
}
public String getName() {
return name;
}
public String getCountry() {
return country;
}
public void setEat(String eat) {
this.eat = eat;
}
public String getEat() {
return eat;
}
public void setHunt(String hunt) {
this.hunt = hunt;
}
public String getHunt() {
return hunt;
}
public void setSleep(String sleep) {
this.sleep = sleep;
}
public String getSleep() {
return sleep;
}
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return age;
}
public void showinfo (lion tom) {
System.out.print("name is : " + tom.getName() + "country is : " + tom.getCountry());
}
public void eat (lion tom){
System.out.print("tom eating :" + tom.getEat());
}
public void hunt (lion tom){
System.out.print("tom hunting is :" + tom.getHunt());
}
public void sleep (lion tom){
System.out.print("tom sleeping in the :" + tom.getSleep());
}
public void age (lion tom){
System.out.print("tom's age :" + tom.getAge());
}
public void sex (lion tom){
System.out.print("tom's sex :" + tom.getSex());
}
}
یه برنامه نوشتم نام سن و کشور و متدها و متغیرهای دیگه ای برای حیوان داره.
مشکل اولم اینه که میخوام هر متد توی یک خط جدا چاپ بشه.
مشکل دومم هم اینه که برای ساخت جنسیت شیر باید از logical استفاده کنم بصورتی که مثلا 0 برای نر و 1 برای ماده باشه ، هر کدوم رو مقدار دهی کردیم جنسیت متناظر با اون رو چاپ کنه، چون تا حالا از logical استفاده نکردم نتونستم پیاده سازیش کنم برای همین کدهام رو میزارم تا کمکم کنید:
package tm;
public class tm {
public static void main(String[] args) {
lion tom = new lion();
tom.setName("tomy");
tom.setCountry("africa");
tom.setEat("barre");
tom.setHunt("deer");
tom.setSleep("grove");
tom.sex();
tom.setAge(5);
tom.showinfo(tom);
tom.eat(tom);
tom.hunt(tom);
tom.sleep(tom);
tom.age(tom);
tom.sex(tom);
}
}
package tm;
import javax.xml.ws.LogicalMessage;
import javax.xml.ws.handler.LogicalHandler;
public class lion {
private String name,country,eat,hunt,sleep;
private int age;
private LogicalMessage sex;
public lion() {
// TODO Auto-generated constructor stub
}
public void setSex(LogicalMessage sex) {
this.sex = sex;
}
public LogicalMessage getSex() {
return sex;
}
public void setName(String name) {
this.name = name;
}
public void setCountry(String country) {
this.country = country;
}
public String getName() {
return name;
}
public String getCountry() {
return country;
}
public void setEat(String eat) {
this.eat = eat;
}
public String getEat() {
return eat;
}
public void setHunt(String hunt) {
this.hunt = hunt;
}
public String getHunt() {
return hunt;
}
public void setSleep(String sleep) {
this.sleep = sleep;
}
public String getSleep() {
return sleep;
}
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return age;
}
public void showinfo (lion tom) {
System.out.print("name is : " + tom.getName() + "country is : " + tom.getCountry());
}
public void eat (lion tom){
System.out.print("tom eating :" + tom.getEat());
}
public void hunt (lion tom){
System.out.print("tom hunting is :" + tom.getHunt());
}
public void sleep (lion tom){
System.out.print("tom sleeping in the :" + tom.getSleep());
}
public void age (lion tom){
System.out.print("tom's age :" + tom.getAge());
}
public void sex (lion tom){
System.out.print("tom's sex :" + tom.getSex());
}
}