Advertisement
Guest User

zadanie z dni,godziny

a guest
Dec 5th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. tools:context=".MainActivity">
  8.  
  9. <EditText
  10. android:id="@+id/editText01"
  11. android:layout_width="wrap_content"
  12. android:layout_height="wrap_content"
  13. android:textSize="15pt"
  14. android:ems="5"
  15. android:inputType="number"
  16. app:layout_constraintLeft_toLeftOf="parent"
  17. app:layout_constraintTop_toTopOf="parent"
  18. android:layout_margin="5pt"
  19. />
  20.  
  21. <TextView
  22. android:id="@+id/textView01"
  23. android:layout_width="wrap_content"
  24. android:layout_height="wrap_content"
  25. android:text="dni"
  26. android:textSize="15pt"
  27. app:layout_constraintLeft_toRightOf="@+id/editText01"
  28. app:layout_constraintBottom_toBottomOf="@id/editText01"
  29. android:layout_margin="5pt"
  30. />
  31.  
  32. <EditText
  33. android:id="@+id/editText02"
  34. android:layout_width="wrap_content"
  35. android:layout_height="wrap_content"
  36. android:textSize="15pt"
  37. android:ems="5"
  38. android:inputType="number"
  39. app:layout_constraintLeft_toLeftOf="parent"
  40. app:layout_constraintTop_toBottomOf="@id/editText01"
  41. android:layout_margin="5pt"
  42. />
  43.  
  44. <TextView
  45. android:id="@+id/textView02"
  46. android:layout_width="wrap_content"
  47. android:layout_height="wrap_content"
  48. android:text="godziny"
  49. android:textSize="15pt"
  50. app:layout_constraintLeft_toRightOf="@+id/editText01"
  51. app:layout_constraintBottom_toBottomOf="@id/editText02"
  52. android:layout_margin="5pt"
  53. />
  54.  
  55. <EditText
  56. android:id="@+id/editText03"
  57. android:layout_width="wrap_content"
  58. android:layout_height="wrap_content"
  59. android:textSize="15pt"
  60. android:ems="5"
  61. android:inputType="number"
  62. app:layout_constraintLeft_toLeftOf="parent"
  63. app:layout_constraintTop_toBottomOf="@id/editText02"
  64. android:layout_margin="5pt"
  65. />
  66.  
  67. <TextView
  68. android:id="@+id/textView03"
  69. android:layout_width="wrap_content"
  70. android:layout_height="wrap_content"
  71. android:text="minuty"
  72. android:textSize="15pt"
  73. app:layout_constraintLeft_toRightOf="@+id/editText01"
  74. app:layout_constraintBottom_toBottomOf="@id/editText03"
  75. android:layout_margin="5pt"
  76. />
  77.  
  78. <Button
  79. android:id="@+id/button01"
  80. android:layout_width="0pt"
  81. android:layout_height="wrap_content"
  82. android:text="przelicz"
  83. android:textSize="10pt"
  84. android:layout_margin="5pt"
  85. app:layout_constraintTop_toBottomOf="@id/editText03"
  86. app:layout_constraintLeft_toLeftOf="parent"
  87. app:layout_constraintRight_toRightOf="parent"
  88. android:onClick="calculate"
  89. />
  90.  
  91. <TextView
  92. android:id="@+id/textView04"
  93. android:layout_width="wrap_content"
  94. android:layout_height="wrap_content"
  95. android:text="................."
  96. android:textSize="12pt"
  97. android:ems="5"
  98. app:layout_constraintLeft_toLeftOf="parent"
  99. app:layout_constraintTop_toBottomOf="@id/button01"
  100. android:layout_margin="5pt"
  101. />
  102.  
  103. <TextView
  104. android:id="@+id/textView05"
  105. android:layout_width="wrap_content"
  106. android:layout_height="wrap_content"
  107. android:text="minut"
  108. android:textSize="15pt"
  109. app:layout_constraintLeft_toRightOf="@id/textView04"
  110. app:layout_constraintTop_toBottomOf="@id/button01"
  111. android:layout_margin="5pt"
  112. />
  113.  
  114. </androidx.constraintlayout.widget.ConstraintLayout>
  115.  
  116.  
  117.  
  118. ***********************************************************************************
  119.  
  120.  
  121. package com.example.k02;
  122.  
  123. import androidx.appcompat.app.AppCompatActivity;
  124.  
  125. import android.os.Bundle;
  126. import android.view.View;
  127. import android.widget.EditText;
  128. import android.widget.TextView;
  129.  
  130. import org.w3c.dom.Text;
  131.  
  132. public class MainActivity extends AppCompatActivity {
  133.  
  134. @Override
  135. protected void onCreate(Bundle savedInstanceState) {
  136. super.onCreate(savedInstanceState);
  137. setContentView(R.layout.activity_main);
  138. }
  139.  
  140. public void calculate(View view) {
  141. double x=0, y=0, z=0;
  142.  
  143. EditText dni = findViewById(R.id.editText01);
  144. EditText godz = findViewById(R.id.editText02);
  145. EditText min = findViewById(R.id.editText03);
  146.  
  147. TextView wynik = findViewById(R.id.textView04);
  148.  
  149. String dni1, godz1, min1;
  150.  
  151. dni1 = dni.getText().toString();
  152. x = Double.parseDouble(dni1);
  153.  
  154. godz1 = godz.getText().toString();
  155. y = Double.parseDouble(godz1);
  156.  
  157. min1 = min.getText().toString();
  158. z = Double.parseDouble(min1);
  159.  
  160. x=x*24*60;
  161. y=y*60;
  162.  
  163. double w = x + y + z;
  164.  
  165. wynik.setText(String.valueOf(w));
  166.  
  167. }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement