標題:
[作業] 三角形邊長判斷
[打印本頁]
作者:
周政輝
時間:
2018-8-25 11:45
標題:
[作業] 三角形邊長判斷
[attach]4694[/attach]
[attach]4695[/attach]
[attach]4696[/attach]
作者:
李知易
時間:
2018-8-26 13:03
package com.example.change.hw1070824;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText input1,input2,input3;
TextView show;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
input1 = (EditText)findViewById(R.id.input1);
input2 = (EditText)findViewById(R.id.input2);
input3 = (EditText)findViewById(R.id.input3);
show = (TextView) findViewById(R.id.show);
}
public void calc(View view)
{
int a = Integer.parseInt(input1.getText().toString());
int b = Integer.parseInt(input2.getText().toString());
int c = Integer.parseInt(input3.getText().toString());
if(a+b>c && b+c>a && c+a>b)
{
if(a*a+b*b==c*c || b*b+c*c==a*a || c*c+a*a==b*b)
show.setText("直角三角形好嗎?直角三角形不就是其中有兩個邊的平方和等於第三邊的平方!連畢氏定理都不會!");
else if(a*a+b*b<c*c || b*b+c*c<a*a || c*c+a*a<b*b)
show.setText("鈍角三角形你不會是不是?鈍角三角形阿就其中有兩個邊的平方和小於第三邊的平方!笨欸!");
else
show.setText("銳角三角形啦!銳角三角形其中有兩個邊的平方和大於第三邊的平方!這種東西還要我幫你算?");
}else
{
show.setText("不可以構成三角形啦!構成三角形存在條件是任兩邊相加大於第三邊,且皆不可為0啦!可不可以像我一樣聰明阿?");
}
}
public void clear(View view) {
input1.setText("");
input2.setText("");
input3.setText("");
show.setText("歡迎使用三角形邊長判斷器~我會客客氣氣得跟您講解喔~");
}
}
複製代碼
作者:
黃茂勛
時間:
2018-8-27 13:30
MainActivity:
package com.example.einstein.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import static com.example.einstein.myapplication.R.id.result;
import static com.example.einstein.myapplication.R.id.side1;
public class MainActivity extends AppCompatActivity {
EditText side1,side2,side3;
TextView result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
side1 = findViewById(R.id.side1);
side2 = findViewById(R.id.side2);
side3 = findViewById(R.id.side3);
result = findViewById(R.id.result);
}
public void click_judge(View view) {
int a = Integer.parseInt(side1.getText().toString());
int b = Integer.parseInt(side2.getText().toString());
int c = Integer.parseInt(side3.getText().toString());
if(a+b>c && b+c>a && c+a>b)
{
if(a*a+b*b==c*c || b*b+c*c==a*a || c*c+a*a==b*b)
result.setText("這是一個直角三角形");
else if(a*a+b*b>c*c || b*b+c*c>a*a || c*c+a*a>b*b)
result.setText("這是一個銳角三角形");
else
result.setText("這是一個頓角三角形");
}else
result.setText("無法構成三形!");
}
public void click_clean(View view) {
side1.setText("");
side2.setText("");
side3.setText("");
result.setText("");
}
}
複製代碼
activity.xml(新加 android:gravity="center"):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity">
<EditText
android:id="@+id/side1"
android:layout_width="324dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:ems="10"
android:hint="@string/side1"
android:gravity="center"
android:inputType="numberSigned"
android:singleLine="false" />
<EditText
android:id="@+id/side2"
android:layout_width="325dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignStart="@+id/side1"
android:layout_marginTop="98dp"
android:ems="10"
android:hint="@string/side2"
android:gravity="center"
android:inputType="numberSigned" />
<EditText
android:id="@+id/side3"
android:layout_width="325dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignStart="@+id/side1"
android:layout_marginTop="160dp"
android:ems="10"
android:hint="@string/side3"
android:gravity="center"
android:inputType="numberSigned" />
<Button
android:id="@+id/judge"
android:layout_width="236dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="185dp"
android:onClick="click_judge"
android:text="@string/judge" />
<Button
android:id="@+id/clean"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="122dp"
android:onClick="click_clean"
android:text="@string/clean" />
<TextView
android:id="@+id/result"
android:layout_width="282dp"
android:layout_height="46dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="231dp"
android:gravity="center"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
</RelativeLayout>
複製代碼
作者:
黃璽安
時間:
2018-8-28 16:14
本帖最後由 黃璽安 於 2018-8-28 22:49 編輯
package com.example.shain.ch02;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class Ch02 extends AppCompatActivity {
EditText input1, input2, input3;
TextView show;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ch02);
input1 = (EditText)findViewById(R.id.input1);
input2 = (EditText)findViewById(R.id.input2);
input3 = (EditText)findViewById(R.id.input3);
show = (TextView)findViewById(R.id.show);
}
public void judgment(View view){
int a = Integer.parseInt(input1.getText().toString());
int b = Integer.parseInt(input2.getText().toString());
int c = Integer.parseInt(input3.getText().toString());
if(a+b>c && a+c>b && b+c>a){
if(a*a+b*b==c*c || b*b+c*c==a*a || c*c+a*a==b*b){
show.setText("這個是直角三角形");
}
else if(a*a+b*b<c*c || b*b+c*c<a*a || c*c+a*a<b*b){
show.setText("這個是鈍角三角形");
}
else{
show.setText("這個是銳角三角形");
}
}
else
show.setText("此三邊不可以構成三角形");
}
public void clear(View view){
input1.setText("");
input2.setText("");
input3.setText("");
show.setText("");
}
}
複製代碼
作者:
蔡季樺
時間:
2018-8-30 18:55
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context=".MainActivity">
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal"
tools:layout_editor_absoluteX="85dp"
tools:layout_editor_absoluteY="50dp" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textEmailAddress"
app:layout_constraintTop_toBottomOf="@+id/editText"
tools:layout_editor_absoluteX="84dp" />
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textEmailAddress"
app:layout_constraintTop_toBottomOf="@+id/editText2"
tools:layout_editor_absoluteX="84dp" />
<Button
android:id="@+id/button"
android:layout_width="211dp"
android:layout_height="46dp"
android:layout_marginTop="8dp"
android:text="@string/判斷"
app:layout_constraintTop_toBottomOf="@+id/textView"
tools:layout_editor_absoluteX="88dp" />
<Button
android:id="@+id/button2"
android:layout_width="207dp"
android:layout_height="45dp"
android:layout_marginTop="8dp"
android:text="@string/清除"
app:layout_constraintTop_toBottomOf="@+id/button"
tools:layout_editor_absoluteX="91dp" />
<TextView
android:id="@+id/textView"
android:layout_width="210dp"
android:layout_height="29dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/editText3"
tools:layout_editor_absoluteX="88dp" />
複製代碼
package com.example.plantsai.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText et,et2,et3;
Button btn,btn2;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et = findViewById(R.id.editText);
et2 = findViewById(R.id.editText2);
et3 = findViewById(R.id.editText3);
btn = findViewById(R.id.button);
btn2 = findViewById(R.id.button2);
tv = findViewById(R.id.textView);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double a =Double.parseDouble(et.getText()+"");
double b =Double.parseDouble(et2.getText()+"");
double c =Double.parseDouble(et3.getText()+"");
if(a+b>c || b+c>a || a+c>b)
{
if(a*a+b*b==c*c || b*b+c*c==a*a || a*a+c*c==b*b)
{
tv.setText("直角三角形");
}else if(a*a+b*b<c*c || b*b+c*c<a*a || a*a+c*c<b*b)
{
tv.setText("鈍角三角形");
}else
{
tv.setText("銳角三角形");
}
}else
{
tv.setText("絕對不是三角形");
}
}
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
et.setText("");
et2.setText("");
et3.setText("");
tv.setText("");
}
});
}
}
複製代碼
作者:
張健勳
時間:
2018-9-1 10:51
package com.example.student.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText sideA,sideB,sideC;
TextView textview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sideA = (EditText) findViewById(R.id.sideA);
sideB = (EditText) findViewById(R.id.sideB);
sideC = (EditText) findViewById(R.id.sideC);
textview = (TextView) findViewById(R.id.textview);
}
public void judge(View view){
int a = Integer.parseInt(sideA.getText().toString());
int b = Integer.parseInt(sideB.getText().toString());
int c = Integer.parseInt(sideC.getText().toString());
if(a+b>c && a+c>b && b+c>a){
if(a*a+b*b==c*c || b*b+c*c==a*a || c*c+a*a==b*b){
textview.setText("直角三角形");
}
else if(a*a+b*b<c*c || b*b+c*c<a*a || c*c+a*a<b*b){
textview.setText("鈍角三角形");
}
else{
textview.setText("銳角三角形");
}
}
else
textview.setText("此三邊無法構成三角形");
}
public void clear(View view){
sideA.setText("");
sideB.setText("");
sideC.setText("");
textview.setText("");
}
}
複製代碼
作者:
蔡庭豪
時間:
2018-9-1 11:00
本帖最後由 蔡庭豪 於 2018-9-2 00:02 編輯
package com.example.houyang.triangle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView first;
TextView second;
TextView third;
TextView res;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
first = findViewById(R.id.first);
second = findViewById(R.id.second);
third = findViewById(R.id.third);
res = findViewById(R.id.result);
}
public void triangle_judge (View view){
int a = Integer.valueOf(first.getText().toString());
int b = Integer.valueOf(second.getText().toString());
int c = Integer.valueOf(third.getText().toString());
if (a+b>c||a+c>b||b+c>a)
if(a*a+b*b>c*c||a*a+c*c>b*b||b*b+c*c>a*a)
res.setText("鈍角三角形");
else if(a*a+b*b<c*c||a*a+c*c<b*b||b*b+c*c<a*a)
res.setText("角三角形");
else if(a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a)
res.setText("直角三角形");
else if(a==b && b==c && a==c)
res.setText("三角形");
else
res.setText("無法溝成三角形");
}
public void Clear(View view){
first.setText(" ");
second.setText(" ");
third.setText(" ");
res.setText(" ");
}
}
複製代碼
作者:
陳思惟
時間:
2018-9-1 11:36
package com.example.student.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText input1, input2, input3;
TextView show;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
input1 = (EditText)findViewById(R.id.side1);
input2 = (EditText)findViewById(R.id.side2);
input3 = (EditText)findViewById(R.id.side3);
show = (TextView)findViewById(R.id.result);
}
public void judgment(View view){
int a = Integer.parseInt(input1.getText().toString());
int b = Integer.parseInt(input2.getText().toString());
int c = Integer.parseInt(input3.getText().toString());
if(a+b>c && a+c>b && b+c>a){
if(a*a+b*b==c*c || b*b+c*c==a*a || c*c+a*a==b*b){
show.setText("這個是直角三角形");
}
else if(a*a+b*b<c*c || b*b+c*c<a*a || c*c+a*a<b*b){
show.setText("這個是鈍角三角形");
}
else{
show.setText("這個是銳角三角形");
}
}
else
show.setText("此三邊不可以構成三角形");
}
public void clear(View view){
input1.setText("");
input2.setText("");
input3.setText("");
show.setText("");
}
}
複製代碼
作者:
陳泓瑜
時間:
2018-9-26 20:41
package com.example.redabbrf.red;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class RED extends AppCompatActivity {
EditText editText, editText2, editText3;
TextView textView;
Button btn1, btn2;
double a,b,c;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_red);
editText = (EditText) findViewById(R.id.editText);
editText2 = (EditText) findViewById(R.id.editText2);
editText3 = (EditText) findViewById(R.id.editText3);
textView = (TextView) findViewById(R.id.textView);
btn1 = (Button) findViewById(R.id.button);
btn2 = (Button) findViewById(R.id.button2);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
a = Double.parseDouble(editText.getText().toString());
b = Double.parseDouble(editText2.getText().toString());
c = Double.parseDouble(editText3.getText().toString());
if(a+b>c && b+c>a && a+c>b)
{
if(a*a+b*b==c*c || c*c+b*b==a*a || a*a+c*c==b*b)
{
textView.setText(R.string.ans1);
}
else if (a*a+b*b>c*c || c*c+b*b>a*a || a*a+c*c>b*b)
{
textView.setText(R.string.ans2);
}
else
{
textView.setText(R.string.ans3);
}
}
else
{
textView.setText(R.string.ans4);
}
}
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
editText.setText("");
editText2.setText("");
editText3.setText("");
textView.setText("");
}
});
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2