gpt4 book ai didi

java - Android Studio 逻辑错误

转载 作者:行者123 更新时间:2023-12-02 12:17:52 26 4
gpt4 key购买 nike

package com.karanvir.tip;

import android.graphics.Color;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;

import static com.karanvir.tip.R.drawable.p;

public class MainActivity extends AppCompatActivity {
public EditText people;

public EditText amount;
public EditText percentage;
public EditText finalAmount;
public String finalAmountz;
public RatingBar rating;
public TextView txt;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

people=(EditText) findViewById(R.id.editText);
amount=(EditText) findViewById(R.id.editText2);
percentage=(EditText) findViewById(R.id.editText3);
finalAmount=(EditText) findViewById(R.id.editText6);
rating=(RatingBar) findViewById(R.id.ratingBar);
//ratingBar.setRating(3);
txt=(TextView) findViewById(R.id.textView);


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

public void calc(View view){

try{
double pep= Double.parseDouble(people.getText().toString());
double a=Double.parseDouble(amount.getText().toString());
double perc=Double.parseDouble(percentage.getText().toString());
double percc=Double.parseDouble(percentage.getText().toString());


if(pep>1||pep==1){
if(perc>1.0) {
double aa=a;
perc = perc / 100;
a = (a * perc);
double newamount=a+aa;
double placeholder = newamount / pep;
double rounder = Math.round(placeholder);


finalAmountz = "$" + String.valueOf(rounder);
finalAmount.setText(finalAmountz.toString());

if (perc>0.12) {
rating.setRating(5);
rating.setVisibility(View.VISIBLE);
txt.setVisibility(View.VISIBLE);
}
else if (perc>0.10&&perc<0.12||perc==0.10) {
rating.setRating(4);
rating.setVisibility(View.VISIBLE);
txt.setVisibility(View.VISIBLE);
}
else if (perc>0.7&&perc<0.10||perc==0.07) {
rating.setRating(3);
rating.setVisibility(View.VISIBLE);
txt.setVisibility(View.VISIBLE);
}
else if (perc>0.05&&perc<0.07||perc==0.05) {
rating.setRating(2);
rating.setVisibility(View.VISIBLE);
txt.setVisibility(View.VISIBLE);
}
if (perc<0.05) {
rating.setRating(1);
rating.setVisibility(View.VISIBLE);
txt.setVisibility(View.VISIBLE);
}


}



}
else if (pep<1||pep==1){
Toast.makeText(MainActivity.this, "Please Enter 1 person minimum", Toast.LENGTH_SHORT).show();
}


}catch (Exception e){
Toast.makeText(MainActivity.this, e.toString(), Toast.LENGTH_SHORT).show();

}


}
}

请不要在这里撕裂我。但我是 Android 开发新手。我现在正在制作一个小费计算器应用程序,一切都按照我想要的方式运行。然而,我的星星计算已关闭。一直显示1星?请看第 72-117 行。有人能帮我吗?抱歉提出了菜鸟问题,我还在学习中。

package com.karanvir.tip;

import android.graphics.Color;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;

import static com.karanvir.tip.R.drawable.p;

public class MainActivity extends AppCompatActivity {
public EditText people;

public EditText amount;
public EditText percentage;
public EditText finalAmount;
public String finalAmountz;
public RatingBar rating;
public TextView txt;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

people=(EditText) findViewById(R.id.editText);
amount=(EditText) findViewById(R.id.editText2);
percentage=(EditText) findViewById(R.id.editText3);
finalAmount=(EditText) findViewById(R.id.editText6);
rating=(RatingBar) findViewById(R.id.ratingBar);
//ratingBar.setRating(3);
txt=(TextView) findViewById(R.id.textView);


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

public void calc(View view){

try{
double pep= Double.parseDouble(people.getText().toString());
double a=Double.parseDouble(amount.getText().toString());
double perc=Double.parseDouble(percentage.getText().toString());


if(pep>1||pep==1){
if(perc>1.0) {
double aa=a;
perc = perc / 100;
a = (a * perc);
double newamount=a+aa;
double placeholder = newamount / pep;
double rounder = Math.round(placeholder);


finalAmountz = "$" + String.valueOf(rounder);
finalAmount.setText(finalAmountz.toString());

if (perc>12) {
rating.setRating(5);
rating.setVisibility(View.VISIBLE);
txt.setVisibility(View.VISIBLE);
}
if (perc>10&&perc<12||perc==10) {
rating.setRating(4);
rating.setVisibility(View.VISIBLE);
txt.setVisibility(View.VISIBLE);
}
if (perc>7&&perc<10||perc==7) {
rating.setRating(3);
rating.setVisibility(View.VISIBLE);
txt.setVisibility(View.VISIBLE);
}
if (perc>5&&perc<7||perc==5) {
rating.setRating(2);
rating.setVisibility(View.VISIBLE);
txt.setVisibility(View.VISIBLE);
}
if (perc<5) {
rating.setRating(1);
rating.setVisibility(View.VISIBLE);
txt.setVisibility(View.VISIBLE);
}


}
else if(perc<=1.0){
double aa=a;
a = (a * perc);
double newamount=a+aa;
double placeholder = newamount / pep;
double rounder = Math.round(placeholder);
finalAmountz = "$" + String.valueOf(rounder);
finalAmount.setText(finalAmountz.toString());



finalAmountz = "$" + String.valueOf(rounder);
finalAmount.setText(finalAmountz.toString());
if (perc>12)
rating.setRating(5);
rating.setVisibility(View.VISIBLE);
txt.setVisibility(View.VISIBLE);
if (perc>10&&perc<12||perc==10)
rating.setRating(4);
rating.setVisibility(View.VISIBLE);
txt.setVisibility(View.VISIBLE);
if (perc>7&&perc<10||perc==7)
rating.setRating(3);
rating.setVisibility(View.VISIBLE);
txt.setVisibility(View.VISIBLE);
if (perc>5&&perc<7||perc==5)
rating.setRating(2);
rating.setVisibility(View.VISIBLE);
txt.setVisibility(View.VISIBLE);
if (perc<5)
rating.setRating(1);
rating.setVisibility(View.VISIBLE);
txt.setVisibility(View.VISIBLE);


}


}
else if (pep>1){
Toast.makeText(MainActivity.this, "Please Enter 1 person minamum", Toast.LENGTH_SHORT).show();
}


}catch (Exception e){
Toast.makeText(MainActivity.this, e.toString(), Toast.LENGTH_SHORT).show();

}


}
}

最佳答案

您正在将 perc 除以 100

if(pep>1||pep==1){
if(perc>1.0) {
double aa=a;
perc = perc / 100;
....

除非您输入的值高于500,否则其值将始终低于 5(您的最后条件),因此始终给予 1 星

关于java - Android Studio 逻辑错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46022631/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com