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

2016/5/10

cant find my last post

1
2
divinity divinity

2016/5/10

#
hi danpost i cant find my last post was it deleted.
danpost danpost

2016/5/11

#
divinity wrote...
hi danpost i cant find my last post was it deleted.
It is here.
divinity divinity

2016/5/11

#
hi dan since i cant seem to find it, i will use here. it is about the same banking program. I have one problem with the password. When the user enter the wrong password, the user is given the opportunity to re-enter the password at least once, daiz how i set it to be but when the user enter the correct password why does it say to re-enter your password,, when the user enter the correct password it should be able to go on to ask for the user first name, last name and id and the rest of the program. how do i get it to read it like that. I have a method called printReport where at the end of the program it should print out the customer first and last name, id number, customer initial account balance, and customer current account balance after all the other operation performed. this program is a banking system where the customers supposed to either deposit, withdraw and print out the customer balance. can you tell me how to go about getting this progrm to run the correct way. this below here is the codes that i have for the program.
 public static double withdraw(double amount)
    {
        double current_bal=0;
        
        current_bal = current_bal - amount;
       
        return current_bal;
    }
    public static double deposit(double amount)
    {
        double current_bal=0, deposit_amt = 0;
        
        deposit_amt = deposit_amt + current_bal;
        
        return deposit_amt;
    }
    public static void printReport( )
    {
        
    }

    
    public static void main(String[] args) 
    {
        Scanner userin = new Scanner(System.in);
        
        
        int pin = 1234;
        int option;
        double amt=0,w,d;
        
        
        double withdrawal,  currentBalance=0, deposits, balance=0, 
                 initialacct_bal;
        char acct_type = 's';
        int i=0, operation_code=0,operation_menu=0;
        
        
        while(i<2)
        {
            System.out.println("please enter your 4 digit pin number");
            pin = userin.nextInt();
           
            if(pin != 1234)
            {
                System.out.println("incorrect pin, please re-enter your pin");
                
            }
            else if(pin == 1234)
            {
                System.out.println("you can now start with your transaction");
            }
            do
           {
                   System.out.println("please re-enter your pin");
                   pin = userin.nextInt();
               
           }while(pin != 1234);
            
            System.out.println("please enter the customer first name");
            String customer_firstname = userin.next();
            
            System.out.println("please enter the customer last name");
            String customer_lastname = userin.next();
             
            System.out.println("please enter customer ID");
            String customer_ID = userin.next();
            
            System.out.println("Account type menu");
            System.out.println("S:Saving Accounts");
            System.out.println("C:Checking Accounts");
            option = userin.next().charAt(0);
           
            System.out.println("please enter initial account balance");
            initialacct_bal = userin.nextDouble();
            
            System.out.println("what operation would you like to perform");
            String operation = userin.next();
            
            System.out.println("what operation do you wish to perform");
            System.out.println("1: deposit");
            System.out.println("2: withdraw");
            System.out.println("3:exit and balance" + balance);
            option = userin.next().charAt(0);
            
            while(operation_code == 1)
            {
                System.out.println("enter money to be deposit");
                deposits = userin.nextDouble();

                d = deposit(amt);

                System.out.println("$ "+ amt +" has been deposited "+ "Account blance is "+ balance);
                i++;
            }
            
            while(operation_code == 2)
            {
                System.out.println("please enter the amount of money to withdraw");
                withdrawal = userin.nextDouble();
            
                if(withdrawal == currentBalance)
                {
                    w = withdraw(amt);
                    System.out.println("$ "+amt +" has been withdrawwn"+ " available balance is "+balance);
                }
                else if(withdrawal > currentBalance)
                {
                    System.out.println("The amount you are trying to withdraw exceed your current overdraft limit");
                    i++;
                }
                System.out.println("exist "+" account balance is "+balance);
            }
                 
            while(operation_menu < -3)
            {
                msg = printReport();
                
            }
        }
this here below is how the program should run. this is the required output on how the program should output EXAMPLE 1 Enter Customer Name: Shantelle Roberts Enter Customer ID : RBC000136 Account Type Menu : S: Savings Account C: Chequing Account Enter Account Type Code: S Enter initial Account Balance: 1200 What Operation do you want to perform? 1: Deposit 2: Withdraw 3: Exit and print Balance Enter an operation code: 1 Enter the amount that you want to deposit to your account: 500 What Operation do you want to perform? 1: Deposit 2: Withdraw 3: Exit and print Balance Enter an operation code: 2 Enter the amount that you want to withdraw from your account: 350 What Operation do you want to perform? 1: Deposit 2: Withdraw 3: Exit and print Balance Enter an operation code:: 3 Customer Name : Shantelle Roberts Customer ID: RBC000136 Account Type: Savings Initial Balance: $1200 Current Balance:$1350
divinity divinity

2016/5/11

#
hi dan i forgot to mention, i have a method called printReport, i am little confused as to what to put as the statement and what to put inside of the parameter list. can u tell me it is empty at the moment
divinity divinity

2016/5/11

#
hi danpost when i ran the program this is the output am getting which is not supposed to be
please enter your 4 digit pin number
1247
incorrect pin, please re-enter your pin
please re-enter your pin
1234
please enter the customer first name
shantelle
please enter the customer last name
roberts
please enter customer ID
RBC0000136
Account type menu
S:Saving Accounts
C:Checking Accounts
5
please enter initial account balance
1200
what operation would you like to perform
1
what operation do you wish to perform
1: deposit
2: withdraw
3:exit and balance0.0
deposit
please enter your 4 digit pin number
BUILD STOPPED (total time: 2 minutes 17 seconds)
danpost danpost

2016/5/11

#
It looks like 'i' is counting the number of operations performed by the customer and not controlling the number of attempts at entering the correct pin number (you are incrementing 'i' after a deposit and after a withdrawal). Now, since the main 'while' loop is limited to two passes, this will allow at maximum two single transaction cycles for the program. That could be by two different customers or by the same customer who would have to enter their information in twice (pin and all). I would first have the limit of 2 put on just that code where the pin number is being acquired and use a separate 'while' loop for the actions on a specific account. Its limit can be the condition that the operation number is not 3 (exit and balance). Currently, the only way to smoothly exit the program is to perform two transactions. There should probably be another way to terminate the program. Maybe have a pin number of zero entered stop the program. Then, you can have everything enclosed in a 'do' loop to allow any number of customers.
divinity divinity

2016/5/16

#
hi danpost i just want to let you know that I got the same program above fix, and i have deleted the part with the password, i decided to give the lecturer the specification that he asked for not what i wanted to put in myself which I thought would have enhanced the program. I have another question for you. I am on my final project for this semester which have to be handed in this week. i have to hand in this week. my game is a multiple choice math game. i build the game but it have logical errors in it. there is a part of the game that say you have to randomized the answers where it doesn't always be the same letter and i have no idea how to go about in doing that can you show me how. there logical errors that i am experience in the game goes as follows: the age limit for the game is from8 -13 but when the user enter the age 13 the game end. which is not supposed to do., as long it dont go beyond the require age the user is eligible to play. so at the age of 13 the user should be able to play but the game end when the user enter the age 13 when the game reach round 2, if the player answers incorrectly it supposed to remain on the same question until the user get it correct or otherwise the game end. they have four chances to do that. if the user answer incorrectly it does repeat for times but it donot come out of the loop it keep looping. and it doesn't goes onto the third round. and it also adding an extra round which is not supposed to do. this is the part of the game where it say the answer have to be randomized. Note, the order in which the correct answer appears and the incorrect number option must be randomized. round 1 - 4 levels - from 1 -4 round 2 - 4 levels - from 5 - 8 round 3 - 2 levels - from 9 -10 am getting an extra round have no idea why and it stop at round 2 doesnt goes into round 3 at all. here is the codes . any help would be much appreciated. here are the codes
if(playerage < 8)
        {
            System.out.println(playername+" you are too young for this game");
            System.out.println(playername+" come back when you are a bit older bye!!! ");
            System.exit(0);
        }
        else if(playerage > 13)
        {
            System.out.println(playername+" you are too old for this game");
            System.out.println(playername+" you have a bless day goodbye!!!!!");
            System.exit(0);
        }
        else if(playerage > 8 && playerage < 13)// start of round 1
        {
            System.out.println("\n*********************welcome to the addition round: round 1");
            
            //indicationg to the user what level and round she will be starting from
            
            while (i < 4 && wrongcount < 4)
            {
                i++;
                //getting the random numbers
                intvalue  = 1 + randobj.nextInt(25);
                intvalue2 = 1 + randobj.nextInt(9);
                correct_ans = intvalue + intvalue2;
                incorrect_ans = 1 + randobj.nextInt(35);
                
                while(correct_ans == incorrect_ans)//this indicating if the random happen to drop to same numbers for the correct and incorrect answer
                {
                    incorrect_ans = 1 + randobj.nextInt(35);
                }
                
                System.out.println(playername+" you are on round 1 "+ " level "+ i);
                System.out.println(playername+" please match the answer with the corresponding letter");
                
                
                System.out.println(playername +" please add "+ intvalue + " + "+ intvalue2);
                System.out.println("A:"+correct_ans);
                System.out.println("B:"+incorrect_ans);
                uSelect = reader.next().charAt(0);
                
                
                if(uSelect == 'A' || uSelect == 'a')
                {
                    System.out.println(playername+" great job, answer is correct keep up the good work");
                    totalscore += 350;
                    System.out.println("round 1");
                    System.out.println("level "+ i);
                    totalscore +=score;
                    System.out.println(" total score is: "+totalscore);
                }
                else
                {
                    while(uSelect !='A' && uSelect !='a' &&  wrongcount < 4)
                    {
                        System.out.println(playername+" okay let me catch my breath here, answer is wrong, try again");
                        totalscore -=175;
                        System.out.println("round 1");
                        System.out.println("level:"+ i);
                        totalscore -=score;
                        System.out.println("total score is: "+totalscore);
                        wrongcount++;
                        
                        while(wrongcount < 4)
                        {
                            i++;
                            System.out.println(playername+" you are still on round 1 "+ " level "+ i);
                            System.out.println(playername+" please match the answer with the corresponding letter");

                             while( intvalue2 == 0)
                            {
                                incorrect_ans = i + randobj.nextInt(35);
                            }
                            System.out.println(playername+"  please add "+ intvalue + " + "+intvalue2);
                            System.out.println("A:"+correct_ans);
                            System.out.println("B:"+incorrect_ans);
                            uSelect = reader.next().charAt(0);
                            wrongcount++;
                        }
                    }
                }
            }
            
            System.out.println("\n**********welcome come to the subtraction round:***round 2*********");
            
            while(i >= 4 && i <=8 && wrongcount < 4)
            {
                i++;
                //get random numbers
                largest  = 1 + randobj.nextInt(25);
                smallest = 1 + randobj.nextInt(9);
                correct_ans = largest - smallest;
                incorrect_ans = 1 + randobj.nextInt(35);
                
                while(correct_ans == incorrect_ans)
                {
                    incorrect_ans = 1 + randobj.nextInt(35);
                }
                if(i == 1)
                {
                    //get the largest and smallest number
                    largest = numvalue;
                    smallest = numvalue2;
                }
                else
                {
                    if(numvalue > largest)
                    {
                        largest = numvalue;
                    }
                    if(numvalue2 > smallest)
                    {
                        smallest = numvalue2;
                    }
                }
                //indicting the user what level and round they are on
                System.out.println(playername+" you are on round 2 "+ " level "+ i);
                System.out.println(playername+" choose the correct answer with the corresponding letter");
                
                while(smallest == 0)
                {
                   smallest = 1 + randobj.nextInt(35);
                }
                
                System.out.println(playername+" please subtract "+ largest+ " - "+ smallest);
                System.out.println("A:"+correct_ans);
                System.out.println("B:"+incorrect_ans);
                uSelect = reader.next().charAt(0);
                
                if(uSelect == 'A' || uSelect == 'a' )
                {
                    System.out.println(playername+" well done kiddo!!!!!!!! you are so right, keep it up");
                    totalscore +=350;
                    System.out.println("round 1");
                    System.out.println("level "+ i);
                    totalscore+=score;
                    System.out.println("total score "+ totalscore);
                }
                else
                {
                    while(uSelect != 'A' && uSelect != 'a' &&  wrongcount < 4)
                    {
                        
                        System.out.println(playername+" Boo-ya boo-hoo you are wrong, please try again");
                        totalscore +=350;
                        System.out.println("round 1");
                        System.out.println("level "+ i);
                        totalscore-=score;
                        System.out.println("total score is "+totalscore);
                        wrongcount++;
                        
                        if(wrongcount == 4)
                        {
                            break;
                        }
                        
                        while(wrongcount < 4)
                        {
                            
                            System.out.println(playername+" you are still on round 2");
                            System.out.println(playername+" please match the correct answer with the corresponding letter");

                            
                            System.out.println(playername+" please subtract "+largest+ " - "+smallest);
                            System.out.println("A:"+correct_ans);
                            System.out.println("B:"+incorrect_ans);
                            uSelect = reader.next().charAt(0);
                            wrongcount++;
                        }
                    }
                }
            }
            System.out.println("\n**************welcome to the division round: round 3***********************");
            
            while(i >=8 && i <=10 && wrongcount < 4)
            {
                i++;
                //get the random numbers
                numerator = 1 + randobj.nextInt(25);
                denominator = 2 + randobj.nextInt(9);
                
                while(denominator == 0)
                {
                    denominator = 2 + randobj.nextInt(9);
                }
                rand1 = 1 + randobj.nextInt(25);
                rand2 = 2 + randobj.nextInt(9);
                correct_ans = numerator = denominator * 2;
                correct_ans = numerator / denominator;
                incorrect_ans = 1 + randobj.nextInt(35);
                
                while(correct_ans == incorrect_ans)
                {
                   incorrect_ans = 1 + randobj.nextInt(35);
                }
                System.out.println(playername+" you are on round 3 "+ " level "+ i);
                System.out.println(playername+" match the correct answer with the corresponding letter");

                
                System.out.println(playername+" please divide "+ numerator+ " / "+denominator);
                System.out.println("A:"+incorrect_ans);
                System.out.println("B:"+correct_ans);
                uSelect = reader.next().charAt(0);
                
                if(uSelect == 'A' || uSelect == 'a')
                {
                    System.out.println(playername+"yayyyyy well done kiddoo!!! you are on the right track, keep it up");
                    totalscore += 350;
                    System.out.println("round 1");
                    System.out.println("level "+i);
                    totalscore += score;
                    System.out.println("total score is: "+totalscore);
                }
                else 
                {
                    while(uSelect != 'A' && uSelect != 'a' && wrongcount < 4)
                    {
                        
                        System.out.println(playername+" awwww come on you can do better than that, incorrect answer again, try again");
                        totalscore -= 175;
                        System.out.println("round 3 ");
                        System.out.println("level "+ i);
                        totalscore -= score;
                        System.out.println("total score is: "+totalscore);
                        wrongcount++;
                        
                        while(wrongcount < 4)
                        {
                           i++;
                           System.out.println(playername+"okay let me take a deep breath here, that is not the correct answer, please try again");
                           totalscore -=175;
                           System.out.println("round:3");
                           System.out.println("level:"+ i);
                           totalscore-= score;
                           System.out.println("total score is: "+ totalscore);
                           wrongcount++;
                        }
                    }
                }
            }                          
        }
        else
        {
            System.out.println(playername+" you have entered an invalid character");
            System.exit(0);
        }
        System.out.println("the winner is "+playername);
        System.out.println("total score is "+totalscore);
        System.out.println("the level the player was on is "+ " level "+ i);
        System.out.println("number of chances left is "+wrongcount);
    }
    
