在我的显示方法

时间:2017-12-25 14:16:53

标签: java

这是我的代码,它在我的显示方法中显示为null和“0”,问题是“obj.display();”是显示null或0,我不知道它有什么问题请帮我,我有一个结婚考试,我一直在练习这些概念,似乎无法解决这个问题

public class Books {

    private String nameOfBook;
    private  String author;
    private int pages;
    private int pubYear;//year publish
    private int isbn;

    public Books() {

    }

    public Books(String nameOfBook,String author,  int pages,  int pubYear, int isbn) {

        this.nameOfBook = nameOfBook;
        this.pages = pages;
        this.author = author;
        this.pubYear = pubYear;
        this.isbn = isbn;
    }

    public String getNameOfBook() {
        return nameOfBook;
    }

    public void setNameOfBook(String nameOfBook) {
        this.nameOfBook = nameOfBook;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public int getPubYear() {
        return pubYear;
    }

    public void setPubYear(int pubYear) {
        this.pubYear = pubYear;
    }

    public int getIsbn() {
        return isbn;
    }

    public void setIsbn(int isbn) {
        this.isbn = isbn;
    }

    public void display(){
        System.out.println("Book's Name: "+getNameOfBook());
        System.out.println("Pages: "+getPages());
        System.out.println("Author's Name: "+getAuthor());
        System.out.println("Year: "+getPubYear());
        System.out.println("ISBN: "+getIsbn());

    }
}

主要方法

import java.util.Scanner;

public class BookDriver {

    public static void main (String [] args){

        Scanner input= new Scanner(System.in);
        System.out.println("Enter the Book's Name: ");
        String nameOfBooks = input.nextLine();
        System.out.println("Enter the author's Name: ");
        String author = input.nextLine();
        System.out.println("Enter Number of pages: ");
        int pages = input.nextInt();
        System.out.println("Enter the publish year: ");
        int pubYear = input.nextInt();
        System.out.println("Enter the ISBN: ");
        int isbn =input.nextInt();
        Books obj= new Books();
        obj.display();
    }
}

2 个答案:

答案 0 :(得分:2)

你的构造函数是空的

  Books obj= new Books(nameOfBooks,author,pages, pubYear ,isbn   );

您应该传递正确的参数,以便显示有效 likethis

import numpy as np
a = np.random.rand(10, 4)

a[:, 3] = a[:, 3] > 0.5

a

np.array([[ 0.93011873,  0.80167023,  0.46502502,  0.        ],
       [ 0.48754049,  0.331763  ,  0.19391945,  1.        ],
       [ 0.17976529,  0.73625689,  0.6550934 ,  0.        ],
       [ 0.17797159,  0.89597292,  0.67507392,  1.        ],
       [ 0.89972382,  0.86131195,  0.85239512,  1.        ],
       [ 0.59199271,  0.14223656,  0.12101887,  1.        ],
       [ 0.71962168,  0.89132196,  0.61149278,  0.        ],
       [ 0.63606024,  0.04821054,  0.49971309,  1.        ],
       [ 0.18976505,  0.49880633,  0.93362872,  1.        ],
       [ 0.00154421,  0.79748799,  0.46080879,  0.        ]])

答案 1 :(得分:1)

Books obj = new Books(nameOfBooks, author, pages, pubYear, isbn);

应该是

{{1}}