I'm supposed to make a banking system that allows me to make transactions for individuals bank accounts. I'm also supposed to primarily use arrays and for loops and those kind of basic things... It's an intro to programming class.

I'm having trouble getting my account class to work. I'm trying to use it to implement different transactions... but I'm getting an error because I'm trying to use type MyDate transdate in the transaction constructor, but I can't reference the transdate from my Account class... It's a beginner question I'm sorry...

I don't need someone to fix the code for me, but if someone could explain what is going on, I'd appreciate it!! thanks!!

public class Account {

	private Customer customer;
	private double AcctBalance;
	private int AcctNumber;
	Transaction t[] = new Transaction[20];
	private int entTrans;
	
	
	private static int nextAcctNum;
	private static double intRate = 0.0001;
	
	public Account (Customer xcust, double xbalance, String xdate){
		customer = xcust;
		AcctBalance = xbalance;
	
		t[1] = new Transaction('d', transdate, AcctBalance);
	}
public class Transaction {

	private char transtype = 'd' | 'w';
	static MyDate transdate;
	private double transamt;
	
	public Transaction(char xtranstype, String eDate, double xtransamt){
		
		transtype = xtranstype;
        transamt = xtransamt;
        
		String sInt = "";
		int datePart[] = new int[3];
		int dp[][] = {{1,2,2001}, {2,22,2002},{3,3,2003}};
		char result = 'y';
		int j = 0;
		
		for ( int i = 0; i < eDate.length(); i++){
			result = eDate.charAt(i);
			if (result == '/'){
				datePart[j] = Integer.parseInt(sInt);
				sInt = "";
				j++;
				continue;
			}//end if
			sInt = sInt + result;
		}//end for
		datePart[j] = Integer.parseInt(sInt);
		
		transdate = new MyDate(datePart[0], datePart[1], datePart[2]);
        
	}
	
	public Transaction(char xtranstype, MyDate xtransdate, double xtransamt){
		transtype = xtranstype;
        transamt = xtransamt;
        transdate = xtransdate;
	}
	
	public char gettranstype() {
        return transtype;
    }
	
	public MyDate gettransdate() {
        return transdate;
    }
	
	public double gettransamt() {
        return transamt;
    }
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
public class MyDate {

		private int month;
		private int day;
		private int year;
		Customer cust1;
		private String date;
		
		public MyDate (int m, int d, int y){
			
			month = m;
			day = d;
			year = y;
			
		}
		
		int getMonth(){
			return month;
		}
		int getDay(){
			return day;
		}
		int getYear(){
			return year;
		}
		
		boolean equals (MyDate p){
			if (month == p.getMonth() & day == p.getDay() & year == p.getYear()){
				return true;	
			}
			return false;
		}
		
		public int addDay (MyDate p){
			day = day + 1;	
			return day;
		}
		public int addDays (MyDate p, int n){
			day = day + n;
			return day;
		}
		public int addMonth (MyDate p){
			month = month + 1;
			return month;
		}
		public int addYear (MyDate p){
			year = year + 1;
			return year;
		}
		public int resetday (MyDate p){
			day = 1;
			return day;
		}
}

Here's the error I get... It also says that transdate cannot resolved to a variable

The only transdate I see is a static variable in the Transaction class. Note that you haven't specified public, private, protected, so it'll default to whatever the default is, I can't remember, but you can always provide one(private, protected, public). Anyway, it's static, so you have to provide the class: Transaction.transdate, so your constructor call would be this...

t[1] = new Transaction('d', Transaction.transdate, AcctBalance);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.