晨曦到日暮 发表于 2018-4-3 16:00:33

java编程题

编写Book类,要求类具有书名,书号,主编,出版社,出版时间,页码,价格,其中页数不能少于250页,否则输出错误信息;具有detail方法,用来在控制台输出每本书的信息


package 练习;

public class Book {
private String title;
private int num;
private String maineditor;
private String publishinghouse;
private int publishtime;
private int pagenumber;
private int price;
public Book(String ptitle, int pnum,String pmaineditor,String ppublishinghouse,int ppublishtime,int ppagenumber,int pprice) {
title = ptitle;
num = pnum;
maineditor = pmaineditor;
publishinghouse = ppublishinghouse;
publishtime =ppublishtime;
pagenumber = ppagenumber;
price = pprice;
}
        public static void maousein(String[] args) {
                public String details() {
                return"这本书的名称是"+title+"这本书的书号是"+num+"这本书的主编是"+maineditor+"这本书的出版社是"+publishinghouse+"这本书的出版时间"
                        是"+publishtime+"这本书的页码是"+这本书的价格是+"price;
                }
                if(pageumber<200) {
                        System.out.println("错误");
                }// TODO Auto-generated method stub
                else {
                        this.pagenumber=pagenumber;
                }
        }

}

nzdf 发表于 2018-4-3 16:40:18

public static void maousein(String[] args) {

改成public static void main(String[] args) {

夜色下的俯瞰 发表于 2018-4-3 16:59:53

你的代码没有包含main方法所以不能运行,按楼上这样改

晨曦到日暮 发表于 2018-4-3 18:16:05

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
        Syntax error on token "details", AnnotationName expected after this token
        Illegal modifier for parameter details; only final is permitted
        Syntax error, insert "[ ]" to complete Dimension
        Syntax error, insert ";" to complete BlockStatements
        Cannot make a static reference to the non-static field title
        Cannot make a static reference to the non-static field num
        Cannot make a static reference to the non-static field maineditor
        Cannot make a static reference to the non-static field publishinghouse
        Syntax error on tokens, delete these tokens
        pageumber cannot be resolved to a variable
        Cannot use this in a static context
        Cannot make a static reference to the non-static field pagenumber

        at 练习.Book.main(Book.java:21)

晨曦到日暮 发表于 2018-4-3 18:18:12

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
        Syntax error on token "details", AnnotationName expected after this token
        Illegal modifier for parameter details; only final is permitted
        Syntax error, insert "[ ]" to complete Dimension
        Syntax error, insert ";" to complete BlockStatements
        Cannot make a static reference to the non-static field title
        Cannot make a static reference to the non-static field num
        Cannot make a static reference to the non-static field maineditor
        Cannot make a static reference to the non-static field publishinghouse
        Syntax error, insert ";" to complete BlockStatements
        String literal is not properly closed by a double-quote
        Syntax error, insert "VariableDeclarators" to complete LocalVariableDeclaration
        Syntax error, insert ";" to complete LocalVariableDeclarationStatement

        at 练习.Book.main(Book.java:21)

wencongsheng 发表于 2018-4-4 11:16:31

把details 函数移到外面去, 然后 new Book(....args); 再调用details
页: [1]
查看完整版本: java编程题