환율을 계산해주는 코드입니다.
단점으로는 변하는 환율값을 실시간으로 반영해주지 못하고 수기로 직접 변경해주어야한다는 치명정인 단점을 가지고 있습니다.
package com.example.currency_converter;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private EditText myText;
private TextView notice;
private RadioGroup RB_group_from, RB_group_to;
private RadioButton RB_from_won, RB_from_dollar, RB_from_euro, RB_from_yen;
private RadioButton RB_to_won, RB_to_dollar, RB_to_euro, RB_to_yen;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myText = (EditText) findViewById(R.id.myText);
notice = (TextView) findViewById(R.id.notice_design);
RB_group_from = (RadioGroup) findViewById(R.id.rb_group_from);
RB_group_to = (RadioGroup) findViewById(R.id.rb_group_to);
RB_from_won = (RadioButton) findViewById(R.id.rb_from_wons);
RB_from_dollar = (RadioButton) findViewById(R.id.rb_from_dollar);
RB_from_euro = (RadioButton) findViewById(R.id.rb_from_euro);
RB_from_yen = (RadioButton) findViewById(R.id.rb_from_yen);
RB_to_won = (RadioButton) findViewById(R.id.rb_to_won);
RB_to_dollar = (RadioButton) findViewById(R.id.rb_to_dollar);
RB_to_euro = (RadioButton) findViewById(R.id.rb_to_euro);
RB_to_yen = (RadioButton) findViewById(R.id.rb_to_yen);
}
public void click_0 (View view){myText.setText(myText.getText()+"0");}
public void click_1 (View view){myText.setText(myText.getText()+"1");}
public void click_2 (View view){myText.setText(myText.getText()+"2");}
public void click_3 (View view){myText.setText(myText.getText()+"3");}
public void click_4 (View view){myText.setText(myText.getText()+"4");}
public void click_5 (View view){myText.setText(myText.getText()+"5");}
public void click_6 (View view){myText.setText(myText.getText()+"6");}
public void click_7 (View view){myText.setText(myText.getText()+"7");}
public void click_8 (View view){myText.setText(myText.getText()+"8");}
public void click_9 (View view){myText.setText(myText.getText()+"9");}
public void click_convert(View view){
String input_string = myText.getText().toString();
if(input_string.length()!=0) {
notice.setText("");
float input_currency = Float.parseFloat(input_string);
float output_currency = 0.0f;
if (RB_from_won.isChecked()) {
if (RB_to_dollar.isChecked()) {
output_currency = input_currency *0.00077f;
myText.setText(input_currency+" won = " + String.valueOf(output_currency) + "dollar");
}
else if (RB_to_euro.isChecked()){
output_currency = input_currency * 0.00071f;
myText.setText(input_currency + " won = " +String.valueOf(output_currency) + "eruo");
}
else if (RB_to_yen.isChecked()){
output_currency = input_currency * 0.10f;
myText.setText(input_currency + " won = " +String.valueOf(output_currency) + "yen");
}
else {
notice.setText("Please make your choice");
}
}
else if(RB_from_dollar.isChecked()){
if(RB_to_won.isChecked()) {
output_currency = input_currency * 1297.69f;
myText.setText(input_currency+" dollar = " + String.valueOf(output_currency) + "won");
}
else if(RB_to_euro.isChecked()) {
output_currency = input_currency * 0.92f;
myText.setText(input_currency+" dollar = " + String.valueOf(output_currency) + "eruo");
}
else if(RB_to_yen.isChecked()) {
output_currency = input_currency * 131.01f;
myText.setText(input_currency+" dollar = " + String.valueOf(output_currency) + "yen");
}
else {
notice.setText("Please make your choice");
}
}
else if(RB_from_euro.isChecked()) {
if (RB_to_won.isChecked()) {
output_currency = input_currency * 1404.80f;
myText.setText(input_currency + " eruo = " + String.valueOf(output_currency) + "won");
} else if (RB_to_dollar.isChecked()) {
output_currency = input_currency * 1.08f;
myText.setText(input_currency + " eruo = " + String.valueOf(output_currency) + "dollar");
} else if (RB_to_yen.isChecked()) {
output_currency = input_currency * 141.76f;
myText.setText(input_currency + " eruo = " + String.valueOf(output_currency) + "yens");
} else {
notice.setText("Please make your choice");
}
}
else if(RB_from_yen.isChecked()) {
if (RB_to_won.isChecked()) {
output_currency = input_currency * 9.91f;
myText.setText(input_currency + " yen = " + String.valueOf(output_currency) + "won");
} else if (RB_to_dollar.isChecked()) {
output_currency = input_currency * 0.0076f;
myText.setText(input_currency + " yen = " + String.valueOf(output_currency) + "dollar");
} else if (RB_to_euro.isChecked()) {
output_currency = input_currency * 0.0071f;
myText.setText(input_currency + " yen = " + String.valueOf(output_currency) + "euro");
} else {
notice.setText("Please make your choice");
}
}
else {
notice.setText("Please make your choice");
}
}
else {
notice.setText("Please insert an amount");
}
}
public void click_dot(View view) {
String myText_string = myText.getText().toString();
if (!myText_string.contains(".")) {
myText.setText(myText.getText() + ".");
}
}
public void click_clear(View view)
{
myText.setText("");
notice.setText("");
RB_group_to.clearCheck();
RB_group_from.clearCheck();
RB_to_won.setEnabled(true);
RB_to_dollar.setEnabled(true);
RB_to_euro.setEnabled(true);
RB_to_yen.setEnabled(true);
}
public void click_rb_from_won(View view)
{
RB_to_won.setEnabled(false);
RB_to_dollar.setEnabled(true);
RB_to_euro.setEnabled(true);
RB_to_yen.setEnabled(true);
RB_group_to.clearCheck();
}
public void click_rb_from_dollar(View view)
{
RB_to_won.setEnabled(true);
RB_to_dollar.setEnabled(false);
RB_to_euro.setEnabled(true);
RB_to_yen.setEnabled(true);
RB_group_to.clearCheck();
}
public void click_rb_from_euro(View view)
{
RB_to_won.setEnabled(true);
RB_to_dollar.setEnabled(true);
RB_to_euro.setEnabled(false);
RB_to_yen.setEnabled(true);
RB_group_to.clearCheck();
}
public void click_rb_from_yen(View view)
{
RB_to_won.setEnabled(true);
RB_to_dollar.setEnabled(true);
RB_to_euro.setEnabled(true);
RB_to_yen.setEnabled(false);
RB_group_to.clearCheck();
}
}
'실시간 운영체제' 카테고리의 다른 글
[실시간 운영체제] 연산 확인 작업 (pt.2) (0) | 2023.04.27 |
---|---|
[실시간 운영체제] 계산기 (0) | 2023.04.27 |
[실시간 운영체제] 연산 확인 작업 (pt.1) (0) | 2023.04.27 |
[실시간 운영체제] 길이 변환기 (0) | 2023.04.27 |
[실시간 운영체제] 온도 변환기 (0) | 2023.04.27 |