zoukankan      html  css  js  c++  java
  • 第十二周课堂实践总结

    课堂测试补做

    码云链接

    代码检查:教材p300 Example10_13
     - 在长虹电视后增加一台海尔电视,价格是你学号的后四位
     - 提交运行结果截图
     - 刻下推送代码到码云
    
    • 源代码
    import java.io.*;
    public class Example10_13 {
        public static void main(String[] args) {
            TV changhong = new TV();
            TV haier = new TV();
            changhong.setName("长虹电视");
            changhong.setPrice(5678);
            haier.setName("海尔电视");
            haier.setPrice(5330);
            File file = new File("television.txt");
            try {
                FileOutputStream fileOut = new FileOutputStream(file);
                ObjectOutputStream objectOut = new ObjectOutputStream(fileOut);
                objectOut.writeObject(changhong);
                objectOut.writeObject(haier);
                objectOut.close();
                FileInputStream fileIn = new FileInputStream(file);
                ObjectInputStream objectIn = new ObjectInputStream(fileIn);
                TV xinfei = (TV)objectIn.readObject();
    
                objectIn.close();
                xinfei.setName("新飞电视");
                xinfei.setPrice(6666);
                System.out.println("changhong的名字:"+changhong.getName());
                System.out.println("changhong的价格:"+changhong.getPrice());
                System.out.println("haier的名字:"+haier.getName());
                System.out.println("haier的价格:"+haier.getPrice());
                System.out.println("xinfei的名字:"+xinfei.getName());
                System.out.println("xinfei的价格:"+xinfei.getPrice());
            }
            catch (ClassNotFoundException event) {
                System.out.println("不能读出对象");
            }
            catch (IOException event) {
                System.out.println(event);
            }
        }
    }
    
    • 结果截图
      image
    IO-myhead
    测试内容
    • 编写代码GenNumber.java生成一个文本文件“你的学号.txt”,一共“你的学号的后三位行”,每行一个数字,该数字是1-你的学号后四位的一个随机数,提交代码和生成文件
    • 研究linux的head命令, 实现head -n的功能MyHead.java,用“你的学号.txt”进行测试,执行 java MyHead n 打印“你的学号.txt”前n行
    • 编写T2B.java, 将 “你的学号.txt”的前十行转化成二进制文件“你的学号.bin”,可以用Linux 下od命令或Windows下的winhex工具查看转化结果,提交代码和生成文件
    • 编写B2T.java, 将“你的学号.bin”的转化成文本文件“你的学号.txt”, 每行除了有数据外,还要添加行号,提交代码和生成文件
    源代码
    结果
  • 相关阅读:
    接口方法上的注解无法被@Aspect声明的切面拦截的原因分析
    SpringBoot整合Netty
    简单的RPC框架
    基于redis的分布式锁的分析与实践
    8种方案解决重复提交问题
    领券中心项目,如何用 Redis 做实时订阅推送的?
    IM(即时通讯)服务端(二)
    IM(即时通讯)服务端(一)
    0xC00000FD: Stack overflow (parameters: 0x00000000, 0x003E2000).错误
    int (*a)[10]和int *a[10]的区别
  • 原文地址:https://www.cnblogs.com/besty-zyx/p/9065231.html
Copyright © 2011-2022 走看看