java - Calling a print method from another class with primitive data types in it -
java - Calling a print method from another class with primitive data types in it -
i have been programming in java using bluej 2 months , need help assignment. making basic vehicle purchase info entry program. need phone call printpurchasedate()
method purchasedate
class. problem faced print statement has 3 int values: year, month, , day. when seek phone call method in vehicle class in printdetails()
method, tells me need return, if take away void have label method string. doesn't work because holds 3 int variables within conflict string method. how can go doing this? want print of info including purchasedate
. apologies in advance if did not nowadays question properly, first post. give thanks help.
i have 2 classes: purchase date , vehicle.
my vehicle class has method, designed print out information:
public void printdetails() { system.out.println("customer:" + " " + customer.getfullname()); system.out.println("vehicle description:" + " " + getvehiclepurchased()); purchasedate.printpurchasedate(); }
im having issues printing date purchasedate class in vehicle class's "printdetails()" method.
/** * purchase info class */ public class purchasedate { private int year; private int month; private int day; private static final int current_year = 2014; private static final int last_month = 12; private static final int last_day = 31; /** * default constructor */ public purchasedate() { } /** * @param year initialize theyear field * @param month initialize themonth field * @param day initialize theday field */ public purchasedate(int theyear, int themonth, int theday) { setyear(theyear); setmonth(themonth); setday(theday); if (year < 1900 || year > 2014) { system.out.println("the year value can no greater current year"); } else { this.year = year; } if (month < 1 || month > 12) { system.out.println("the month value must between 1 , 12"); } else { this.month = month; } if (day < 1 || day > 31) { system.out.println("the day value must between 1 , 31"); } else { this.day = day; } } //mutators , accessors /** * @return year */ public int getyear() { homecoming year; } /** * @return month */ public int getmonth() { homecoming month; } /** * @return day */ public int getday() { homecoming day; } /** * @param year */ public final void setyear(int newyear) { year = newyear; } /** * @param month */ public final void setmonth(int newmonth) { month = newmonth; } /** * @param day */ public final void setday(int newday) { day = newday; } /** * prints purchase date */ public void printpurchasedate() { system.out.println("the purchase date is:" + " " + year + "-" + month + "-" + day); } }
i want system.out.println
print out date have in purchasedate
class.
public void printdetails() { system.out.println("customer:" + " " + customer.getfullname()); system.out.println("vehicle description:" + " " + getvehiclepurchased()); purchasedate.printpurchasedate(); }
the basic problem in code calling printpurchasedate() in static way non static method. have create refrence of purchasedate class , calll method refrence
purchasedate pd = new purchasedate(); public void printdetails() { system.out.println("customer:" + " " + customer.getfullname()); system.out.println("vehicle description:" + " " + getvehiclepurchased()); pd.printpurchasedate(); }
other thing can declair method static.
public static void printpurchasedate(){ // code here }
java methods int call primitive
Comments
Post a Comment