0

Hi all, I created a parser class to parse a string inputed by the user. The BankAccountParser class is a utility class that will be used to create a bank account object (one of a saving object, a checking object, and a money market object ----> All of these classes are already created) from a parsable string. The following method is needed: public static BankAccount parseStringToAccount(String lineToParse. The parseStringToAccount method's argument will be a string in the following format:

For a saving,

type/accountID/balance/interest

For a money market,

type/accountID/balance/interest/penalty

For a checking,

type/accountID/balance/interest/numberOfUsedChecks

A real example of this string would be:

Saving/1003/4000.50/0.03

OR

MoneyMarket/1004/4000.50/0.08/14.00

OR

Checking/1005/4000.50/0.05/24

The BankAccountParser will parse this string, pull out the information, create/instantiate a new object of one of Saving, MoneyMarket, or Checking using their constructor with attributes of the object (depending on whether the first substring is Saving, MoneyMarket, or Checking), and return it to the calling method. The type will always be present and always be one of Saving, MoneyMarket, and Checking. (It can be lower case or upper case).

I am new to Java and I am having troubles creating/instantiating a new object of these different classes (Saving, MoneyMarket, Checking).

My code looks like this as of now:

public class BankAccountParser class
 {
	 public static BankAccount parseStringToAccount(String lineToParse)

	 	{
			lineToParse.split("/");

			if (words[0] equals ("Saving"))
				{
					stringID = "Saving";
					Saving newSaving = new 
				}

			else if (words[0] equals ("Checking"))
				{
					stringID = "Checking";
				}

			else if (words[0] equals ("MoneyMarket"))
				{
					stringID = "MoneyMarket";
				}

			return stringID;
		}
}

For an example of the MoneyMarket, Saving, and Checking class, my code for checking class is listed below:

public class Checking extends BankAccount
 {
  public Checking(String, double, double, int)

  	{
		super(accountID, balance, interest);
		int numberOfUsedChecks;
	}

  public void updateBalance()

  	{
		if (balance >= "1000.00") && (numberOfUsedChecks < "30")

		{
			balance = (balance) + (balance * interest);
		}

		else

		{
			balance = balance;
		}

		return balance;

	}

  public String toString();

  	{
		String result = ( " \n" + "Checking Account:"
						+ "\n" + super.toString()
						+ "\n" + "Number of Used Checks:\t" + numberOfUsedChecks + "\n\n" );

		return result;
	}

I really appreciate the help. Thanks in advance.

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by dem10
0

I believe this should work:

public class BankAccountParser class
 {
	 public static BankAccount parseStringToAccount(String lineToParse)

	 	{
			lineToParse.split("/");

			if (words[0] equals ("Saving"))
				{
					//stringID = "Saving";
					Saving newAccount = new Saving();
				}

			else if (words[0] equals ("Checking"))
				{
					//stringID = "Checking";
					Checking newAccount = new Checking();
				}

			else if (words[0] equals ("MoneyMarket"))
				{
					//stringID = "MoneyMarket";
					MoneyMarket newAccount = new MoneyMarket();
				}

			return newAccount;
		}
 }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.