Java面向对象程序设计.哪位JAVA高手,帮我做一下下面的试题...

Java面向对象程序设计.哪位JAVA高手,帮我做一下下面的试题...,第1张

1、B;2、C;3、B;4、B;5、B;6、C;7、B;8、C;9、C;10、A;11、D;12、D;13、B;14、A;15、D

无聊哦~~~

三楼说的不错!方法重载是指参数的个数与类型不一样!所以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)

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/11149130.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-14
下一篇2023-05-14

发表评论

登录后才能评论

评论列表(0条)

    保存