This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2016/12/9

reflection

1
2
3
danpost danpost

2016/12/12

#
divinity wrote...
hi danpost can u show me whay you mean because when I put it at line 4 am getting a major error
Replace lines 2 through 9 in your last class posting to this:
DecimalFormat df = new DecimalFormat("#.00");
Account[] acc = new Account[10];

public static void main(String[] args) {    
    createAccount();
}
danpost danpost

2016/12/12

#
You should probably remove the 'static' keyword throughout the class EXCEPT the 'main' method. Then, instead of 'createAccount();' in the main method use 'new ATM().createAccount();'
divinity divinity

2016/12/12

#
hi danpost, super_Hippo well I got the errors to be remove, by removing the static word in the public static void, and now I am having a new error here now the error msg is create a new field, create a class in ATM and create a new ATM in pacage
DecimalFormat df = new DecimalFormat("#.00");
         Account[] acc = new Account[10];
        public static void main(String[] args) {
              
              newATM.createAccount();(the error is under newATM)
    }
        public void newATMcreateAccount()
        {
            Scanner input = new Scanner(System.in);
            int i = 0; 
            double bal= 50.0;
danpost danpost

2016/12/12

#
Line 5 should have 'new ATM()' -- not 'newATM'; and line 7 should simply be 'public void createAccount()'.
divinity divinity

2016/12/12

#
hi danpost I remove the newATM from the constructor and put in the newATM() but the error still persist
danpost danpost

2016/12/12

#
divinity wrote...
I remove the newATM from the constructor and put in the newATM() but the error still persist
It is 'new ATM()' with a space between 'new' and 'ATM()'.
divinity divinity

2016/12/12

#
hi danpost i have done everything that you told me to do but for some I am not getting the desired result. what is there that is preventing it from getting this result below Example if id entered was 2 and a withdrawal of 30 was made then a deposit of 100, at the end of the program if balance was checked, it should reflect 120. because when i run the program, it is not reflecting the 120, I even change the amount to 100 from the 50 and still not getting the 120 in my first assignment and also in my second assignment( which, by the way) supposed to run the same way as assignment I, it is increasing the amount instead of decreasing, don't know what is the cause. The codes are the same for both assignment, can u take a look at it and explain to me why it is not reflect the required amount, is it something in my calculation and how can i fix it.
divinity divinity

2016/12/12

#
this my codes for the second assignment, I am only posting the main part only for now
ackage Project;

import java.text.DecimalFormat;
import java.util.Scanner;



public class ATM {
    DecimalFormat df = new DecimalFormat("#.00");
        Account[] acct = new Account[10];
        public static void main(String[] args) {
            //create account method 
            new ATM().createAccount();
    }
        public void createAccount()
        {
            Scanner input = new Scanner(System.in);
            int i=0; 
            final double bal = 50.0;
            //this account hold 10 account
            
            //creating a new person
            Person[] p = new Person[i++];
            
            //acquiring the user information
            for(i=0; i<acct.length; i++){
                System.out.println("Enter your first name");
                String fn = input.next();
                
                System.out.println("Enter your address");
                String a = input.next(); 
                
                System.out.println("Enter your contact");
                String c = input.next();            
                
                System.out.println("Enter the client number");
                int cn = input.nextInt(); 
                                
                //creating a new client each time the program runs
                Clients client = new Clients(fn,  a, c, cn);
                
                
                //asking the user to enter the type of account they want to utilize
                System.out.println("Welcome to the Account Type:\n  ");
                System.out.println("Please select from the following menu:\n");
                System.out.println("===================================");
                System.out.println("| Please select your account type |");
                System.out.println("===================================");
                System.out.println("| [\n1] Savings Account           |");
                System.out.println("| [\n2] Checking Account          |");
                System.out.println("| [\n3] CreditCard Account        |");
                System.out.println("===================================");      
                int acctType = input.nextInt();
               
                if(acctType == 1)
                {
                    acct[i] = new SavingsAccount(i, bal, client);
                }
                else if(acctType == 2)
                {
                    acct[i] = new CheckingAccount(i, bal, client);
                }
                else if(acctType == 3)
                {
                    acct[i] = new CreditCardAccount(i, bal, client);
                }
            }
            while(true)
            {
                System.out.println("Enter your account id");
                int id = input.nextInt();
                      //this  will let user break out of the loop to end the program
                      if(id == -1)
                      {
                          break;
                      }
                   //this loop indicate that the id should be between 1 - 9
                while(id < 0 || id > 9)
                {
                    //indicating to the user that the id enter is wrong and to try again
                    System.out.println("ID is incorect, try again");
                    id = input.nextInt();
                }
                //this while indicate whether the user enter the wrong id, given another chance to re-enter
                while(true)
                {
                    displayMenu();
                    
                    if(!useMenu(acct[id],input))
                    {
                        System.out.println();
                        break;
                    }
                    System.out.println("\n");
                }
            }
        }
        public boolean useMenu(Account acct, Scanner input)
        {
            int userchoice = input.nextInt();
            
            //everytime it runs it shall be false until it is true
            double amt=0;
            if(userchoice == 5)
            {
                return false;
            }
            else if(userchoice == 1)
            {
                //user checking their balances
                System.out.println("The account balance is: "+ acct.getbalance());
                return true;
            }
            else if(userchoice == 2)
            {
                //asking the user what amount to be withdrawn
                System.out.println("Enter the amount to withdraw");
                amt =input.nextDouble();//hold the amt to be withdrawn
                if(amt > acct.getbalance())//indicating if the amt withdrwn is over the limit
                {
                    //indicating that there is not enough funds in the account
                    System.out.println("Insufficient funds " + "Balance is "+acct.getbalance());
                }
                else
                {
                    //letting the user know that thre is enough in the account
                    acct.withdraw(amt);
                    //balance is printed out after transaction''''''''''''''''
                    System.out.println("Balance is: "+ acct.getbalance());
                }
            }
            else if(userchoice == 3)
            {
                //user is asked to enter the amount to be deposited
                System.out.println("Enter the amount to deposit");
                acct.deposit(input.nextDouble());//hold the amt deposited
                System.out.println("Balance is "+ acct.getbalance());//gathering the balance after the  transactions
                return true;
            }
            else if(userchoice == 4)
            {
                //gathering the user information 
                System.out.println(acct.getClient().toString());
            }
            else
            {
                //this indicated that the user enter a choice that is not there.
                System.out.println("invalid choice");
            }
            return true;
        }
        
        public static void displayMenu()
        {
            //displaying the menu where the user has to choose from
            System.out.println("Welcome to the Automated Teller Machine!\n");
            System.out.println("Select from the following menu options below:\n");
            System.out.println("===================================");
            System.out.println("|         Main Menu               |");
            System.out.println("===================================");
            System.out.println("| [1] Check Balance               |");
            System.out.println("| [2] Withdraw                    |");
            System.out.println("| [3] Deposit                     |");
            System.out.println("| [4] Display owner's Details     |");
            System.out.println("| [5] Exist                       |");
            System.out.println("Please select your choice now!!   |");
            System.out.println("====================================");
        }
}
Super_Hippo Super_Hippo

2016/12/12

#
Did you adjust the withdraw/deposit methods? Maybe show them again, the problem might sit there.
danpost danpost

2016/12/12

#
To double check your new balances, replace lines 73 through 76 with the following:
if (id == -1)
{
    System.out.println("\n\nID  BALANCE");
    for (int i=0; i<acc.length; i++)
    {
        System.out.println(" "+i+df.format(acc[i].getBalance()));
    }
    break;
}
Maybe the terminal printout will help in determining the exact cause of the problem.
divinity divinity

2016/12/12

#
hi super_hippo in the second assignment, the withdraw/deposit method supposed to be abstract and danpost I am going to try and do with u say
divinity divinity

2016/12/12

#
hey danpost this is the result when i add in what you have told me to. which is not suppose to happen and I still havent got it to work, to be able to get the 120 when i used the id 2
Select from the following menu option below:

===================================
|       Main Menu                 |
===================================
| [1] Check Balance               |
| [2] Withdraw                    |
| [3] Deposit                     |
| [4] Display User Information    |
| [5] Exist                       |
===================================
Please select your choice now!!
1
The account balance is: 50.0


Welcome to the Automated Teller Machine!

Select from the following menu option below:

===================================
|       Main Menu                 |
===================================
| [1] Check Balance               |
| [2] Withdraw                    |
| [3] Deposit                     |
| [4] Display User Information    |
| [5] Exist                       |
===================================
Please select your choice now!!
2
Enter the amount to withdraw
25
Balance is: 25.0


Welcome to the Automated Teller Machine!

Select from the following menu option below:

===================================
|       Main Menu                 |
===================================
| [1] Check Balance               |
| [2] Withdraw                    |
| [3] Deposit                     |
| [4] Display User Information    |
| [5] Exist                       |
===================================
Please select your choice now!!
3
Enter the amount to deposit
10
Balance is 35.0


Welcome to the Automated Teller Machine!

Select from the following menu option below:

===================================
|       Main Menu                 |
===================================
| [1] Check Balance               |
| [2] Withdraw                    |
| [3] Deposit                     |
| [4] Display User Information    |
| [5] Exist                       |
===================================
Please select your choice now!!
2
Enter the amount to withdraw
40
Insufficient amount  Balance is: 35.0


Welcome to the Automated Teller Machine!

Select from the following menu option below:

===================================
|       Main Menu                 |
===================================
| [1] Check Balance               |
| [2] Withdraw                    |
| [3] Deposit                     |
| [4] Display User Information    |
| [5] Exist                       |
===================================
Please select your choice now!!
4

First Name sallann 
Last Name fieldson 
Address maraval 
Contact 7226585


Welcome to the Automated Teller Machine!

Select from the following menu option below:

===================================
|       Main Menu                 |
===================================
| [1] Check Balance               |
| [2] Withdraw                    |
| [3] Deposit                     |
| [4] Display User Information    |
| [5] Exist                       |
===================================
Please select your choice now!!
2
Enter the amount to withdraw
30
Balance is: 5.0


Welcome to the Automated Teller Machine!

Select from the following menu option below:

===================================
|       Main Menu                 |
===================================
| [1] Check Balance               |
| [2] Withdraw                    |
| [3] Deposit                     |
| [4] Display User Information    |
| [5] Exist                       |
===================================
Please select your choice now!!
3
Enter the amount to deposit
100
Balance is 105.0


Welcome to the Automated Teller Machine!

Select from the following menu option below:

===================================
|       Main Menu                 |
===================================
| [1] Check Balance               |
| [2] Withdraw                    |
| [3] Deposit                     |
| [4] Display User Information    |
| [5] Exist                       |
===================================
Please select your choice now!!
5

Enter your account ID
-1


ID Balance
 050.00
 150.00
 2105.00
 350.00
 450.00
 550.00
 650.00
 750.00
 850.00
 950.00
BUILD SUCCESSFUL (total time: 5 minutes 12 seconds)
danpost danpost

2016/12/12

#
The output might be a little confusing as I forgot the separation between the IDs and the balances -- the first digit in each line is the ID number. All ending balances were $50.00 except for account with ID of 2, of which the ending balance was $105.00 (which was the correct amount).
danpost danpost

2016/12/12

#
If you are worried about the ending balance not being $120.00, then don't. The assignment said nothing about withdrawing $25.00 and depositing $10.00 (which drops the balance by $15.00). That is why you came up with $105.00 instead of $120.00.
divinity divinity

2016/12/12

#
yeah okay danpost how do I get rid of this. I need to remove that, cant let the lecture see dah, that is marks taken out, want every possible marks for this and the second one also
ID Balance
 050.00
 150.00
 2105.00
 350.00
 450.00
 550.00
 650.00
 750.00
 850.00
 950.00
There are more replies on the next page.
1
2
3