import javax.swing.JOptionPane;

public class Finance
{
	public static void main(String[]args)
	{
		boolean Access = false;
		String studentName = JOptionPane.showInputDialog(null, "Enter in your name: ");
		//String current = JOptionPane.showInputDialog(null, "Enter your password: ");
		//double currentBalance = Double.parseDouble(current);
	
		Account newAccount = new Account(studentName); //Gains access to Account class
		
		
		JOptionPane.showMessageDialog(null, newAccount.toString());
	}
}

class Account
{		
	//Declared Variables
	String accountName;
	private boolean error = false;
	
	//Constructor
	Account()
	{
	}
	Account(String Name)
	{		
		accountName = Name;
	}	
	public String getAccount()
	{
		return accountName;
	}	
	boolean falseAccount()
	{
		if(accountName == "keenan")
		{
			error = true;
			return true;			
		}
		else
		{
			error = false;
			return false;
		}
	}	
	
	public String toString()
	{
		if(falseAccount() == true)
		{
			return "\nAccess Granted. Welcome " + accountName;
		}
		else
		{
			return "\nAccess Denied. " + accountName + " is not on the list";
		}
	}
}

It prints out the opposite of what is needed, and also is this a clean way to write code still? I'm seeing many new ways of writing now.

Recommended Answers

All 2 Replies

at line 39 use .equals() in comparing strings like so

if( accountName.equals("keenan") )

Sigh... The the little things we make mistakes on..
Thank you, zeroliken.

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.