
无聊哦~~~
三楼说的不错!方法重载是指参数的个数与类型不一样!所以13题应该是A,不过1题就是看不准那个下划线或减号了,呜呜~~
第一题public class AirCondition extends Device {
private String dName//空调名称
private String address//空调厂家
private double price//空调价格
private int temperature//空调的温度
public AirCondition(String dName, String address,double price,int temperature) {
this.dName = dName
this.address = address
this.price = price
this.temperature = temperature
}
//给空调升温temp度
public void raiseTemp (int temp) {
this.temperature += temp
}
//给空调降温temp度
public double lowerTemp(int temp) {
return this.temperature -= temp
}
public String getdName() {
return dName
}
public void setdName(String dName) {
this.dName = dName
}
public String getAddress() {
return address
}
public void setAddress(String address) {
this.address = address
}
public double getPrice() {
return price
}
public void setPrice(double price) {
this.price = price
}
public int getTemperature() {
return temperature
}
public void setTemperature(int temperature) {
this.temperature = temperature
}
public String toString() {
StringBuffer r = new StringBuffer()
r.append("设备名称: " + getdName() + "\n")
r.append("出厂厂家: " + getAddress() + "\n")
r.append("价格: " + getPrice() + "\n")
r.append("初始温度: " + getTemperature() + "\n")
return r.toString()
}
}
第二题
import java.io.DataInputStream
import java.io.FileInputStream
public class Score {
private Object[][] data = new Object[10][2]//存放学好和密码
public static void main(String[] args) {
new Score().readData()
}
//读取数据
public void readData(){
DataInputStream dis = null
try {
dis = new DataInputStream(new FileInputStream("studentdata"))
for(int i = 0i <data.lengthi++){
data[i][0] = dis.readUTF()//学好
data[i][1] = dis.readInt()//密码
}
//调用计算
calc()
} catch (Exception e) {
e.printStackTrace()
}
}
//计算
public void calc(){
int total = 0
double avg = 0
int max = 0
int min = 0
Object[] temp
for (int i = 0i <data.lengthi++) {
for (int j = 0j <data.length - 1j++) {
if((Integer)(data[j][1]) > (Integer)(data[j + 1][1])){
temp = data[j]
data[j] = data[j + 1]
data[j + 1] = temp
}
}
}
for (int i = 0i <data.lengthi++) {
total += (Integer)data[i][1]
System.out.println("学号: " + data[i][0] + "\t" + "分数: " + data[i][1])
}
avg = total / data.length//平均
min = (Integer)data[0][1]
max = (Integer)data[data.length - 1][1]
System.out.println("最高分: " + max)
System.out.println("最低分: " + min)
System.out.println("平均分: " + avg)
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)