【一键在线重装系统源码】【2022捕鱼赚钱源码】【dx轰炸源码开源】java源码分享比较经典的源码

2025-01-31 15:04:13 来源:源码为 分类:时尚

1.java源代码 求大神 明天就要上机

java源码分享比较经典的源码

java源代码 求大神 明天就要上机

       package com.uisftec;

       import java.io.Serializable;

       public class TestScores implements Serializable {

        private double[] testScores;

        public TestScores(double[] testScores) {

        this.testScores = testScores;

        }

        public double getAverageScore() {

        double sum = 0.0d;

        for (int i = 0; i < testScores.length; i++) {

        sum += testScores[i];

        }

        return sum / testScores.length;

        }

       }

       package com.uisftec;

       public class InvalidTestScore {

        public InvalidTestScore(double[] testScores) {

        if (testScores == null) {

        throw new IllegalArgumentException("数组为空");

        }

        for (int i = 0; i < testScores.length; i++) {

        if (testScores[i] < 0 || testScores[i] > ) {

        throw new IllegalArgumentException("数组中包含的test Score不在0~这个范围内");

        }

        }

        }

       }

       package com.uisftec;

       import java.io.DataOutputStream;

       import java.io.File;

       import java.io.FileInputStream;

       import java.io.FileNotFoundException;

       import java.io.FileOutputStream;

       import java.io.IOException;

       import java.io.ObjectInputStream;

       import java.io.ObjectOutput;

       import java.io.ObjectOutputStream;

       public class TestScoresSerialize {

        public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {

        // 创建5个对象

        TestScores testScores1 = new TestScores(new double[] { 1.0, 2.0 });

        TestScores testScores2 = new TestScores(new double[] { 5.0, 2.0 });

        TestScores testScores3 = new TestScores(new double[] { .0, .0 });

        TestScores testScores4 = new TestScores(new double[] { .0, .0 });

        TestScores testScores5 = new TestScores(new double[] { .0, .0 });

        // 创建数组

        TestScores[] testScores = new TestScores[] { testScores1, testScores2, testScores3, testScores4, testScores5 };

        // 写入到D盘testScores.dat

        ObjectOutput out = new ObjectOutputStream(new FileOutputStream("d:\\testscores.dat"));

        for (TestScores testScores6 : testScores) {

        out.writeObject(testScores6);

        }

        // D盘STOUT

        File file = new File("D:\\STDOUT");

        // 创建输出留

        DataOutputStream outputStream = new DataOutputStream(new FileOutputStream(file));

        // 创建读取d盘序列化对象

        ObjectInputStream in = new ObjectInputStream(new FileInputStream("d:\\testscores.dat"));

        // 打印平均分并写入到D盘STDOUT

        TestScores testScores8 = (TestScores) in.readObject();

        System.out.println(testScores8.getAverageScore());

        outputStream.writeDouble(testScores8.getAverageScore());

        TestScores testScores9 = (TestScores) in.readObject();

        outputStream.writeDouble(testScores9.getAverageScore());

        System.out.println(testScores9.getAverageScore());

        TestScores testScores = (TestScores) in.readObject();

        System.out.println(testScores.getAverageScore());

        outputStream.writeDouble(testScores.getAverageScore());

        TestScores testScores = (TestScores) in.readObject();

        System.out.println(testScores.getAverageScore());

        outputStream.writeDouble(testScores.getAverageScore());

        TestScores testScores = (TestScores) in.readObject();

        System.out.println(testScores.getAverageScore());

        outputStream.writeDouble(testScores.getAverageScore());

        // 关闭流

        out.close();

        in.close();

        outputStream.close();

        }

       }

更多资讯请点击:时尚

推荐资讯

浙江绍兴市场监管部门全力守护节日市场秩序

中国消费者报杭州讯记者施本允)“陈女士你好,我是上虞区市场监管局的工作人员,我们接到投诉说你在水果店买到了坏了的车厘子,请问具体情况是怎么样的?”这是农历正月初一发生在小越街头一家水果店的一次对话,当

王毅稱台海最危險「賴清德之流的台獨行徑」 外交部:中國是最大禍源

美國國務卿布林肯Antony Blinken)27日在聯合國大會期間,會晤中國外交部長王毅,雙方針對台海進行交談。王毅點出,台海局勢最大危險是「賴清德之流的台獨行徑」,美國國務院則持續強調維護台海和平

太阳耀斑爆发 新疆现彩色星空

太阳耀斑爆发 新疆现彩色星空2024-10-12 17:59:00评论:字体大小 T T T近日,新疆克拉玛依白杨河水库附近的胡杨林上空,繁星闪烁,如同无数颗璀璨钻石镶嵌在夜空,唯美至极!据了解,这一