Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. import React from 'react';
  2. import { StyleSheet, Text,TextInput, View, Button,} from 'react-native';
  3.  
  4. export default class Nilai extends React.Component {
  5.  
  6. constructor(props) {
  7. super(props)
  8. this.state = {
  9. Tugas1:0,
  10. Tugas2:0,
  11. NA:0,
  12. Predikat:'',
  13. };
  14. }
  15. render() {
  16. return (
  17. <View style={styles.containerMain}>
  18. <View style={styles.boxAtas}>
  19. <Text style={styles.text}>Siak</Text>
  20. </View>
  21.  
  22.  
  23. <View style={styles.boxTengah}>
  24. <View style={styles.masuk}>
  25. <Text style={styles.text2}>Tugas 1 : </Text>
  26. <TextInput style = {styles.txtInput}
  27. placeholder="Masukkan Nilai Tugas1"
  28. onChangeText={
  29. (Tugas1)=>this.setState({Tugas1})
  30. }
  31. keyboardType = 'numeric'
  32. />
  33. </View>
  34.  
  35. <View style={styles.masuk}>
  36. <Text style={styles.text2}>Tugas 2 :</Text>
  37. <TextInput style = {styles.txtInput2}
  38. placeholder="Masukkan Nilai Tugas2"
  39. onChangeText={
  40. (Tugas2)=>this.setState({Tugas2})
  41. }
  42. keyboardType = 'numeric'
  43. />
  44.  
  45. </View>
  46.  
  47. <View style={styles.vbutton}>
  48. <Button
  49. onPress ={
  50. () => {
  51. let nilaiTotal = 0.5 * this.state.Tugas1 + 0.5* this.state.Tugas2;
  52. this.setState({NA:nilaiTotal});
  53.  
  54. if (nilaiTotal>50)
  55. this.setState({Predikat:'Lulus'});
  56. else {
  57. this.setState({Predikat:'Tidak Lulus'});
  58. }
  59. }
  60. }
  61. title="Hitung"
  62. accessibilityLabel="Klik untuk menghitung"
  63. />
  64. </View>
  65.  
  66.  
  67. </View>
  68.  
  69.  
  70. <View style={styles.box3}>
  71.  
  72.  
  73. <Text style={styles.text2}>Nilai Akhir : {this.state.NA} </Text>
  74. <Text style={styles.text2}>Predikat : {this.state.Predikat}</Text>
  75.  
  76.  
  77.  
  78.  
  79.  
  80. </View>
  81.  
  82. {/* <View style={styles.footer}>
  83. <Text style={styles.text}>Copyright Ferdo Kaban</Text>
  84. </View> */}
  85.  
  86. </View>
  87. );
  88. }
  89. }
  90.  
  91. const styles = StyleSheet.create({
  92. containerMain: {
  93. flex: 1,
  94. flexDirection: 'column',
  95.  
  96. },
  97. boxAtas:{
  98. flex: 1,
  99. backgroundColor: 'blue',
  100. justifyContent: 'center',
  101. alignItems: 'center',
  102.  
  103. },
  104. txtInput: {
  105. height: 40,
  106. width: -50,
  107. backgroundColor:'white',
  108. margin:10,
  109. padding: 10
  110. },
  111. txtInput2: {
  112. height: 40,
  113. width: -50,
  114. backgroundColor:'white',
  115. padding: 10,
  116. margin:10,
  117. },
  118.  
  119. boxTengah:{
  120. flex: 2.5,
  121. backgroundColor: '#61cdf4',
  122. },
  123.  
  124. masuk:{
  125. flexDirection:'row',
  126. marginTop:10,
  127. },
  128.  
  129. box3: {
  130. flex: 3,
  131. backgroundColor: 'powderblue',
  132. justifyContent: 'center',
  133. alignItems: 'center',
  134. },
  135.  
  136. text: {
  137. fontSize: 35,
  138. color: 'white',
  139. },
  140.  
  141. text2: {
  142. fontSize: 20,
  143. color: 'black',
  144. fontWeight: 'bold',
  145. margin:10,
  146. padding: 10
  147. },
  148.  
  149. vbutton:{
  150. flex : 3,
  151. justifyContent: 'space-around',
  152. marginTop : 60,
  153. }
  154.  
  155. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement