TRENDING NEWS

POPULAR NEWS

I Have An Error While Doin My Computer Project Of Java Bluej . I Get Null During Output

How many types or kinds of errors can occur in a Java programming language, and how can we modify those errors?

There are five types of errors in java( first 3 are errors and last 2 are exceptions ):1. System ErrorsThese type of errors are system or platform related and generally occurs at console. e.g. classpath is not set.2. Syntax ErrorsThese types of error occurred due to incorrect grammar in the programming language.Common examples are:Misspelled variable and function namesMissing semicolonsImproperly matches parentheses, square brackets, and curly bracesIncorrect format in selection and loop statements3. Semantic ErrorsSemantic errors are compile time errors. The compiler will list the line number and even the word that is causing the issue. e.g. Not declaring an object properly. So if I run into this issue one of the best ways I can resolve this is consult the documentation and find out what the constructor has to say.4. Runtime errors:Runtime errors occur during the execution of program. These are also known as runtime exceptions. e.g. Accessing a file which is not present.5. Logical errors:Logic errors occur when there is a design flaw in your program. Common examples are:Multiplying when you should be dividingAdding when you should be subtractingOpening and using data from the wrong fileDisplaying the wrong messageFirst three are known as errors in java which cannot be handled during the execution during the program execution.Last two are exceptions which can be handled using try-catch[1] block.Footnotes[1] Java - Exceptions

Why am I getting array index out of bounds exception?

It is legal to have an array with size 'zero' in Java.Example :

int[ ] a = new int[0];
System.out.println(a[0]);

// Runtime Exception : ArrayIndexOutOfBoundsException: 0
But you will get runtime exception AIOBE. Know more - AlgoValley

Design a class named BankAccount in java to hold data for bank account?

If you do not know Java, you could start with the Java Tutorial here
http://java.sun.com/docs/books/tutorial/

Scroll down to Getting Started and click on the link.
Check out Learning the Java Language as well.

I will give you some basics, but not do the whole thing myself.

You need to create a class BankAccount

public class BankAccount{
...
}

Inside this class you need to add methods.
The constructor
public BankAccount(double balance, double interestRate) {
...
}
The deposit method
public void deposit(double amount) {
...
}
The withdrawal method
public void withdrawal(double amount) {
...
}
The calcInterest method
private void calcInterest() {
...
}
The monthlyProcess method
protected void monthlyProcess() {
...
}

Now create a SavingsAccount class
public class SavingsAccount extends BankAccount {
...
}
The constructor
public SavingsAccount(double balance, double interestRate) {
super(balance, interestRate);
...
}
The deposit method
public void deposit(double amount) {
...
}
The withdrawal method
public void withdrawal(double amount) {
...
}
The monthlyProcess method
protected void monthlyProcess() {
...
}

You will need some variables in both classes.
BankAccount:
private double balance = 0.0;
private int deposits = 0;
private int withdrawals = 0;
private double interestRate = ;
private double serviceCharge = 1;

SavingsAccount:
private double minBalance = 25;
private boolean active = false;

The Main class
public static void main(String[] args) {
...
}

Variables:
private SavingsAccount sAccount;

In the main method create a new SavingAccount

That is a brief description, and gives you a start on what you will have to learn to be able to understand it.

How do you play .Wav files in java?

I've found a lot of examples but none work. I'm using BlueJ. I am relatively new to Java and I need to learn how to add sound for our ShowCase Project.

BankAccount and SavingsAccount Classes?

The problem is how your creating a new instance of SavingsAccount, the syntax is:

ClassName objName = new ClassName();

Then objName will be a new instance of whatever ClassName is, also your passing in 2 strings as parameters for your constructor, if you look at the SavingsAccount class you'll see the constructor expects a String and an int i.e

SavingsAccount objName = new SavingsAccount("string", 2343);

Also, the methods your calling in main, numDeposit() for example, should be getNumDeposit()... and the last method your calling returns void...so it can't be used in a System.out.println() like that. I think it needs to be called outside of a print statement.

This works:

public static void main(String[] args) {
SavingsAccount account = new SavingsAccount("James Howard", 1289789);

System.out.println("Enter your account balance $:");
System.out.println("Enter the annual interest rate:");
System.out.println("Enter the number of withdrawals:");
System.out.println("Enter the number of deposits:");

System.out.println(account);
System.out.println("Account Balance $:" + account.getBalance());
System.out.println("Withdraw:" + account.getNumWithdrawals());
System.out.println("Deposit:" + account.getNumDeposits());
account.monthlyProcess();
}

http://ideone.com/8kEPOv

TRENDING NEWS