Проблемы с моим кодом (незаконное начало выражения) - PullRequest
0 голосов
/ 24 сентября 2019

спасибо, что уделили время на чтение этого поста.Может ли кто-нибудь сказать мне, почему я получаю:

SuperPhoneCardInc.java:7: error: illegal start of expression public static void main(String[] args); ^ SuperPhoneCardInc.java:7: error: illegal start of expression public static void main(String[] args); ^ SuperPhoneCardInc.java:7: error: ';' expected public static void main(String[] args); ^ SuperPhoneCardInc.java:7: error: '.class' expected public static void main(String[] args); ^ SuperPhoneCardInc.java:7: error: ';' expected public static void main(String[] args);

Когда я пытаюсь javac код

Вот код,Я извиняюсь за зверское форматирование.Спасибо :

import java.util.Scanner;

public class SuperPhoneCardInc {

{

public static void main(String[] args); 


{

CardTable ct = new CardTable();

Scanner in = new Scanner(System.in);

String line = null;

boolean done = false;

String cardType = null;

if(!in.hasNextLine())


{

done = true;

}

else

{

line = in.nextLine();

}

if(!done && line.length() >= 4 && line.substring(0,4).equals("quit"))

{

done = true;

}

while(!done)

{

System.out.println("Input: " + line);

Scanner inl = new Scanner(line);

String command = "";

if(inl.hasNext())

{

command = inl.next();

}

if(command.equals("add"))

{

boolean invalidArgs = false;

long no = 0;

int passwd = 0;

if(inl.hasNextLong())

{

no = inl.nextLong();

}

else

{

invalidArgs = true;

}

if(!invalidArgs && inl.hasNextInt())

{

passwd = inl.nextInt();

}

else

{

invalidArgs = true;

}

if(!invalidArgs && inl.hasNext())

{

cardType = inl.next();

}

else

{

invalidArgs = true;

}

if(!invalidArgs && (no <= 0 || passwd <= 0))

{

invalidArgs = true;

}

PhoneCard card = null;

if(!invalidArgs)

{

card = new PhoneCard( no , passwd );

}

else

{

invalidArgs = true;

}

if(invalidArgs)

{

}

else if(ct.get(no) != null)

{

System.out.println("Error: card no " + no + " already exists");

}

else if(!ct.add(card))

{

System.out.println("Error: card table full");

}

else

{

System.out.println("Result: added card " + no);

}

}

else if(command.equals("getBalance"))

{

boolean invalidArgs = false;

long no = 0;

int passwd = 0;

if(inl.hasNextLong())

{

no = inl.nextLong();

}

else

{

invalidArgs = true;

}

if(!invalidArgs && inl.hasNextInt())

{

passwd = inl.nextInt();

}

else

{

invalidArgs = true;

}

if(!invalidArgs && (no <= 0 || passwd <= 0))

{

invalidArgs = true;

}

if(invalidArgs)

{

System.out.println("Error: invalid arguments for getBalance command");

}

else

{

PhoneCard card = ct.get(no);

if(card == null)

{

System.out.println("Error: card no " + no + " does not exist");

}

else if(card.getPassword() != passwd)

{

System.out.println("Error: password " + passwd + " incorrect");

}

else

{

System.out.printf("Result: card %d balance is %.2f%n",

no, card.getBalance());

}

}

}

else if(command.equals("getLimit"))

{

boolean invalidArgs = false;

long no = 0;

int passwd = 0;

String zone = "";

if(inl.hasNextLong()){ //check if file has card number.

no = inl.nextLong();//places the car number in "no"

}

else{

invalidArgs = true;//if there is no card number, comman is invalid.

}

if(!invalidArgs && inl.hasNextInt()){ //if statement to see if command is valid and the file has the card password

passwd = inl.nextInt();//places file password in variable "passwd"

}

else {//if no password is give, command becomes invalid

invalidArgs = true;

}

if(!invalidArgs && (no <= 0 || passwd <= 0)){//if statement to see if command is valid and the file has the zone to which the card is referencing

invalidArgs = true;

}

if(!invalidArgs && inl.hasNext() ){//if statement to see if command is valid and the file has the zone to which the card is referencing

zone = inl.next();//places zone from file in variable "zone"

if (!CallZone.isValidZone(zone)){//if statement to see if zone is a valid callzone

invalidArgs = true;//if zone is invalid set command as invalid

}

}

else { //if none of these arguments have been fulfilled, make command invalid

invalidArgs = true;

}

if(invalidArgs) {//if statement is invalid print error message

System.out.println("Error: invalid arguments for getBalance command");

}

else{//if statement is valid return card number from cardtable list

PhoneCard card = ct.get(no);

if(card == null){//if no card exist (does not match number read from file) print error message

System.out.println("Error: card no " + no + " does not exist");

}

else if(card.getPassword() != passwd){//if card password from file does not match card password from cardtable print error message

System.out.println("Error: password " + passwd + " incorrect");

}

else{ //if every requirement is valid, print message stating the limit of the card, with it's number and zone it has called

System.out.printf("Result: card %d limit for zone %s is %d%n", no, zone, card.getLimit(CallZone.convertToZone(zone)));

}

}

}

else if(command.equals("charge"))

{

//variable used within "charge" method

boolean invalidArgs = false;

long no = 0;

int passwd = 0;

String zone = "";

int minutes = 0;

if(inl.hasNextLong()) { //if statement to see if the file has card number

no = inl.nextLong();//places the files card number in variable "no"

}

else {//if no card number, command becomes invalid

invalidArgs = true;

}

if(!invalidArgs && inl.hasNextInt()){//if statement to see if command is valid and the file has the card password

passwd = inl.nextInt();//places file password in variable "passwd"

}

else{ //if no password is give, command becomes invalid

invalidArgs = true;

}

if(!invalidArgs && (no <= 0 || passwd <= 0)) {//if statement to see if command is valid and the file has the zone to which the card is referencing

invalidArgs = true;

}

if(!invalidArgs && inl.hasNext() ){ //if no password is give, command becomes invalid

zone = inl.next();//places zone from file in variable "zone"

if (!CallZone.isValidZone(zone)){//if statement to see if zone is a valid callzone

invalidArgs = true;//if zone is invalid set command as invalid

}

}

else{//if none of these arguments have been fulfilled, make command invalid

invalidArgs = true;

}

if (!invalidArgs && inl.hasNextInt()){//if statement to see if command is valid and the file has the amount of minutes used

minutes = inl.nextInt();

}else {//if no minutes is given by file, make command invalid

invalidArgs = true;

}

if(invalidArgs) {//if command is invalid print error message for "charge" command

System.out.println("Error: invalid arguments for getBalance command");

}

else{//if commanf is valid return card no using get(no) command

PhoneCard card = ct.get(no);

double initialBalance = 0;

if (card != null){

initialBalance = card.getBalance();

}

if(card == null){//if no card exists (does not match number read from file) print error message

System.out.println("Error: card no " + no + " does not exist");

}

else if(card.getPassword() != passwd){

System.out.println("Error: password " + passwd + " incorrect");

}

else if(!card.charge(minutes, CallZone.convertToZone(zone))){//if card is unabe to charge the minutes used (based on CallZone) print error message

System.out.println("Error: card "+no+" limit for zone "+zone+" is "+minutes+" minutes\n");

}

else { //if every requirment is valid retrieve the new balance of the card selected and print how much was charged to card and the new balance

double currentBalance = card.getBalance();

System.out.println("Result: card "+no+" charged " +(initialBalance-currentBalance)+ ", new balance is " +currentBalance);

}

}

}

else if(command.equals("deductWeeklyFee"))

{

PhoneCard card = ct.first();

while(card != null)

{

card.deductWeeklyFee();

System.out.printf("Result: card %d charged weekly fee%n",

card.getNumber());

card = ct.next();

}

System.out.println("Result: weekly fees deducted");

}

else if(command.equals("printAll"))

{

PhoneCard card = ct.first();

while(card != null)

{

System.out.printf("Result: %s%n", card);

card = ct.next();

}

System.out.println("Result: all cards printed");

}

else

{

System.out.println("Error: command invalid");

}

if(!in.hasNextLine())

{

done = true;

}

else

{

line = in.nextLine();

}

if(!done && line.length() >= 4 && line.substring(0,4).equals("quit"))

{

done = true;

}

}

}

}

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...