gpt4 book ai didi

java - 当该程序显示无法找到或加载主类时,如何使该程序运行?

转载 作者:行者123 更新时间:2023-12-01 19:38:59 25 4
gpt4 key购买 nike

我对 Java 很陌生,我不断收到此错误,但我无法弄清楚。

Error: Could not find or load main class restaurantclient.RestaurantClient Java Result: 1

这是在 Netbeans 上进行的,我确信我所做的一切都是正确的。这是我的 Java 类(class)作业,我非常感谢您的帮助。我已经研究这个问题好几天了。

import java.text.DecimalFormat;

public class RestaurantClient {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Restaurant r1;
Restaurant r2;
r1 = new Restaurant("PizzaHut", 152, (float) 4.95); //instantiating
r2 = new Restaurant("Dominos", 10, (float) 3.657);
System.out.print(r1.toString());
System.out.print(r2.toString());
r2.setPeopleServed(r1.getPeopleServed());
r2.setAveragePrice(r1.getAverageMeal());
if (r1.equals(r2)) //checking if equal
System.out.println("\nThe two objects are the same");
else
System.out.println("\nThe two objects are NOT the same");
r2.setName(r1.getName());
if (r1.equals(r2)) //checking if equal
System.out.println("\nThe two objects are the same");
else
System.out.println("\nThe two objects are NOT the same");
DecimalFormat pricePattern = new DecimalFormat("$###,###,000.00");
System.out.println("Tax paid per year: " + pricePattern.format(r1.averageTaxes()));

}

}

//Restaurant.java

public class Restaurant extends Store {
private int peopleServed;
private float avgmeal;

public Restaurant(String newName, int peopleServed, float avgmeal) {
super(newName);
setPeopleServed(peopleServed);
setAveragePrice(avgmeal);
}
public void setPeopleServed(int newpeopleServed) {
if (newpeopleServed >= 0)
peopleServed = newpeopleServed; //mutator alows client to change the value of name
else
System.out.println("Number has to be greater than zero");
}
public void setAveragePrice(float newprice) {
if (newprice >= 0)
avgmeal = newprice; //mutator alows client to change the value of name
else
System.out.println("Number has to be greater than zero");
}
public int getPeopleServed() {
return peopleServed; //accessor; returns current value
}
public float getAverageMeal() {
return avgmeal; //accessor; returns current value
}
public String toString() {
return "Name of store is: " + super.getName() +
"\nNumber of people served is " + peopleServed +
"\nAverage price per person is " + avgmeal + "\n";
}

public boolean equals(Object o) {
if (!(o instanceof Restaurant))
return false;
else {
Restaurant objRest = (Restaurant) o;
if (avgmeal == objRest.avgmeal && peopleServed == objRest.peopleServed && super.equals(objRest))
return true;
else
return false;

}

}
public double averageTaxes() {
double avgtaxes = (double)(super.taxrate * (peopleServed * avgmeal * 365));
return avgtaxes; //accessor; returns current value
}

}

//Store.java

public class Store {
private String storename;
public final float taxrate = (float) .08000;

public Store(String newName) //constructor
{
setName(newName);
}

public String getName() {
return storename; //accessor; returns current value
}
public void setName(String newName) {
storename = newName; //mutator alows client to change the value of name
}
public String toString() {
return "Name of store is: " + storename;
}
public boolean equals(Object o) {
if (!(o instanceof Store))
return false;
else {
Store objStore = (Store) o;
if (storename.equals(objStore.storename))
return true;
else
return false;
}
}
}

最佳答案

系统正在寻找主类restaurantclient.RestaurantClient,因此类RestaurantClient位于包restaurantClient中,但是您的类 RestaurantClient 似乎在默认包中。

关于java - 当该程序显示无法找到或加载主类时,如何使该程序运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56071673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com