Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 有没有办法在我的代码中使用视频类_Java_Arrays - Fatal编程技术网

Java 有没有办法在我的代码中使用视频类

Java 有没有办法在我的代码中使用视频类,java,arrays,Java,Arrays,我无法在我的程序中使用视频类。我的代码运行良好,但根据问题,我应该使用视频类 但是我没有使用它就得到了想要的输出 videoStore扩展了video类,但没有使用video类的方法。每次执行后,videoStore数组值都会重置,我不知道为什么 class VideoStore extends Video{ String videoStore[]=new String[100]; int rating[]=new int[100]; boolean status[]=n

我无法在我的程序中使用视频类。我的代码运行良好,但根据问题,我应该使用视频类

但是我没有使用它就得到了想要的输出

videoStore扩展了video类,但没有使用video类的方法。每次执行后,videoStore数组值都会重置,我不知道为什么

class VideoStore extends Video{
    String videoStore[]=new String[100];
    int rating[]=new int[100];
    boolean status[]=new boolean[100];
    int i=0,ind=0,len=-1;
    VideoStore(String name) {
        super(name);
    }
    void addVideo(String name){
        videoStore[i]=name;
        status[i]=false;
        i++;
        len++;


    }
    void doCheckout(String name){
        if(len>=0){
        int index=index(name);
        status[index]=true;
        }
        else{
            System.out.println("Nothig in inventory");
        }

    }
    void doReturn(String name){
        if(len>=0){
        int index=index(name);
        status[index]=false;
        }
        else{
            System.out.println("Nothing in inventory");
        }

    }
    void receiveRating(String name,int rating){
        if(len>=0){
        int index=index(name);
        this.rating[index]=rating;
        }
        else{
            System.out.println("Nothing in inventory");
        }
    }
    void listInventory(){
        if(len!=-1){
        for(int p=0;p<=len;p++){
            System.out.println(videoStore[p]+"\t"+status[p]+"\t"+rating[p]);
        }
        }
        else{
            System.out.println("nothing in inventory");
        }

    }
    int index(String name){
        for (int i = 0; i < videoStore.length; i++) {
            if(videoStore[i].equals(name)){
                return i;
            }
        }
        return -1;
    }

 }

我不会给你全部的代码,只是让你开始

当VideoStore扩展了你们所说的视频时,VideoStore是一个错误的视频,你们想说的是VideoStore有视频。您需要的是视频商店中的视频列表

所以你的视频商店应该是这样的:

class VideoStore {
    Video[] videos = new Video[100];

    void addVideo(String name) {
        Video v = new Video(name);
        for(int i=0; i<videos.length; i++) {
            if(videos[i] == null) {
                videos[i] = v;
                break;
            }
        }
    }

    void doCheckout(String name) {
        int index = index(name);
        videos[index].setCheckout(true);
    }

    void doReturn(String name) {
        // your code
    }

    void receiveRating(String name, int rating) {
        // your code
    }

    void listInventory() {
       // your code
    }

    int index(String name) {
        // your code
    }

}
对于你的审问:

videoStore数组值在每次执行后都会重置我不知道为什么

class VideoStore extends Video{
    String videoStore[]=new String[100];
    int rating[]=new int[100];
    boolean status[]=new boolean[100];
    int i=0,ind=0,len=-1;
    VideoStore(String name) {
        super(name);
    }
    void addVideo(String name){
        videoStore[i]=name;
        status[i]=false;
        i++;
        len++;


    }
    void doCheckout(String name){
        if(len>=0){
        int index=index(name);
        status[index]=true;
        }
        else{
            System.out.println("Nothig in inventory");
        }

    }
    void doReturn(String name){
        if(len>=0){
        int index=index(name);
        status[index]=false;
        }
        else{
            System.out.println("Nothing in inventory");
        }

    }
    void receiveRating(String name,int rating){
        if(len>=0){
        int index=index(name);
        this.rating[index]=rating;
        }
        else{
            System.out.println("Nothing in inventory");
        }
    }
    void listInventory(){
        if(len!=-1){
        for(int p=0;p<=len;p++){
            System.out.println(videoStore[p]+"\t"+status[p]+"\t"+rating[p]);
        }
        }
        else{
            System.out.println("nothing in inventory");
        }

    }
    int index(String name){
        for (int i = 0; i < videoStore.length; i++) {
            if(videoStore[i].equals(name)){
                return i;
            }
        }
        return -1;
    }

 }

这是正常的,它们只在内存中,一旦程序终止就会被删除。

要使用Video类方法,必须使用VideoStore like Video vs=new VideoStorevideoName了解更多有关继承和多态行为的信息[我在程序中没有发现任何错误。它对我来说运行良好。如果你说的数组值在每次执行后都会被重置,那么在完成程序值丢失后,我想告诉你java只在内存中存储数据。对于永久存储,你需要数据库。代码正在运行,但我有什么办法可以利用吗当VideoStore扩展视频时,你说VideoStore是一个错误的视频,你想说的是VideoStore有视频。你需要的是VideoStore中的视频列表,但你可以通过从每个案例中删除y/n提示符并将其放在后面,大大简化你的切换语句开关。
class VideoStore {
    Video[] videos = new Video[100];

    void addVideo(String name) {
        Video v = new Video(name);
        for(int i=0; i<videos.length; i++) {
            if(videos[i] == null) {
                videos[i] = v;
                break;
            }
        }
    }

    void doCheckout(String name) {
        int index = index(name);
        videos[index].setCheckout(true);
    }

    void doReturn(String name) {
        // your code
    }

    void receiveRating(String name, int rating) {
        // your code
    }

    void listInventory() {
       // your code
    }

    int index(String name) {
        // your code
    }

}