# Thread: Simple Java program not working:

1. Senior Member Join Date
Jan 2014
Posts
137
Rep Power
0

## Simple Java program not working:

This is a very simple program but when I run it my "miniumBalance" method returns my else statement "ERROR-Account Type was not found."

Java Code:
```import java.util.Scanner;

public class BankAccount
{
private Double balance;

public Double minimunBalance(String acccType)
{
if(acccType == "student" || acccType == "Student")
{
set_balance(100.00);
}
else if(acccType == "basic" || acccType == "Basic")
{
set_balance(500.00);
}
{
set_balance(1000.00);
}
else
{
set_balance(000.00);
}

return get_balance();
}

//setter function
public void set_balance(Double amount)
{
balance=amount;
}
//getter function
public Double get_balance()
{
return balance;
}

public void FindInterest(String a)
{
double min_balance = minimunBalance(a);
double interest = 0;
double total = 0;

if(min_balance == 100)
{
interest = 0.03; // % 3.0 quarterly
total = min_balance * interest * (.25); // 1st quarter

//calculate quarters 2-4
for(int i=0;i<3;i++){total = total * interest * (.25);};

System.out.println("The is a minimun requirement of \$100 balance for this account.\n");
System.out.println("If you leave 100 dollars in your account\n"
+ "you will have of "+total+" in your account after 12 montns.\n"
+ " because we give you a amazing interst rate of % 3.0.");
}
else if(min_balance == 500)
{
interest = 0.032; // % 3.2 quarterly

total = min_balance * interest * (.25); // 1st quarter

//calculate quarters 2-4
for(int i=0;i<3;i++){total = total * interest * (.25);};

System.out.println("The is a minimun requirement of \$500 balance for this account.\n");
System.out.println("If you leave 500 dollars in your account\n"
+ "you will have of "+total+" in your account after 12 montns.\n"
+ " because we give you a amazing interst rate of % 3.2.");
}
else if(min_balance == 1000)
{
interest = 0.041; // % 4.1 quarterly

total = min_balance * interest * (.25); // 1st quarter

//calculate quarters 2-4
for(int i=0;i<3;i++){total = total * interest * (.25);};

System.out.println("The is a minimun requirement of \$1000 balance for this account.\n");
System.out.println("If you leave 1000 dollars in your account\n"
+ "you will have of "+total+" in your account after 12 montns.\n"
+ " because we give you a amazing interst rate of % 4.1.");
}
else
{
System.out.println("Sorry but an Error occured");
}

}
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);

System.out.println("Enter the account type you are interested in:\n"
+ "Student\n"
+ "Basic\n"

String status = input.nextLine();

BankAccount account = new BankAccount();

account.FindInterest(status);

input.close();
}

}``` Reply With Quote

2. Senior Member Join Date
Apr 2013
Location
Sweden
Posts
272
Rep Power
8

## Re: Simple Java program not working:

don't compare String types with ==, rather with the equals method Reply With Quote

3. Just a guy Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
13

## Re: Simple Java program not working:

Java Code:
`else if(acccType == "advanced" || acccType == "Advanced")`
its less error-prone to do:

Java Code:
`else if(acccType.equalsIgnoreCase("advanced")){`
or to just toLowerCase() the input value right from the start. Reply With Quote

4. Senior Member Join Date
Jan 2014
Posts
137
Rep Power
0

## Re: Simple Java program not working:

Thank you.... I am coming from C++ and trying to learn Java. Reply With Quote

5. Just a guy Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
13

## Re: Simple Java program not working:

String is an object, if you use == to compare two String references you're only checking if it is the exact same object instance and not if the String objects contain the exact same sequence of characters. Much in the same way that in C++ you would be checking if two pointers point to exactly the same memory address and thus the same array of characters / the same STL string object.

But in C++ the truth can be muddied because you are able to overload the standard behavior of the == operator. Perhaps that is what you are used to. Reply With Quote

6. Senior Member Join Date
Jan 2014
Posts
137
Rep Power
0

## Re: Simple Java program not working:

I got it working, thanks for the help everyone.

Any good recommendations of places to find fun programs besides like tic tac toe, etc.

I learn the best when I run into a problem. I have only been learning Java for 3 weeks but I am getting the hang of it pretty fast. Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
{"ft_lang_label":"__label__en","ft_lang_prob":0.718344,"math_prob":0.8262567,"size":5415,"snap":"2021-04-2021-17","text_gpt3_token_len":1527,"char_repetition_ratio":0.116799116,"word_repetition_ratio":0.31602708,"special_character_ratio":0.33407202,"punctuation_ratio":0.16524217,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95014876,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-01-25T08:02:31Z\",\"WARC-Record-ID\":\"<urn:uuid:3ffffc95-e15f-4b37-bba8-6132c41c242f>\",\"Content-Length\":\"64497\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2fdc5891-1f72-45c9-9999-b43166831b0a>\",\"WARC-Concurrent-To\":\"<urn:uuid:2102a5f2-b045-4d28-aba9-49aaabf961f6>\",\"WARC-IP-Address\":\"163.172.65.71\",\"WARC-Target-URI\":\"https://www.java-forums.org/new-java/86185-simple-java-program-not-working.html\",\"WARC-Payload-Digest\":\"sha1:I7NZAK67C57BXRNKNFGCS5Q2BFBHHVRL\",\"WARC-Block-Digest\":\"sha1:2WJTGKIRKJM2LOJKBWZSK7M6VPKFG37V\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-04/CC-MAIN-2021-04_segments_1610703565376.63_warc_CC-MAIN-20210125061144-20210125091144-00149.warc.gz\"}"}