首页 > 电脑 > java问题,求代码,真心

java问题,求代码,真心

电脑 2023-11-17

JAVA题目,求代码。

只发主函数代码 public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("输入本金数目:"); double count = sc.nextDouble(); System.out.println("一年到期本息总和为:" + count * 1.0225); System.out.println("两年到期本息总和为:" + count * Math.pow(1.027, 2)); System.out.println("三年到期本息总和为:" + cou

java的问题,求代码

String本身就有。 ~ ~~~~~~ ~~~~~~~~~~ ~~~~

java难题,急,求代码?

接口和类全在一个包下,如果不在一个包下记得import调用,show的重写你根据需要自己改

//ShouFei接口
publicinterfaceShouFei{
publicvoidfuFei(doublemileage);
publicvoidshow();
}
//Bus类
publicclassBusimplementsShouFei{
StringairConditioning;
doublemoney;
publicBus(StringairConditioning){
this.airConditioning=airConditioning;
}
@Override
publicvoidfuFei(doublemileage){
if(airConditioning.equals("空调")){
money=2;
}else{
money=1;
}
}
@Override
publicvoidshow(){
System.out.println("公交车,"+airConditioning+",费用:"+money);
}
}
//Taxi类
publicclassTaxiimplementsShouFei{
doublemileage;
booleanisDay;
doublemoney;
publicTaxi(booleanisDay){
this.isDay=isDay;
}
@Override
publicvoidfuFei(doublemileage){
this.mileage=mileage;
//判断是否为白天
if(isDay){
//判断里程数是否大于三公里
if(mileage<3){
money=8;
}else{
money=8+(mileage-3)*1.5;
}
}else{
if(mileage<3){
money=10;
}else{
money=10+(mileage-3)*1.5;
}
}
}
@Override
publicvoidshow(){
System.out.print("出租车,");
if(isDay){
System.out.print("白天");
}else{
System.out.print("晚上");
}
System.out.println(",里程数:"+mileage+"收费:"+money);
}
}
//测试类
publicclassTest{
publicstaticvoidmain(String[]args){
Busbus=newBus("空调");
bus.fuFei(10);
bus.show();
Taxitaxi=newTaxi(true);
taxi.fuFei(20);
taxi.show();
}
}

JAVA编程问题,求一个题的全部代码

publicclassStudent{

privateStringname;

privateintid;

privatedoubleenglishScore;

privatedoublechineseScore;

privatedoublemathScore;
publicStudent(Stringname,intid,doubleenglishScore,doublechineseScore,doublemathScore){
super();
this.name=name;
this.id=id;
this.englishScore=englishScore;
this.chineseScore=chineseScore;
this.mathScore=mathScore;
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicintgetId(){
returnid;
}
publicvoidsetId(intid){
this.id=id;
}
publicdoublegetEnglishScore(){
returnenglishScore;
}
publicvoidsetEnglishScore(doubleenglishScore){
this.englishScore=englishScore;
}
publicdoublegetChineseScore(){
returnchineseScore;
}
publicvoidsetChineseScore(doublechineseScore){
this.chineseScore=chineseScore;
}
publicdoublegetMathScore(){
returnmathScore;
}
publicvoidsetMathScore(doublemathScore){
this.mathScore=mathScore;
}


publicdoublegetsumScore(){

returnenglishScore+chineseScore+mathScore;
}

}
importjava.util.Scanner;
publicclassStudentDemo{

privateStudent[]datas;

publicvoidinputData(){

Scannerscanner=newScanner(System.in);

System.out.println("请输入学生个数:");

intstudentNum=scanner.nextInt();

datas=newStudent[studentNum];

for(inti=0;i
System.out.println("请输入学生学号:");

intid=scanner.nextInt();

System.out.println("请输入学生姓名:");

Stringname=scanner.next();

System.out.println("请输入学生英语成绩:");

doubleenglishScore=scanner.nextDouble();

System.out.println("请输入学生数学成绩:");

doublemathScore=scanner.nextDouble();

System.out.println("请输入语文成绩:");

doublechineseScore=scanner.nextDouble();

Studentstudent=newStudent(name,id,englishScore,chineseScore,mathScore);

datas[i]=student;

}

}

publicStringgetScores(){

StringBuffersb=newStringBuffer();

for(inti=0;i
sb.append("学生"+datas[i].getName()+"的总分是:"+datas[i].getsumScore()+",");

}

returnsb.toString();

}


publicdoublegetAllAvgScore(){


intlen=datas.length;

doublesum=0;

for(inti=0;i
sum+=datas[i].getsumScore();

}

doubleavg=sum/len;

returnavg;

}


publicdouble[]getEachavgScore(){

intlen=datas.length;

doublechinessum=0;

doublemathsum=0;

doubleenglishsum=0;

for(inti=0;i
chinessum+=datas[i].getChineseScore();

mathsum+=datas[i].getMathScore();

englishsum+=datas[i].getEnglishScore();
}

doublechinAvg=chinessum/len;

doublemathAvg=mathsum/len;

doubleenglishAvg=englishsum/len;

double[]avgs={chinAvg,mathAvg,englishAvg};

returnavgs;

}

}
publicclassTest{

publicstaticvoidmain(String[]args){

StudentDemodemo=newStudentDemo();

demo.inputData();

Stringscores=demo.getScores();

System.out.println(scores);

double[]eachavgScore=demo.getEachavgScore();

System.out.println("语文的平均总分是:"+eachavgScore[0]);
System.out.println("数学的平均总分是:"+eachavgScore[1]);
System.out.println("英语的平均总分是:"+eachavgScore[2]);

doubleallAvgScore=demo.getAllAvgScore();

System.out.println("全班的平均总分是"+allAvgScore);

}
}
结果:
请输入学生个数:
3
请输入学生学号:
0001
请输入学生姓名:
李晓明
请输入学生英语成绩:
78
请输入学生数学成绩:
88
请输入语文成绩:
69
请输入学生学号:
0002
请输入学生姓名:
张华
请输入学生英语成绩:
97
请输入学生数学成绩:
88
请输入语文成绩:
86
请输入学生学号:
0003
请输入学生姓名:
余小慧
请输入学生英语成绩:
78
请输入学生数学成绩:
98
请输入语文成绩:
65
学生晓明的总分是:235.0,学生张华的总分是:271.0,学生余小慧的总分是:241.0,
语文的平均总分是:73.33333333333333
数学的平均总分是:91.33333333333333
英语的平均总分是:84.33333333333333
全班的平均总分是249.0

java 代码

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; public class Emp { private String id; private int age; private String sex; public Emp(String id, int age, String sex) { this.id = id; this.age = age; this.sex = sex; } public int ge

标签:Java 编程 Java编程 信息技术

大明白知识网 Copyright © 2020-2022 www.wangpan131.com. Some Rights Reserved. 京ICP备11019930号-18