PokerDegenerate
Daemon Poster
- Messages
- 1,465
OK I am learning Java and am stuck...
Here is the problem...
create a class named CheckingAccount with data fields for an account number and a balance. Include a constructor that takes arguments for each field. The constructor sets the balance to 0 if it is below the required 200.00 mininum for an account. Also include a method that displays account details, including an explanation if the balance was reduced to 0. Write an application named TestCheckingAccount in which you instantiate two CheckingAccount objects, prompt the user for values for the account number and balance, and display the values of both accounts.
OK first here is what I have for the constructors Please tell me if they are correct it compiles but I am not sure if they are correct for the question.
If this is good I am stuck on how to write the application to instantiate the objects.
I have this but I can't seem to get it right no matter what I add or change:
EDIT*** sorry for the lack of whitespace I don't know how to put code up with whitespace....
Here is the problem...
create a class named CheckingAccount with data fields for an account number and a balance. Include a constructor that takes arguments for each field. The constructor sets the balance to 0 if it is below the required 200.00 mininum for an account. Also include a method that displays account details, including an explanation if the balance was reduced to 0. Write an application named TestCheckingAccount in which you instantiate two CheckingAccount objects, prompt the user for values for the account number and balance, and display the values of both accounts.
OK first here is what I have for the constructors Please tell me if they are correct it compiles but I am not sure if they are correct for the question.
public class CheckingAccount
{
private int accountNumber;
private double balance;
public int getNumber()
{
return accountNumber;
}
public double getbalance()
{
return balance;
}
public void setNumber(int accountNmb)
{
accountNumber = accountNmb;
}
public void setBalance(double blnce)
{
if(balance < 200.0)
blnce = 0;
else
balance = blnce;
}
public void display()
{
if(balance == 0)
System.out.println("If you have less than $200.00 in your account the balance is set to zero");
else
System.out.println("The balance for account number " + accountNumber + " is " + balance);
}
}
If this is good I am stuck on how to write the application to instantiate the objects.
I have this but I can't seem to get it right no matter what I add or change:
import java.util.Scanner;
public class testCheckingAccount
{
public static void main(String[] args)
{
int accountNmb;
double blnce;
CheckingAccount CustomerAccount1 = new CheckingAccount();
CheckingAccount CustomerAccount2 = new CheckingAccount();
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter your account number");
accountNmb = keyboard.nextInt();
keyboard.nextLine();
System.out.println("Please enter your account number");
blnce = keyboard.nextDouble();
}
EDIT*** sorry for the lack of whitespace I don't know how to put code up with whitespace....