Created
May 18, 2018 14:47
-
-
Save edenizk/b018e711d2fe3bf215b25d568a56ab8d to your computer and use it in GitHub Desktop.
mixer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.deniz.puzzle_game; | |
public class CompanyAndDevice { | |
private final String COMPANY_NAME; | |
private final String COMPANY_DEVICE; | |
public CompanyAndDevice(String COMPANY_NAME,String COMPANY_DEVICE){ | |
this.COMPANY_NAME = COMPANY_NAME; | |
this.COMPANY_DEVICE = COMPANY_DEVICE; | |
} | |
@Override | |
public String toString(){ | |
return " " + COMPANY_DEVICE + " From " + COMPANY_NAME + " Company \n\n\n"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.deniz.puzzle_game; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.widget.EditText; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
EditText edtPuzzle = (EditText) findViewById(R.id.edtPuzzle); | |
String oldEdtPuzzleValue; | |
Puzzle myPuzzle = new Puzzle(); | |
myPuzzle.letsShuffleTheDevices(); | |
for(int i = 0; i < 60; i++){ | |
oldEdtPuzzleValue = edtPuzzle.getText().toString(); | |
edtPuzzle.setText(oldEdtPuzzleValue + myPuzzle.giveMeTheModels()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.deniz.puzzle_game; | |
import java.security.SecureRandom; | |
public class Puzzle { | |
private CompanyAndDevice[] companyAndDevices; | |
private int currentDeviceModel; | |
private static final int NUMBER_OF_MODELS = 60; | |
private static final SecureRandom secureRandomNumbers = new SecureRandom(); | |
public Puzzle() { | |
String[] companies = {"Apple", "Google", "Sony", "Samsung", "HTC"}; | |
String[] devices = {"Xperia Z3", "iPhone 6", "Galaxy Note8", "Galaxy Note10", | |
"iPod Touch", "HTC M9", "Xperia Z5", "ipod Nano", | |
"Xperoa M", "Galaxy S6", "Nexus5", "Nexus10"}; | |
companyAndDevices = new CompanyAndDevice[NUMBER_OF_MODELS]; | |
currentDeviceModel = 0; | |
for (int index = 0; index < companyAndDevices.length ; index++){ | |
companyAndDevices[index] = new CompanyAndDevice(companies[index/12], devices[index/12]); | |
} | |
} | |
public void letsShuffleTheDevices(){ | |
currentDeviceModel = 0; | |
for(int firstDevice = 0 ; firstDevice < companyAndDevices.length; firstDevice++){ | |
int secondDevice = secureRandomNumbers.nextInt(NUMBER_OF_MODELS); | |
CompanyAndDevice tempCompanyDevice = companyAndDevices[firstDevice]; | |
companyAndDevices[firstDevice] = companyAndDevices[secondDevice]; | |
companyAndDevices[secondDevice] = tempCompanyDevice; | |
} | |
} | |
public CompanyAndDevice giveMeTheModels(){ | |
if(currentDeviceModel < companyAndDevices.length){ | |
return companyAndDevices[currentDeviceModel++]; | |
}else{ | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment