[英]Error running and compiling java code related issues
運行代碼的問題
不斷獲得非法逃逸角色
聲明變量,以及似乎正確聲明的字符串。
import java.swing.*;
import java.text.DecimalFormat;
public class TWP1Project {
private static Object dataIn;
public static void main(String[] args) {
// declare class variables
int hours;
double fee, rate, tuition;
// call methods
displayWelcome();
hours = getHours();
rate = getRate();
tuition = calcTuition(hours);
fee = myArray(1);
diplayTotal(tuition+fee);
}
public static void displayWelcome()
{
System.out.println("\Welcome to the Tuition and Fees Calculator");
}
}
public static int getHours()
{
//declare variables
String strHours;
int hours = 0;
//prompts user for input
System.out.println("Enter the number of hours accrued in a class.");
hours = dataIn.readLine();
try
{
hours = Integer.parseInt(strHours);
}
catch{NumberFormatException e};
JOptionPane.showMessageDialog{null,"Your entry was not in the proper format.",
"Error"JOptionPane.INFORMATION_MESSAGE};
{
System.out.println("Please input whole numbers only");
}
return hours;
}
//the getRate() method ask user to input the rate per credit hours.
public static double getRate()
{
int hours =12;
if (hours>12)
System.out.println("calculate the rate per credit hours");
else
if (hours<12)
System.out.println("credit hours is inaccurate");
else
System.out.println("zero");
}
}
return rate;
//the calcTuition() allowed to calculate tuition.
public static double calcTuition()
{`enter code here`
int hours
double rate =0.0;
double rate * hours
}
return tuition;
//
public static myArray(int tuition)
{
int tuition
double fee
}
return fee
如果可以或需要一些提示,則需要糾正方面的幫助。 在Java中正確運行它時遇到問題。
從System.out.println("\\Welcome to the Tuition and Fees Calculator");
刪除\\
System.out.println("\\Welcome to the Tuition and Fees Calculator");
或者,如果您在消息中需要“ \\”,請在輸入時加上雙反斜杠。
嘗試這個:
public static void displayWelcome()
{
System.out.println("\\Welcome to the Tuition and Fees Calculator");
}
更多信息: https : //docs.oracle.com/javase/tutorial/java/data/characters.html
您有多個錯誤,我已經解決了其中的一些錯誤,並給出了一些指示...請在編寫代碼時使用Netbeans或Eclipse之類的IDE ...我已經將其他一些留給您了,並說明了什么你應該對他們做
import java.io.Console;
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
public class TWP1Project {
private static Console dataIn; // if you want to read from keyboard or
// something, this should be of type
// Scanner, not Object - to use it you need
// to also add import java.util.Scanner;
public static void main(String[] args) {
// declare class variables
int hours;
double fee, rate, tuition;
// call methods
displayWelcome();
hours = getHours();
rate = getRate();
tuition = calcTuition(hours);
fee = myArray(1); // you have
diplayTotal(tuition + fee);
}
public static void displayWelcome() {
System.out.println("Welcome to the Tuition and Fees Calculator"); // no
// backslash
} // erased one brace this
public static int getHours() {
// declare variables
String strHours; // you didn't initialize strHours
int hours = 0;
// prompts user for input
System.out.println("Enter the number of hours accrued in a class.");
dataIn = System.console(); // need to initialize in order to read lines
// from it
hours = Integer.parseInt(dataIn.readLine()); // this doesn't prompt for
// input, you need a
// scanner object
try {
hours = Integer.parseInt(strHours); // didn't initialize strHours
} catch (NumberFormatException e) {
} // pay attention here
JOptionPane.showMessageDialog(null,
"Your entry was not in the proper format.", "Error",
JOptionPane.INFORMATION_MESSAGE); // you need ( , not {
{
System.out.println("Please input whole numbers only");
}
return hours;
}
// the getRate() method ask user to input the rate per credit hours.
public static double getRate() {
int hours = 12;
if (hours > 12)
System.out.println("calculate the rate per credit hours");
else if (hours < 12)
System.out.println("credit hours is inaccurate");
else
System.out.println("zero");
return rate; // you need to initialize the rate somewhere...i'll let
// this for you
}
// the calcTuition() allowed to calculate tuition.
public static double calcTuition() {
int hours;
double rate = 0.0;
double tuition = rate * hours; // i don't actually know what you meant
// here, but you should declare the
// tuition and then initialize it
return tuition;
}
//
public static myArray(int tuition) // you forgot the return type
{
// don't know what you meant here, but again, initialize
double fee;
return fee;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.