danpost danpost

2016/5/16

#
divinity wrote...
the age limit for the game is from8 -13 but when the user enter the age 13 the game end. which is not supposed to do., as long it dont go beyond the require age the user is eligible to play. so at the age of 13 the user should be able to play but the game end when the user enter the age 13
Currently, line 13 limits the age to between 9 and 12, inclusive. The age limit was already set to between 8 and 13 before that line. Remove line 13, as well as line 14 and 241 -- then, auto-indent.
when the game reach round 2, if the player answers incorrectly it supposed to remain on the same question until the user get it correct or otherwise the game end. they have four chances to do that. if the user answer incorrectly it does repeat for times but it donot come out of the loop it keep looping. and it doesn't goes onto the third round.
The condition on line 86 is also incorrect for what you want. You want to include '4', but NOT '8'. You do not appear to have any code that prints a message that four incorrect answer have been given and ending the game. It might be best to create a method for incrementing 'wrongcount' and checking its value to exit the program. That way, you can remove it as a condition in the while loops and ensure that anywhere when its value becomes '4', the game will end:
private void bumpWrongCount()
{
    wrongcount++;
    if (wrongcount == 4)
    {
        System.out.println("You have answered wrong too many times.  Game Over!"
        System.exit(0);
    }
}
Then anywhere you have 'wrongcount++;' in the code you have given above, change it to 'bumpWrongCount();'.
danpost danpost

2016/5/16

#
I have edited my last post to include more stuff. To randomize the options would take a lot of changes. Too much to easily explain. Basically, you would have to always have the correct answer as 'A' or 'a' to begin with and declare a new variable to hold that value. Then, on a 50:50 random chance, switch the options and set the variable to the other value ('B' or 'b'). Of course, with you having already named the variables that hold the options 'correct_ans' an 'wrong_ans', this may not go over too well (although it would still work). You could create alternate variables for the options:
char correct_response = 'A';
int option1 = correct_ans;
int option2 = incorrect_ans;
if (randObj.nextInt(2) == 1)
{
    int hold = option2:
    option2 = option1;
    option1 = hold;
    correct_response = 'B';
}
Then, you would print the options ('option1' and 'option2'), get and test the response (comparing input to 'correct_response') and proceed from there.
danpost danpost

2016/5/16

#
You may have to manipulate the input before comparing with the correct response:
if (Character.toUpperCase(uSelect) == correct_response)
divinity divinity

2016/5/17

#
private void bumpWrongCount() how do I used that because I am getting a syntax error. telling me illegal start of a statement. how do i implement it without the syntax error, is that belong to object oriented programming
danpost danpost

2016/5/17

#
You maybe did one of three things: (1) placed the method 'bumpWrongCount' inside another method; (2) placed the method totally outside the class; or (3) somehow removed or added a bracket unintentionally; For assistance, you will have to post the entire class code where you placed the method.
divinity divinity

2016/5/17

#
this program am building here is not an object oriented program danpost, this is programming 1, I havent moved to object oriented programming as yet.
divinity divinity

2016/5/17

#
this is just a simple command line programming math final project am doing
danpost danpost

2016/5/17

#
divinity wrote...
this is just a simple command line programming math final project am doing
Oh, I see. Then you cannot add the method as I suggested. You need to replace 'wrongcount++' everywhere in your code with the code I placed within that method.
There are more replies on the next page.
1
2