问题 解答题

某地上网有两种收费方式,用户可以任选其一:

(A)包时制:60元包30小时(该月上网不超过30小时的部分,收费为60元),超量4元/小时(该月上网时间超过30小时的部分按4元/小时计算)

(B)计时制:3元/小时设上网时间为t小时/月

(1)列代数式:计时制的每月上网费用为______元;当0<t≤30时,包时制的每月上网费用为______元.当t>30时,包时制的每月上网费用为______元;

(2)某用户计划上网50小时/月,选用哪种上网方式比较划算?

(3)当t为何值时,两种上网方式的费用相等?在什么情况下,选用计时制比较合算?

答案

(1)采用计时制应付的费用为:3t元;

当0<t≤30时,包时制的每月上网费用为60元.当t>30时,包时制的每月上网费用为60+4(t-30)=4t-60元;

(2)若一个月内上网的时间为50小时,

则计时制应付的费用为3×50=150(元)

包月制应付的费用4×50-60=140(元)

∵140<150,

∴采用包月制合算.

(3)当0<t≤30时,3t=60,解得t=20;

当t>30时,3t=4t-60,解得t=60.

答:当t=20或t=60时,两种上网方式的费用相等,当0<t<60时,选用计时制比较合算.

单项选择题
问答题

请完成以下程序,首先由一个类Example2_3实现Serializable接口,并有三个成员变量,分别为int型、double型和String型,可以用toString的方法显示这三个成员变量。在main方法中创建这个Example2_3的持久对象,根据用户在命令行输入的三个参数来设定其中成员变量的值。然后,将这个对象写入名为TheSerial.data的文件,并显示成员变量。最后从文件TheSerial.data中读出三个成员变量并显示出来。 注意:请勿改动main()主方法和其他已有语句内容,仅在横线处填入适当语句。 import java.io.*; class TheSerial implements Serializable { private int intValue; private double doubleValue; private String string; TheSerial() { intValue = 123; doubleValue = 12.34; string = "Serialize Test"; } public void setDouble(double d) { doubleValue = d; } public void setInt(int i) { intValue = i; } public void setString(String s) { string = s; } public String toString() { return("int="+intValue+"double="+doubleValue+" string="+string); } } public class Example2_3 { public static void main(String argv[]) { TheSerial e1 = new TheSerial(); TheSerial e2; try { e1.setInt(Integer.parseInt(argv[0])); e1.setDouble(Double.parseDouble(argv[1])); e1.setString[argv[2]); } catch(Exception e) { e1.setString(e.getMessage{)); } System.out.println(e1); try { FileOutputStream oS = new FileOutputStream("TheSerial.data"); ObjectOutputStream oIS = new ObjectOutputStream(oS); ______; } catch(IOException ioException) { System.out.println(ioException.getMessage()); } try { FileInputStream iS = new FileInputStream("TheSerial. data"); ObjectInputStream oIS = new ObjectInputStream(iS); ______ System.out.println(e2); } catch(IOException ioException) { System.out.println(ioException.getMessage()); } catch(ClassNotFoundException cnfException) { System.out.println(cnfException.getMessage()); } } }