├── CharacterCounter.kt ├── Main └── mainFile.kt ├── Penghitung_Bangun_Datar.kt ├── README.md ├── haypp_main.kt ├── iseng.kt ├── tashya.kotlin └── vitriawidiasari.kotlin /CharacterCounter.kt: -------------------------------------------------------------------------------- 1 | package com.andyra.andyramadhan 2 | import java.util.Scanner 3 | 4 | private val scn = Scanner(System.`in`) 5 | private var iText = "" 6 | 7 | private fun main() { 8 | inputText() 9 | } 10 | 11 | private fun inputText(){ 12 | println("Character Counter Application") 13 | println("Please Input your text : ") 14 | 15 | iText = scn.next() 16 | if (iText.length < 1){ 17 | awal(true) 18 | } 19 | else { 20 | hitung() 21 | } 22 | } 23 | 24 | fun hitung() { 25 | println("Characters : ${iText.length}") 26 | print("ulang? Y/N : ") 27 | val ulang = scn.next() 28 | if (ulang.equals("Y") || ulang.equals("y")){ 29 | awal(true) 30 | } 31 | } 32 | 33 | fun awal(ulangi :Boolean){ 34 | if(ulangi){ 35 | inputText() 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Main/mainFile.kt: -------------------------------------------------------------------------------- 1 | package com.haypp.myreadwritefile 2 | 3 | import android.app.AlertDialog 4 | import android.os.Bundle 5 | import android.view.View 6 | import android.widget.Toast 7 | import androidx.appcompat.app.AppCompatActivity 8 | import com.haypp.myreadwritefile.databinding.ActivityMainBinding 9 | 10 | class MainActivity : AppCompatActivity(), View.OnClickListener { 11 | 12 | private lateinit var binding: ActivityMainBinding 13 | 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | binding = ActivityMainBinding.inflate(layoutInflater) 17 | setContentView(binding.root) 18 | 19 | binding.buttonNew.setOnClickListener(this) 20 | binding.buttonOpen.setOnClickListener(this) 21 | binding.buttonSave.setOnClickListener(this) 22 | 23 | } 24 | 25 | override fun onClick(view: View) { 26 | when (view.id) { 27 | R.id.button_new -> newFile() 28 | R.id.button_open -> showList() 29 | R.id.button_save -> saveFile() 30 | } 31 | } 32 | 33 | /** 34 | * Clear semua data yang sudah ditampilkan 35 | */ 36 | private fun newFile() { 37 | binding.editTitle.setText("") 38 | binding.editFile.setText("") 39 | Toast.makeText(this, "Clearing file", Toast.LENGTH_SHORT).show() 40 | } 41 | 42 | /** 43 | * Method untuk menampilkan semua file yang ada 44 | */ 45 | private fun showList() { 46 | val items = fileList() 47 | val builder = AlertDialog.Builder(this) 48 | builder.setTitle("Pilih file yang diinginkan") 49 | builder.setItems(items) { _, item -> loadData(items[item].toString()) } 50 | val alert = builder.create() 51 | alert.show() 52 | } 53 | 54 | private fun loadData(title: String) { 55 | val fileModel = FileHelper.readFromFile(this, title) 56 | binding.editTitle.setText(fileModel.filename) 57 | binding.editFile.setText(fileModel.data) 58 | Toast.makeText(this, "Loading " + fileModel.filename + " data", Toast.LENGTH_SHORT).show() 59 | } 60 | /** 61 | * Method untuk save data, nama file akan diambil dari binding.editTitle 62 | */ 63 | private fun saveFile() { 64 | when { 65 | binding.editTitle.text.toString().isEmpty() -> Toast.makeText(this, "Title harus diisi terlebih dahulu", Toast.LENGTH_SHORT).show() 66 | binding.editFile.text.toString().isEmpty() -> Toast.makeText(this, "Kontent harus diisi terlebih dahulu", Toast.LENGTH_SHORT).show() 67 | else -> { 68 | val title = binding.editTitle.text.toString() 69 | val text = binding.editFile.text.toString() 70 | val fileModel = FileModel() 71 | fileModel.filename = title 72 | fileModel.data = text 73 | FileHelper.writeToFile(fileModel, this) 74 | Toast.makeText(this, "Saving " + fileModel.filename + " file", Toast.LENGTH_SHORT).show() 75 | } 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /Penghitung_Bangun_Datar.kt: -------------------------------------------------------------------------------- 1 | package com.andyra.submission1ivanandyramadhan.Data.Local 2 | import java.util.Scanner 3 | 4 | private val bgnDatar = arrayOf("Persegi", "Persegi Panjang", "Lingkaran") 5 | private val jenis = arrayOf("Luas", "Keliling") 6 | 7 | private val sBgnDtr = bgnDatar.size 8 | private val sJenis = jenis.size 9 | private val scn = Scanner(System.`in`) 10 | private var iBgn: Int = 0 11 | private var iJns: Int = 0 12 | 13 | private fun main() { 14 | pilihBangun() 15 | } 16 | 17 | private fun pilihBangun(){ 18 | println("Aplikasi penghitung Keliling dan Luas bangun datar : ") 19 | println("Mohon pilih bangun datar : ") 20 | 21 | for(i in 0..sBgnDtr-1) 22 | { 23 | println("${i+1}. ${bgnDatar[i]}") 24 | } 25 | print("Masukkan Angka (1 - ${sBgnDtr}) : ") 26 | iBgn = scn.nextInt()-1 27 | 28 | sBgnDtr 29 | if (iBgn < 0 || iBgn >= sBgnDtr){ 30 | awal(true) 31 | } 32 | else { 33 | hitung() 34 | } 35 | } 36 | 37 | fun hitung() { 38 | when(bgnDatar[iBgn]){ 39 | "Persegi" -> persegi() 40 | "Persegi Panjang" -> pPanjang() 41 | "Lingkaran" -> lingkaran() 42 | } 43 | 44 | println("") 45 | print("ulang? Y/N : ") 46 | val ulang = scn.next() 47 | if (ulang.equals("Y") || ulang.equals("y")){ 48 | awal(true) 49 | } 50 | } 51 | 52 | 53 | fun persegi() { 54 | println("") 55 | print("Masukkan sisi persegi : ") 56 | var sisi = scn.nextFloat() 57 | 58 | println("") 59 | println("sisi = ${sisi}") 60 | println("luas persegi = ${sisi*sisi}") 61 | println("keliling persegi = ${4*sisi}") 62 | 63 | } 64 | fun pPanjang() { 65 | println("") 66 | print("Masukkan panjang persegi : ") 67 | var pjg = scn.nextFloat() 68 | print("Masukkan lebar persegi : ") 69 | var lbr = scn.nextFloat() 70 | 71 | println("") 72 | println("panjang = ${pjg} , lebar = ${lbr}") 73 | println("luas persegi panjang = ${pjg*lbr}") 74 | println("keliling persegi panjang = ${2*(pjg+lbr)}") 75 | 76 | } 77 | 78 | fun lingkaran() { 79 | println("") 80 | print("Masukkan jari - jari lingkaran : ") 81 | var jari = scn.nextFloat() 82 | 83 | println("") 84 | println("jari jari = ${jari}") 85 | println("luas lingkaran = ${3.14*jari*jari}") 86 | println("keliling lingkaran = ${2*3.14*jari}") 87 | } 88 | 89 | fun awal(ulangi :Boolean){ 90 | if(ulangi){ 91 | pilihBangun() 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kotlin-Projects 2 | # hacktoberfest 3 | 4 | ## Contributing 5 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 6 | 7 | Please make sure to update tests as appropriate. 8 | 9 | ## License 10 | [MIT](https://choosealicense.com/licenses/mit/) 11 | 12 | hacktoberfest 2021 13 | -------------------------------------------------------------------------------- /haypp_main.kt: -------------------------------------------------------------------------------- 1 | package com.haypp.githubuser 2 | 3 | import android.app.SearchManager 4 | import android.content.ContentValues.TAG 5 | import android.content.Context 6 | import android.content.Intent 7 | import androidx.appcompat.app.AppCompatActivity 8 | import android.os.Bundle 9 | import android.util.Log 10 | import android.view.Menu 11 | import android.view.MenuItem 12 | import android.view.View 13 | import android.widget.ProgressBar 14 | import androidx.appcompat.widget.SearchView 15 | import androidx.recyclerview.widget.LinearLayoutManager 16 | import com.haypp.githubuser.adaptor.ListUserAdaptor 17 | import com.haypp.githubuser.api.* 18 | import com.haypp.githubuser.databinding.ActivityMainBinding 19 | import retrofit2.Call 20 | import retrofit2.Callback 21 | import retrofit2.Response 22 | 23 | class MainActivity : AppCompatActivity() { 24 | private lateinit var bindingg: ActivityMainBinding 25 | private val listDataUtama = ArrayList() 26 | 27 | override fun onCreate(savedInstanceState: Bundle?) { 28 | super.onCreate(savedInstanceState) 29 | setContentView(R.layout.activity_main) 30 | findUser("haypp") 31 | bindingg = ActivityMainBinding.inflate(layoutInflater) 32 | setContentView(bindingg.root) 33 | bindingg.rvgithub.setHasFixedSize(true) 34 | } 35 | 36 | private fun showRecyclerList() { 37 | bindingg.rvgithub.layoutManager = LinearLayoutManager(this) 38 | val listUserAdaptor = ListUserAdaptor(listDataUtama) 39 | bindingg.rvgithub.adapter = listUserAdaptor 40 | } 41 | 42 | override fun onCreateOptionsMenu(menu: Menu): Boolean { 43 | val inflater = menuInflater 44 | inflater.inflate(R.menu.option_menu, menu) 45 | val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager 46 | val searchView = menu.findItem(R.id.search).actionView as SearchView 47 | searchView.setSearchableInfo(searchManager.getSearchableInfo(componentName)) 48 | searchView.queryHint = resources.getString(R.string.search_hint) 49 | searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { 50 | override fun onQueryTextSubmit(query: String): Boolean { 51 | searchView.clearFocus() 52 | findUser(query) 53 | return true 54 | } 55 | override fun onQueryTextChange(newText: String): Boolean { 56 | return false 57 | } 58 | }) 59 | return true 60 | } 61 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 62 | when (item.itemId) { 63 | R.id.menuFavorite -> { 64 | val i = Intent(this, FavoriteActivity::class.java) 65 | startActivity(i) 66 | return true 67 | } 68 | R.id.menuSettings -> { 69 | val i = Intent(this, SettingsActivity::class.java) 70 | startActivity(i) 71 | return true 72 | } 73 | else -> return true 74 | } 75 | } 76 | 77 | private fun findUser(username: String) { 78 | showLoading(true) 79 | ApiConfig.getApiService().getSearchUser(username).enqueue(object : Callback { 80 | override fun onResponse(call: Call, response: Response) { 81 | if (response.isSuccessful) { 82 | showLoading(false) 83 | val listItems = response.body() 84 | if (listItems != null) { 85 | listDataUtama.clear() 86 | responseUser(listItems.items) 87 | } 88 | } 89 | } 90 | override fun onFailure(call: Call, t: Throwable) { 91 | Log.e(TAG, "onFailure: ${t.message.toString()}") 92 | showLoading(false) 93 | } 94 | }) 95 | } 96 | private fun responseUser(items: ArrayList) { 97 | for(mitems in items){ 98 | listDataUtama.add(Items(mitems.avatarUrl, mitems.login)) 99 | } 100 | showRecyclerList() 101 | } 102 | private fun showLoading(isLoading: Boolean) { 103 | val progressBar = findViewById(R.id.barprogess) 104 | progressBar?.visibility = if (isLoading) View.VISIBLE else View.GONE 105 | } 106 | } 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /iseng.kt: -------------------------------------------------------------------------------- 1 | package com.example.finalcalculator 2 | import androidx.appcompat.app.AppCompatActivity 3 | import android.os.Bundle 4 | import kotlinx.android.synthetic.main.activity_main.* 5 | import net.objecthunter.exp4j.ExpressionBuilder 6 | 7 | class MainActivity : AppCompatActivity() 8 | { 9 | 10 | override fun onCreate(savedInstanceState: Bundle?) 11 | { 12 | super.onCreate(savedInstanceState) 13 | setContentView(R.layout.activity_main) 14 | 15 | 16 | /*Number Buttons*/ 17 | 18 | tvOne.setOnClickListener { 19 | evaluateExpression("1", clear = true) 20 | } 21 | 22 | tvTwo.setOnClickListener { 23 | evaluateExpression("2", clear = true) 24 | } 25 | 26 | tvThree.setOnClickListener { 27 | evaluateExpression("3", clear = true) 28 | } 29 | tvFour.setOnClickListener { 30 | evaluateExpression("4", clear = true) 31 | } 32 | 33 | tvFive.setOnClickListener { 34 | evaluateExpression("5", clear = true) 35 | } 36 | 37 | tvSix.setOnClickListener { 38 | evaluateExpression("6", clear = true) 39 | } 40 | 41 | tvSeven.setOnClickListener { 42 | evaluateExpression("7", clear = true) 43 | } 44 | 45 | tvEight.setOnClickListener { 46 | evaluateExpression("8", clear = true) 47 | } 48 | 49 | tvNine.setOnClickListener { 50 | evaluateExpression("9", clear = true) 51 | } 52 | 53 | tvZero.setOnClickListener { 54 | evaluateExpression("0", clear = true) 55 | } 56 | 57 | /*Operators*/ 58 | 59 | tvPlus.setOnClickListener { 60 | evaluateExpression("+", clear = true) 61 | } 62 | 63 | tvMinus.setOnClickListener { 64 | evaluateExpression("-", clear = true) 65 | } 66 | 67 | tvMul.setOnClickListener { 68 | evaluateExpression("*", clear = true) 69 | } 70 | 71 | tvDivide.setOnClickListener { 72 | evaluateExpression("/", clear = true) 73 | } 74 | 75 | tvDot.setOnClickListener { 76 | evaluateExpression(".", clear = true) 77 | } 78 | 79 | tvClear.setOnClickListener { 80 | tvExpression.text = "" 81 | tvResult.text = "" 82 | } 83 | 84 | tvEquals.setOnClickListener { 85 | val text = tvExpression.text.toString() 86 | val expression = ExpressionBuilder(text).build() 87 | 88 | val result = expression.evaluate() 89 | val longResult = result.toLong() 90 | if (result == longResult.toDouble()) { 91 | tvResult.text = longResult.toString() 92 | } else { 93 | tvResult.text = result.toString() 94 | } 95 | } 96 | 97 | tvBack.setOnClickListener { 98 | val text = tvExpression.text.toString() 99 | if(text.isNotEmpty()) { 100 | tvExpression.text = text.drop(1) 101 | } 102 | 103 | tvResult.text = "" 104 | } 105 | } 106 | 107 | /*Function to calculate the expressions using expression builder library*/ 108 | 109 | fun evaluateExpression(string: String, clear: Boolean) { 110 | if(clear) { 111 | Result.text = "" 112 | Expression.append(string) 113 | } else { 114 | Expression.append(Result.text) 115 | Expression.append(string) 116 | Result.text = "" 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /tashya.kotlin: -------------------------------------------------------------------------------- 1 | 2 | // Hello World Program 3 | 4 | fun main(args : Array) { 5 | println("Hello, World!") 6 | } 7 | -------------------------------------------------------------------------------- /vitriawidiasari.kotlin: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env kotlin 2 | 3 | @file:Repository("https://jcenter.bintray.com") 4 | @file:DependsOn("org.jetbrains.kotlinx:kotlinx-html-jvm:0.6.11") 5 | 6 | import kotlinx.html.*; import kotlinx.html.stream.*; import kotlinx.html.attributes.* 7 | 8 | val addressee = args.firstOrNull() ?: "World" 9 | 10 | print(createHTML().html { 11 | body { 12 | h1 { +"Hello, $address!" } 13 | } 14 | }) 15 | --------------------------------------------------------------------------------