鱼C论坛

 找回密码
 立即注册
查看: 4688|回复: 5

java编程题

[复制链接]
发表于 2018-4-3 16:00:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
编写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;
                }
        }

}
截图00.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-4-3 16:40:18 | 显示全部楼层
public static void maousein(String[] args) {

改成public static void main(String[] args) {
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-4-3 16:59:53 | 显示全部楼层
你的代码没有包含main方法所以不能运行,按楼上这样改
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 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)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 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)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-4-4 11:16:31 | 显示全部楼层
把details 函数移到外面去, 然后 new Book(....args); 再调用details
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-11-15 07:01

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表