• 30-10-2009, 01:58:41
    #1
    Oncelikle merhaba herkese.

    henuz java ya yeni adim attim.sinifta bu hafta yaptigimiz calismada bazi ufak sorunlar var.artik ufakmidir buyukmudur orasi tartisilir:}

    programin ozellikleri asagidakidadir.

    1) sayi tahmin etme programi

    2) kullanici maximum bir sayi sececek ve program 1 ile kullanicinin sectigi maximum sayi arasindan sayi tutacak.

    3) daha sonra kullanici aklindaki sayiyi girecek.eger sayi programin olusturdugu sayidan buyukse "too high", kucukse "too low" tarzinda kullaniciyi bilgilendirecek.

    4) kullanici random sayiyi bulduktan sonra.program kullanicinin sayiyi bulmak icin kac defa tahmin ettigini gosterecek.

    5) Ve son olarak program kullaniciya soru soracak.tekrar oynamak istermisiniz?

    kullanici 'y' basarsa tekrardan program baslayacak.'n'basarsa program kapanacak.


    not: 4. ve 5.siklarda sorun yasiyorum. kendi kodlarimi paylasiyorum.suan icin 2 class var.


    metotlar icin olan sinif asagidadir.

    /**
     * This is the class description that has method names printguestion and testcondition
     * @author Diyar Polat
     *
     */
    import java.util.Random;
    import java.util.Scanner;
    
    
    class Game {
        private int randomNumber; // random number that will be created
        private int guessedNumber; // number that we guess
        private int maxNumber; // maximum number sets 1 to max
        
        /* Prints question*/
        public void printQuestion()
        {
            System.out.println("We are going to play a number guessing game.");
            System.out.println("You are going to guess a number between 1 and what number?");
        }
        
        /* Test the condition if the user enters to high or too low */
        public void testCondition()
        {
            Scanner input = new Scanner(System.in);
            maxNumber = input.nextInt(); // number that you guessed
            System.out.println("Type a number between 1 and " + maxNumber);
            Random r = new Random(); //Creates random object
            randomNumber = r.nextInt(maxNumber);
            
            while(guessedNumber != randomNumber){
                guessedNumber = input.nextInt();
                if (guessedNumber < randomNumber)
                    System.out.println("Too low. Try again: ");
                if (guessedNumber > randomNumber)
                    System.out.println("Too high. Try again:");
                if (guessedNumber == randomNumber)
                    System.out.println("Right: You got it");
                
            }
            
        }
        
    }
    metotlari test eden sinif asagidadir.

    /**
     * This program creates random number and let asks user to guess a number
     * @author Diyar Polat
     *
     */
    import java.util.*;
    public class GameTest {
        public static void main(String[] args) {
            String playAgain; // variable name
            Scanner input = new Scanner(System.in); // Gets the input from user
            Game myGame = new Game(); //Creates mygame object
            myGame.printQuestion(); //calls printquestion method
            myGame.testCondition(); // calls testCondition method
            System.out.println("Would you like to play again?");
            
            /* The loop body */
            do {
                playAgain = input.next();
                Game myotherGame = new Game();
                myotherGame.printQuestion();
                myotherGame.testCondition();
                System.out.println("Would you like to play again?");
                playAgain = input.next();
            } while (playAgain == "y" || playAgain == "Y");
            
        }
    }        
    
    /*
    
    We are going to play a number guessing game.
    You are going to guess a number between 1 and what number?
    70
    Type a number between 1 and 70
    56
    Too low. Try again:
    65
    Too high. Try again:
    60
    Too low. Try again:
    63
    Too high. Try again:
    62
    Too high. Try again:
    61
    Right: You got it
    Would you like to play again?
    y
    We are going to play a number guessing game.
    You are going to guess a number between 1 and what number?
    
    */
    Programdaki sorunlara gelince tekrar oynamak istermisiniz?(would you like to play again?) sorusunda kullanici 'y' girerse tekrardan basliyor program fakat bir daha ayni islemi yapmiyor.

    yani..

    Alıntı
    Dogru tahmin! It took you 2 tries.
    Tekrar oynamak istermisiniz? y
    yukarakini yapamiyorum
  • 30-10-2009, 01:59:13
    #2
    soruyu tam cevirememis olabilirim. sorunun orijinalini veriyorum ve icerisinde ornek ciktilarda mevcut.


    Write a Java program that plays a number guessing game with the user. Your program asks the user to set the high end of the range, and then your program gets a secret random number inside the range. The user then repeatedly guesses what random number your program has, until she gets it right. Your program gives her hints along the way: "Too high." or "Too low".

    Below is a sample output from one run of the program. Your output has to match this one exactly, except of course that the answer that your Random object chooses will be different. User input is big and bold.


    We are going to play a number guessing game.
    You are going to guess a number between 1 and what number? 10
    Type a number between 1 and 10: 5
    Too high. Try again: 3
    Too high. Try again: 2
    RIGHT! It took you 2 tries.
    Would you like to play again? y

    You are going to guess a number between 1 and what number? 20
    Type a number between 1 and 20: 10
    Too high. Try again: 5
    Too high. Try again: 3
    Too high. Try again: 2
    RIGHT! It took you 3 tries.
    Would you like to play again? n

    If you study the run above, you will see that the user gets to play the game as many times as she wants, and each time she plays the game, she:
    • chooses the high value in the range that she will be guessing.
    • is allowed as many tries as needed to guess the correct random number.
    • gets feedback that helps her by telling her if her previous guess was too high or too low.
    • is shown how many tries it took her to get the right answer in the end.

    You must have a class Game, that represents one play of the Game. That is, one object represents one play of the game, which keeps track of one randomly generated number in a range, and one play with the user; this one play of the game allows the user as many tries as necessary to guess that random number.

    You must also have a second class called Main that repeatedly asks the user if she wants to play (again).
  • 30-10-2009, 02:10:25
    #3
    Deitelin kitabı sanırım.
    Yukarıda 2 kutu varya kodları yazdığın ilk kutuda randomun altında int bir değişken tanımla ve while döngüsüne girmeden 0 tanımla while içinde ise too low ve too high yazdırıyorsunya onun altına bu değişkeni artıran ifadeyi koy degisken_adi++; şeklinde
    right you got it altına ise
    degisken_adi++; ve print (degisken_adi ) de.
  • 30-10-2009, 22:39:41
    #4
    Başlığı görünce merakla içeri girdim ama görünce hayal kırıklığına uğradım.
    Babayiğit ölçmedeki kıstasın bu saçma programsa vay haline.
  • 31-10-2009, 19:27:07
    #5
    sacma olan sensin.sacma olmasan bos bos yorum yazmassin.bos bos konusma gozunu sevem...