Java错误!哈文';我在别处没有看到解决办法
我正在编写一个程序,允许一个零售商和多个买家进行购物的借贷。在每个买家购买或制作pmnt后,我需要每月汇总每笔交易。Java错误!哈文';我在别处没有看到解决办法,java,Java,我正在编写一个程序,允许一个零售商和多个买家进行购物的借贷。在每个买家购买或制作pmnt后,我需要每月汇总每笔交易。 这就是我所知道的,我在这一点上唯一的错误是: Main.java:136: error: not a statement displayprocestran; ^ Main.java:144: error: not a statement displayprostrans
这就是我所知道的,我在这一点上唯一的错误是:
Main.java:136: error: not a statement
displayprocestran;
^
Main.java:144: error: not a statement
displayprostrans;
^
以下是节目:
/*Project4B, Judith Berk, CIS 2110, 4/28/13*/
import java.io.*;
public class Project4BDriver
{
public void main(String args[]) throws IOException ;
{
Project4B app;
app = new Project4B();
app.appMain();
}
} //end of class DriverProject4B
class Project4B
{
//Data declarations
BufferedReader stdin;
String custName;
char transType;
int transNum;
float transAmt;
float prcnt;
float prcntChrg;
float TprcntChrg;
float runBal;
float begBal;
float endBal;
float TPmnt;
float TChrg;
int PurchCtr;
float HiPurchAmt;
String HiPurchCust;
float AvgPurch;
float CoMonthBal;
float CoTnewChrg;
float CoTPmnt;
float CobegBal;
public void appMain() throws IOException ;
{
outputHeader();
initReport();
getAcctInfo();
initrunBal();
while (transNum != 0);
{
prostrans();
}
calculate average;
calculate runBal;
calculate interest;
display summary;
}
void outputHeader();
{
//Output report header
System.out.print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
System.out.println("Project4B");
System.out.println("Judith Berk CIS 2110");
System.out.println("Supply Chain Monthly Report");
System.out.print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
void initReport()
{
//standard input will be keyboard
stdin = new BufferedReader(new InputStreamReader.System.in());
TPmnt = 0;
TChrg = 0;
PurchCtr = 0;
PrcntChrg = 0;
TprcntChrg = 0;
hiPurchAmt = 0;
CoMonthlyBal = 0;
}
public void getAcctInfo() throws IOException;
{
System.out.print("Please enter CUSTOMER NAME:");
custName = (stdin.readLine());
System.out.print("Please enter BEGINNING BALANCE for Customer:");
begBal = Float.parseFloat(stdin.readLine());
System.out.print("Please enter Customer's individual INTEREST RATE (i.e. 0.05, 0.03, 0.035):");
prcnt = Float.parseFloat(stdin.readLine());
}
void initrunBal()
{
runBal = begBal;
}
public void prostrans() throws IOException;
{
get transNum;
}
public void gettransNum() throws IOException;
{
System.out.print("Please enter TRANSACTION NUMBER:");
transNum = Integer.ParseInt(stdin.readLine());
}
public void gettransDetails() throws IOException;
{
System.out.print("Please enter TRANSACTION AMOUNT:");
transAmt = Float.parseFloat(stdin.readLine());
System.out.print("Please enter TRANSACTION TYPE:");
transType = (stdin.readLine().charAt(0));
}
void calcTPmntTChrgTPrcntChrgandrunBal();
{
if ((transType == "C") && (transType == "c"))
{
purchCtr = purchCtr + 1;
prcntChrg = prcnt * transAmt;
runBal = runBal + transAmt + prcntChrg;
TChrg = TChrg + transAmt;
TprcntChrg = prcntChrg + prcntChrg;
displayprocestran;
}
else if ((transType == "p") && (transType == "P"))
{
runBal = runBal - transAmt;
TPmnt = TPmnt + transAmt;
displayprostrans;
}
}
void displayprostran();
{
System.out.println("*\n" + custName);
System.out.println("*\n" + transAmt);
System.out.println("*\n" + runBal);
}
void updateHiPurchCustandHiPurchTot();
{
if (HiPurchAmt > TChrg);
{
HiPurchChrg = TChrge;
HiPurchName = custName;
}
}
void calcAvgPurch();
{
AvgPurch = TChrg / purchCtr;
}
void initCoMonthBal()
{
get CobegBal;
}
{
System.out.print("Enter Company Beginning Balance");
CobegBal = Float.parseFloat(stdin.readLine());
}
void calcCosummary();
{
CoMonthBal = CobegBal + TChrg - TPmnt;
}
void displaysummary()
{
System.out.print("Customer Name:\t" + custName);
System.out.print("Customer Beginning Balance:\t" + begBal);
System.out.print("Customer Payments:\t" + TPmnt);
System.out.print("Customer New Charges:\t" + TChrg);
System.out.print("Customer Interest Charge:\t" + TprcntChrg);
System.out.print("Customer Ending balance:\t" + runBal);
System.out.print("Overall Company Ending Balance:\t" + CoMonthlBal);
System.out.print("Monthly Average Purchases:\t" + AvgChrg);
System.out.print("Monthly Payments Received:\t" + TPmnts);
System.out.print("Customer with highest monthly Purchases:\t" + HiPurchName);
System.out.print("Highest Monthly Purchase Amount:\t" + HiPurchAmt);
}
}
请帮帮我
谢谢朱迪
你的问题
这绝对不是一个声明。也许你是说
displayprocestran();
关于错误消息的旁注
起初,错误消息似乎有点神秘,但让我们看看您的
Main.java:136: error: not a statement displayprocestran;
Main.java:144: error: not a statement displayprostrans; ^
好的,它告诉你它找到了^
指向的错误,它位于displayprocestran
的末尾。它还告诉你这不是一个声明。这应该告诉你,你有一个语法错误,这意味着你键入了错误。现在,您可以到处调用像stdin.readLine()
这样的方法。您应该开始尝试并建立链接,以了解为什么会出现这些错误
我注意到的其他我没有看到的事情已经提到了
命名 好吧,我想最大的问题是你的方法有多不可读。本手册解释了应如何布置方法和变量。例如:
displayprocestran --- > displayProcesTran (I think)
封装
你有这样的方法:
void initrunBal()
{
runBal = begBal;
}
我不确定用户何时需要使用此方法。因此,也许可以将其设置为访问修饰符私有
。这是为了确保呈现给类用户的接口正是他们所需要的方法。他们不需要知道你的类的内部工作。这就是所谓的
根本无法编译的东西
这不是有效的Java。我不确定你到底想从中得到什么。也许您想返回transNum
?在这种情况下,应为:
public int getTransNum()
{
return transNum;
}
在以下代码中:
if ((transType == "C") && (transType == "c"))
{
...
displayprocestran;
}
您实际上是在尝试调用void displayprostran()
方法吗?如果是这样,就这样称呼它
if ((transType == "C") && (transType == "c"))
{
...
displayprostran();
}
啊,不要把钱作为浮点数来存储。
displayprostrans代码>不是一条语句。另外,@MK是完全正确的-不要将浮动用于货币,它们在财务方面甚至不够精确。变量transType
是一个char
;与字符文本'C'
和'C'
进行比较。此外,它不能同时是'C'
和'C'
。我猜你的意思是“或”,所以用|
代替&
。
if ((transType == "C") && (transType == "c"))
{
...
displayprocestran;
}
if ((transType == "C") && (transType == "c"))
{
...
displayprostran();
}