菜鸟求助:java小程序,怎么改进?
classStudent{Stringname;intage;intsum=0;intave=0;intChinese;intEnglish;intMath;public...
class Student
{
String name;
int age;
int sum=0;
int ave=0;
int Chinese;
int English;
int Math;
public void show(String name,int age)
{
this.name=name;
this.age=age;
System.out.printf("姓名:"+this.name,"年龄"+this.age);
}
public void total(int Chinese,int English,int Math)
{
sum= Chinese+English+Math;
//return sum;
}
int average(int sum)
{
ave=sum/3;
return ave;
}
}
public class test22 {
/**
* @param args
*/
public static void main(String[] args) {
Student per1=new Student();
per1.show("张三",30);
per1.sum=188;
System.out.printf("总分为:"+per1.sum);
System.out.printf("平均分:"per1.average(sum));
}
}
预期效果如下:
----------------------------------------------
姓名:张三,30岁
总分:** ,平均分:** 展开
{
String name;
int age;
int sum=0;
int ave=0;
int Chinese;
int English;
int Math;
public void show(String name,int age)
{
this.name=name;
this.age=age;
System.out.printf("姓名:"+this.name,"年龄"+this.age);
}
public void total(int Chinese,int English,int Math)
{
sum= Chinese+English+Math;
//return sum;
}
int average(int sum)
{
ave=sum/3;
return ave;
}
}
public class test22 {
/**
* @param args
*/
public static void main(String[] args) {
Student per1=new Student();
per1.show("张三",30);
per1.sum=188;
System.out.printf("总分为:"+per1.sum);
System.out.printf("平均分:"per1.average(sum));
}
}
预期效果如下:
----------------------------------------------
姓名:张三,30岁
总分:** ,平均分:** 展开
4个回答
展开全部
class Student {
String name;
int age;
int sum = 0;
int ave = 0;
int Chinese;
int English;
int Math;
public void show(String name, int age) {
this.name = name;
this.age = age;
System.out.println("姓名:" + this.name+"," + this.age+"岁");
}
public void total(int Chinese, int English, int Math) {
sum = Chinese + English + Math;
}
int average() {
ave = sum / 3;
return ave;
}
}
public class test22 {
/**
* @param args
*/
public static void main(String[] args) {
Student per1 = new Student();
per1.show("张三", 30);
per1.total(80, 60, 90);
System.out.printf("总分:" + per1.sum);
System.out.printf(",平均:" + per1.average());
}
}
String name;
int age;
int sum = 0;
int ave = 0;
int Chinese;
int English;
int Math;
public void show(String name, int age) {
this.name = name;
this.age = age;
System.out.println("姓名:" + this.name+"," + this.age+"岁");
}
public void total(int Chinese, int English, int Math) {
sum = Chinese + English + Math;
}
int average() {
ave = sum / 3;
return ave;
}
}
public class test22 {
/**
* @param args
*/
public static void main(String[] args) {
Student per1 = new Student();
per1.show("张三", 30);
per1.total(80, 60, 90);
System.out.printf("总分:" + per1.sum);
System.out.printf(",平均:" + per1.average());
}
}
展开全部
修改2句即可
1
System.out.printf("姓名:"+this.name + ", 年龄"+this.age);
2
System.out.printf("平均分:" + per1.average(per1.sum));
1
System.out.printf("姓名:"+this.name + ", 年龄"+this.age);
2
System.out.printf("平均分:" + per1.average(per1.sum));
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
简化后的代码:
public class Student {
String name;
int age;
int sum=0;
int ave=0;
int Chinese;
int English;
int Math;
public Student(String string, int i, int j) {
this.name=string;
this.age=i;
this.sum =j;
System.out.println("姓名:"+this.name+",年龄: "+this.age);
}
public void show(String name,int age)
{
}
public void total(int Chinese,int English,int Math)
{
sum= Chinese+English+Math;
//return sum;
}
int average(int sum)
{
ave=sum/3;
return ave;
}
}
public static void main(String[] args) {
Student per1=new Student("张三",30,188);
System.out.println("总分为:"+per1.sum+", 平均分:"+per1.average(per1.sum));
}
}
public class Student {
String name;
int age;
int sum=0;
int ave=0;
int Chinese;
int English;
int Math;
public Student(String string, int i, int j) {
this.name=string;
this.age=i;
this.sum =j;
System.out.println("姓名:"+this.name+",年龄: "+this.age);
}
public void show(String name,int age)
{
}
public void total(int Chinese,int English,int Math)
{
sum= Chinese+English+Math;
//return sum;
}
int average(int sum)
{
ave=sum/3;
return ave;
}
}
public static void main(String[] args) {
Student per1=new Student("张三",30,188);
System.out.println("总分为:"+per1.sum+", 平均分:"+per1.average(per1.sum));
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
确定内部类能这么用?为什么不分开写。这种代码不可取啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询