体质评估计算器-kotlin

2024-02-26 17:10
文章标签 评估 kotlin 计算器 体质

本文主要是介绍体质评估计算器-kotlin,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

前言

这学期上了移动智能开发,做了几个作业,虽然做得不是很理想,但是还是想记录一下,方便有些用法以后回来可查。
android下载和配置见:android studio配置介绍 。

关键代码: Android-class/elevator_cal (gitee仓库)
原创链接: 体质评估计算器-kotlin
https://blog.csdn.net/weixin_43850253/article/details/113560574



效果

在这里插入图片描述
在这里插入图片描述


项目结构

主要是MainActivity.kt 和 activity_main.xml文件
在这里插入图片描述



详细代码

MainActivity.kt

package com.example.elevator_calimport androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
import androidx.appcompat.app.AlertDialog
import kotlin.math.absclass MainActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)btn.setOnClickListener {if (!kg.text.toString().trim().equals("") && !height.text.toString().trim().equals("")) {if (rb1.isChecked || rb2.isChecked) {val wt = kg.text.toString().toFloat()val ht = height.text.toString().toFloat()val subLt = arrayOf(80, 70)val rateLt = arrayOf(0.7, 0.6)var subValue = 0if (rb2.isChecked) {subValue = 1}val dreamWeight = (ht - subLt[subValue]) * rateLt[subValue]val overWeight = (wt - dreamWeight) / dreamWeightprintln("dreamWeight: $dreamWeight $overWeight")val tipList = arrayOf("体重不足, 体重偏轻20%以上", "体重过轻, 体重偏轻10%到20%","正常体重, 体重正负10%", "体重过重, 体重偏重10%到20%", "肥胖的小可爱,体重偏重20%以上")var tipIndex = 2 // 初始设置为正常体重嘻嘻嘻when {overWeight < -0.2 -> tipIndex = 0overWeight in -0.2..-0.1 -> tipIndex = 1overWeight in 0.1..0.2 -> tipIndex = 3overWeight > 0.2 -> tipIndex = 4}showResultView.text = tipList[tipIndex]} else {showDialog("请选择性别") // 用AlertDialog实现函数}} else {showDialog("请输入身高或体重!") // 用AlertDialog实现函数    }}}}private fun showDialog(message_str: String) {val builder = AlertDialog.Builder(this)builder.setTitle("错误提示消息").setMessage(message_str).setPositiveButton("确定", { dialog, id -> }).setNegativeButton("取消", { dialog, id -> })builder.create()builder.show()}
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><TextViewandroid:id="@+id/txt"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_marginTop="40dp"android:text="@string/title"android:textSize="30sp" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="30dp"android:layout_marginStart="30dp"android:layout_marginTop="40dp"><TextViewandroid:id="@+id/txt1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/txt_kg" /><EditTextandroid:id="@+id/kg"android:layout_width="100dp"android:inputType="number"android:layout_height="wrap_content" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="30dp"android:layout_marginStart="30dp"android:layout_marginTop="40dp"><TextViewandroid:id="@+id/txt2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/txt_height" /><EditTextandroid:id="@+id/height"android:layout_width="100dp"android:inputType="number"android:layout_height="wrap_content"/></LinearLayout><RadioGroupandroid:id="@+id/rg"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_marginLeft="30dp"android:layout_marginStart="30dp"android:layout_marginTop="40dp"><RadioButtonandroid:id="@+id/rb1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginRight="30dp"android:checked="true"android:text="@string/radio_male" /><RadioButtonandroid:id="@+id/rb2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/radio_female"/></RadioGroup><Buttonandroid:id="@+id/btn"android:layout_width="180dp"android:layout_height="wrap_content"android:text="@string/cal_button"android:layout_gravity="center"android:layout_marginTop="30dp"/><TextViewandroid:id="@+id/resultTip"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_marginTop="40dp"android:textSize="28sp"android:text="@string/result_tip"/><TextViewandroid:id="@+id/showResultView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="50dp"android:layout_marginStart="50dp"android:layout_marginTop="20dp"android:textSize="22sp"/></LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.elevator_cal"><applicationandroid:allowBackup="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:theme="@style/AppTheme"><activity android:name=".MainActivity"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application></manifest>

在build.gradle中:

apply plugin: 'com.android.application'apply plugin: 'kotlin-android'
// 这里可以方便直接按id获取组件
apply plugin: 'kotlin-android-extensions'android {compileSdkVersion 30buildToolsVersion "30.0.1"defaultConfig {applicationId "com.example.elevator_cal"minSdkVersion 15targetSdkVersion 30versionCode 1versionName "1.0"testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"}buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'}}
}dependencies {implementation fileTree(dir: 'libs', include: ['*.jar'])implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"implementation 'androidx.appcompat:appcompat:1.0.2'implementation 'androidx.core:core-ktx:1.0.2'implementation 'androidx.constraintlayout:constraintlayout:1.1.3'testImplementation 'junit:junit:4.12'androidTestImplementation 'androidx.test.ext:junit:1.1.0'androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

想引起注意的是, 以下语句可以方便直接按id选中组件。

apply plugin: 'kotlin-android-extensions'

这篇关于体质评估计算器-kotlin的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/749573

相关文章

PR曲线——一个更敏感的性能评估工具

在不均衡数据集的情况下,精确率-召回率(Precision-Recall, PR)曲线是一种非常有用的工具,因为它提供了比传统的ROC曲线更准确的性能评估。以下是PR曲线在不均衡数据情况下的一些作用: 关注少数类:在不均衡数据集中,少数类的样本数量远少于多数类。PR曲线通过关注少数类(通常是正类)的性能来弥补这一点,因为它直接评估模型在识别正类方面的能力。 精确率与召回率的平衡:精确率(Pr

安卓开发板_联发科MTK开发评估套件串口调试

串口调试 如果正在进行lk(little kernel ) 或内核开发,USB 串口适配器( USB 转串口 TTL 适配器的简称)对于检查系统启动日志非常有用,特别是在没有图形桌面显示的情况下。 1.选购适配器 常用的许多 USB 转串口的适配器,按芯片来分,有以下几种: CH340PL2303CP2104FT232 一般来说,采用 CH340 芯片的适配器,性能比较稳定,价

Kotlin高阶函数与Lambda表达式及内联函数的介绍

目录 1、高阶函数1.1、什么是高阶函数?1.1.1、不带返回值的高阶函数1.1.2、带参数且带返回值的高阶函数1.1.3、与一般的函数进行比较 1.2、如何使用?1.3、高阶函数有什么作用? 2、Lambda表达式2.1、什么是Lambda表达式?2.1.1、无参数的写法2.1.2、有参数的写法2.1.3、有参数且有返回值的写法 2.2、如何使用?2.3、Lambda表达式有什么作用? 3

随着人们网络安全意识提高,软件架构设计与评估也成为重中之重

目录 案例 【题目】 【问题 1】(13 分) 【问题 2】(12分) 【答案】 【问题 1】答案 【问题 2】答案 相关推荐 案例         阅读以下关于软件架构设计与评估的叙述,回答问题 1 和问题 2。 【题目】         某电子商务公司为正更好地管理用户,提升企业销售业绩,拟开发一套用户管理系统。该系统的基本功能是根据用户的消费级别、消费历史、信

android kotlin复习 Anonymous function 匿名函数

1、还是先上个图,新建kt: 2、代码: package com.jstonesoft.myapplication.testfun main(){val count = "helloworld".count()println(count);println("------------------------")var count2 = "helloworld".count(){it ==

基于yolov8的包装盒纸板破损缺陷测系统python源码+onnx模型+评估指标曲线+精美GUI界面

【算法介绍】 基于YOLOv8的包装盒纸板破损缺陷检测系统是一种高效、智能的解决方案,旨在提高生产线上包装盒纸板的质量检测效率与准确性。该系统利用YOLOv8这一前沿的深度学习模型,通过其强大的目标检测能力,能够实时识别并标记出包装盒纸板上的各种破损缺陷,如划痕、撕裂、孔洞等。 在系统中,首先需对包含破损缺陷的包装盒纸板图像进行数据采集和标注,形成训练数据集。随后,利用这些数据进行模型训练,使

QT学习之计算器

网格布局初尝试,快速构建计算器 项目结构: wident.h拖动建立界面,20个button,一个lineedit 布局好后整体网格布局调整,依次给每个案件输入文本,并改objectname方便后期辨识 为了在lineedit显示数字,转到槽,编辑点击事件,如显示“1” void Widget::on_pushButton1_clicked(){expression += "1";u

android开发---Kotlin语言基础语法

目录 数据打印 变量 函数 程序逻辑控制   if  when 循环 数据打印 IDE采用的androidStudio 可自行官网下载 https://developer.android.google.cn/studio/archive?hl=zh-cn 新建项目 添加一个main方法,main()函数的左边出现了一个运行标志的小箭头。现在我们只要点击一下这个

Arcgis字段计算器:随机生成规定范围内的数字

选择字段计算器在显示的字段计算器对话框内,解析程序选择Python,勾选上显示代码块, 半部分输入: import random; 可修改下半部分输入: random.randrange(3, 28) 表示生成3-28之间的随机数 字段计算器设置点击确定完成随机数的生成,生成的随机数如下图所示。

数据安全评估工程师CCRC-DSA怎么考?

数据安全评估工程师的职责涉及对数据安全风险进行专业评估。 他们通过深入分析企业的数据资产,识别潜在风险,并设计相应的防范措施。 此岗位要求从业者具备深厚的计算机科学与网络安全专业知识以及丰富的实践经历。 对于想要成为数据安全评估工程师的人来说,基本条件包括:1. 教育背景:通常需要本科以上学历,以计算机科学、信息安全或网络工程等相关专业为佳。 2. 技能水平:必须掌握操作系统、数据库、