Aditionally, i've also been given some unfinished code and asked to complete it. This consists of two classes - the ClassDate and the ClassTransaction.
ClassDate code -
class Date
{// properties
private int day, month, year;
public Date (Date d) {
day = d.day;
month = d.month;
year = d.year;
}
public Date () {
}
// methods
public void readDate(){
//TO BE COMPLETED }//readDate
public void printDate() {
System.out.print(day + "/" + month + "/" + year);
}//printDate
public boolean validDate()
{if (!validYear(year))
return false;
else if (!validMonth(month))
return false;
else if(!validDay(day,month))
return false;
else
return true;
}//validDate
private boolean validYear(int y)
{if ((y < 1990) || (y > 2100))
return false;
else
return true;
}//validYear
private boolean validMonth(int m)
{if ((m < 0) || (m > 12))
return false;
else
return true;
}//validMonth
private boolean validDay(int d, int m)
{if ((d < 0) || (d > daysinMonth(m)))
return false;
else
return true;
}//validDay
private int daysinMonth(int m)
{int NumDays;
switch(m)
{case 1:case 3:case 5:case 7:
case 8:case 10:case 12 : NumDays = 31;
break;
case 4:case 6:case 9:case 11:
NumDays = 30;
break;
case 2 : NumDays = 28;
break;
default: NumDays = 0;
}
return NumDays;
}//daysinMonth
} // end of class Date
The readDate method should prompt the user and read in relevant values for day, month and year and should determine whether the dates are valid by calling the method validDate. Any ideas on how i can complete this code ^^^ ?
ClassTransaction code -
class Transaction {
private double amount;
private double newBalance;
private boolean type;
private Date d;
public void readTransaction() {
char c;
d = new Date();
d.readDate();
do
{
System.out.print("Is this transaction a withdrawal or deposit? (W or D)
");
c = uuInOut.ReadChar();
uuInOut.ReadLn();
if (c != 'W' && c != 'w' && c != 'D' && c != 'd')
System.out.println("Invalid entry. Try again.");
}while (c != 'W' && c != 'w' && c != 'D' && c != 'd');
if (c == 'W' || c =='w')
type = true;
else
type = false;
System.out.print("Enter amount: ");
amount = uuInOut.ReadDouble();
}
public void printTransaction() {
//TO BE COMPLETED
}
public boolean getType() {
return type;
}
public double getAmount() {
return amount;
}
public void setBalance(double value) {
newBalance = value;
}
}
Complete the class Transaction, by providing code for the method printTransaction. Again any help with finishing the above code?
Thanks alot again for any help you can provide!