الموضوع: lab sheet 6
عرض مشاركة واحدة
منتديات طلاب وطالبات جامعة الملك عبد العزيز منتديات طلاب وطالبات جامعة الملك عبد العزيز
قديم 23-12-2011, 02:52 PM   #42

الماسة 6

جامعي

 
تاريخ التسجيل: Dec 2011
التخصص: حاسب
نوع الدراسة: إنتظام
المستوى: الثالث
الجنس: أنثى
المشاركات: 95
افتراضي رد: lab sheet 6

1 // Lab 3: Multiply.java
2 // Program generates single digit multiplication problems
3 import java.util.*;
4
5 public class MultiplyTest
6 {
7 public static void main( String args[] )
8 {
9
quiz();
11 } // end main
12
13 // ask the user to answer multiplication problems
14 public void quiz()
15 {
16 Scanner input = new Scanner( System.in );
17
18 int guess; // the user's guess
19 int answer; // the correct answer

20 /* write code to call method createQuestion to display the question and return the correct answer */
21
22 System.out.println( "Enter your answer (-1 to exit):" );
23 guess = input.nextInt();
24
25 while ( guess != -1 )
26 {
27 /* write code to call the method checkResponse to check the user's answer and return the result */
/* if checkResponse is true, write code to call method createQuestion to display the question and return the correct answer */
28
29 System.out.println( "Enter your answer (-1 to exit):" );
30 guess = input.nextInt();
31 } // end while
32 } // end method
33
34 // prints a new question and returns the corresponding answer
35 /* write method header for the createQuestion method */
36 {
37 // get two random numbers between 0 and 9
38 /* Write code to get two random numbers and store them in variables digit1 and digit2. */
39 /* Write code to multiply the two variables and store the result
40 in the return variable */
41 System.out.printf( "How much is %d times %d?\n", digit1, digit2 );
42 } // end method createQuestion
43
44 // checks if the user answered correctly and return the result of the comparison as a boolean variable
45 /* Write method header for checkResponse */
46 {
boolean correct; // true when the answer is correct
47 /* Write code to test whether the answer is incorrect */
48 /* Write code to tell the user to try again, if the answer is incorrect and set the Boolean variable */
49 else
50 {
51 System.out.println( "Very Good!" );
52 /* Write code to call method createQuestion to display another question */
53 } // end else
54 } // end method checkResponse
55 } // end class MultiplyTest
وكمان دا السوال عقدني
تكفون بكرة الامتحان

 

الماسة 6 غير متواجد حالياً   رد مع اقتباس