עבור לתוכן

שאלה בJAVA : תכנות מונחה עצמים.

Featured Replies

פורסם

למה להגדיר את המשנתה float ולהחזיר double ?

פורסם

icelord69, ערוך את ההודעה שלך ושים את הקוד בתוך טג קוד (כפתור # למעלה).

פורסם
  • מחבר

תנסה לרשום פה את הקוד( או לפחות את החלקים הרלוונטים -> הגדרות של הקלאס SINGER ו DISK ), שיהיה לאנשים קל יותר להבין מה בדיוק אתה מנסה לעשות ואיפה הטעות.


public class Singer
{
private String fname;
private String lname;
private int age;
private String sex;

public Singer (String fname, String lname, int age, String sex)
{
this.fname=fname;
this.lname=lname;
this.age=age;
this.sex=sex;
}

public Singer (Singer singer)
{
this.fname = singer.fname;
this.lname = singer.lname;
this.age = singer.age;
this.sex = singer.sex;

}
public String getFname()
{
return this.fname;
}

public String getLname()
{
return this.lname;
}

public int getAge()
{
return this.age;
}

public String getSex()
{
return this.sex;
}

public void setFname(String fname)
{
this.fname=fname;
}

public void setLname(String lname)
{
this.lname=lname;
}

public void setAge(int age)
{
this.age=age;
}

public void setSex(String sex)
{
this.sex=sex;
}

public String toString()
{
return this.fname+" "+this.lname+" "+this.age+" "+this.sex;
}
}

public class Disc
{
private String discName;
private Singer singer;
private double price;
private int numOfSong;
private String style;

public Disc (String discName, Singer singer, double price, int numOfSong, String style)
{
this.discName=discName;
this.singer=new Singer(singer);
this.numOfSong=numOfSong;
this.price=price;
this.style=style;
}

public String getDiscName()
{
return this.discName;
}

public double getPrice()
{
return this.price;
}

public int getNumOfSong()
{
return this.numOfSong;
}

public String getStyle()
{
return this.style;
}

public void setDiscName(String discName)
{
this.discName=discName;
}

public void setPrice(double price)
{
this.price=price;
}

public void setNumOfSong(int numOfSong)
{
this.numOfSong=numOfSong;
}

public void setStyle (String style)
{
this.style=style;
}

public String toString ()
{
return this.discName+" "+this.singer+" "+this.price+" "+this.numOfSong+" "+this.style;
}

//הפעולה שאנחנו מדברים עליה \\

public static double calculateDiscPrice(Disc[] a)
{
double price=0;
for(int i=0; i<a.length; i++)
if((a[i].singer._______.compareTo("שלומי")==1)&&(a[i].singer._______.compareTo("שבת")==1))
price=price+a[i].price;
return price;
}

public static String mostExpensive(Disc[] a)
{
String x="No disc has more then 12 songs";
double price=a[0].price;
for(int i=1; i<a.length; i++)
if((a[i].price>price)&&(a[i].numOfSong>12))
x=a[i].discName;
return x;
}

public static void printDanceDisc(Disc[] a)
{
for(int i=0; i<a.length; i++)
if((a[i].style.compareTo("dance")==1)&&(a[i].numOfSong>10))
System.out.println(a[i].discName+" ");
}
}

מחלקה סינגר ואז דיסק.

אגב זאת לא בדיוק בעיה .. זה יותר כמו חיפוש פונקציה .. זה לא שאני לא מצליח , פשוט לא זוכר מה מורה כתב במקום ה-________ שאני כתבתי ..

פורסם

תרשום

getFname()

זה ה getter של המשתנה fname.

פורסם
  • מחבר

GETTER ^_^ !

עכשיו הבנתי .. תגידו פעולה מאחזרת ..

תאמת שבדיוק מתי שהעתקתי לך את הקוד ניסיתי את זה וזה לא סימן שגיאה.. אבל אני כמעט בטוח שהמורה שלי נתן משהו אחר..

אני אבדוק ואודיע לכם :)

חג שמח !

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים