Java How to programm Deitel Book exercise 6.35 -


i've been studying deitel's book(java how program) , want solve exercise 6.35. here's asks:

write program assist student learn multiplication.use random object produce 2 positive integers (one digit each). program should show on screen this:("how 7 times 3")

then student should insert answer , program controls if answer correct or wrong.if it's correct program continue asking question,else program waits until student answer correct.for every new question must new method created(this method should called once when application starts , when user answers correct question).

how do this?

//i have problem inside do-while block!

      package multiplication; import java.util.random; import java.util.scanner;  /*hey again! i've been trying solve problem using netbeans environment  *  */   public class ypologismos {     private int p;     private int a,b;      public ypologismos(int a,int b,int p)     {         this.a=a;         this.b=b;         this.p=p;      }    public ypologismos()  {    }        public void screen()  {      system.out.println("wrong answer ....please retry");  }           public void askfornumbers()     {         random r=new random();          int a,b;         a=r.nextint(10);         b=r.nextint(10);         int p;//p=product         p=(a*b);         system.out.println("how is:"+" "+a+" "+"times"+" "+b+" "+"?");          system.out.println("please insert answer!");         scanner s=new scanner(system.in);        int ans;//ans=answer        ans=s.nextint();                {            while(ans==p){                 system.out.println("well done!");                askfornumbers();            }         }while(ans!=p);       }       } 

//and main class ...

package multiplication;   public class main {       public static void main(string[] args)     {          ypologismos application=new ypologismos();          application.askfornumbers();       }  } 

make terse story book of how it.

teach multiplication:     repeat // solving problems        int first number = random        int second number = random        int product = first number * second number        repeat            int answer = ask how first number times second number            if answer != product                error!        until answer == product        solved! 

the above first idea, not following requirements. clears loop comes in loop , on.


reading extended question

public class ypologismos {      /** entry point application. */     public static void main(string[] args) {         ypologismos application = new ypologismos();         application.teachmultiplication();     }      private void teachmultiplication() {         while (wantsaproblem()) {              askaproblem();         }     }      private void askaproblem() {         int αλφα = random.nextint(10);         int βητα = random.nextint(10);         ...     } } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -