一堆无效的错误,可能是因为格式原因,但我无法破解它

问题描述 投票:0回答:1
public class TicketTest
{
    int serial;
    
    public static void main(String args[])
    {
        int total_sales = 0;
                new WebTicket(10);
                new WebTicket(5);
                new CounterTicket();
                new DiscountTicket(5, "Student");
                new DiscountTicket(10, "Senior");
        
        
    }
}

class Ticket(int days, String type) {
    public static int COUNTER_TICKET_PRICE = 50; 
    public static int WEB_TICKET_PRICE = 30; 
    public static int WEB_TICKET_LT_WEEK_PRICE = 40; 
    public static double DISCOUNT = 0.5;
    int serial;
    int price;
}
class WebTicket extends Ticket {
    if (days>7) {
        price = 40;
    }else {
        price = 30;
    }
    System.out.println("Ticket: [serial= "+serial+" Price: "+price+"]");
    serial += 1;
}
class CounterTicket extends Ticket {
    price = 50;
    System.out.println("Ticket: [serial= "+serial+" Price: "+price+"]");
    serial += 1;
}
class DiscountTicket extends Ticket {
    if (days>7) {
        price = 20;
    }else {
        price = 15;
    }
    System.out.println("Ticket: [serial= "+serial+" Price: "+price+" Type: "+type+"]");
    serial += 1;
}

我正在尝试制作一个程序,在调用 main 方法中的这些类时打印票证信息,但是 Ticket 类中的“类”正在获取并出错,表示需要一条记录,并且 main 方法中的新 __Ticket 内容没有不被认出。

控制台看起来像这样:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    Syntax error, insert ". class" to complete Expression
    tickets cannot be resolved to a variable
    tickets cannot be resolved to a variable
    tickets cannot be resolved to a variable
    tickets cannot be resolved to a variable

    at test.TicketTest.main(TicketTest.java:12)

我尝试删除/添加大括号,但没有成功。可能是打字错误或者我找不到的东西。

java inheritance constructor record
1个回答
0
投票

@TrippKinetics 是的,那是我的问题。我必须在类内部创建函数才能调用构造函数,并且我试图在类中传递参数。谢谢!

© www.soinside.com 2019 - 2024. All rights reserved.