Need help with Assignment. [Splitting Strings] [Full code provided]

Hi, I need help with an Assignment that requires me to continue(inheritance) on an existing assignment that I previously did.

When I compile them there are no syntax errors, but when I try to run the code it says "PatternSyntaxExeption: null(in java.util.regex.Pattern)". Do I need to use regex?

#This is the main code that uses all the methods.
[code]import java.util.Random;
import java.util.Scanner;

class pdaSIM{
public static void main(String args[]){
pdaCMD pda = new pdaCMD();
Random rand = new Random();
Scanner in = new Scanner(System.in);

double credit = 0;
String battery_stat="[#][#][#][][]";
String emailData = "John1987@gmail.com*This a test email.";

credit = 2+rand.nextInt(10);
//use power procedudure
pda.power = true;
//start of main code
//loops until power is false
while (pda.power == true){
//split emailData string
emailData = pda.splitEmail(emailData);
//displays layout
pda.showCredit(credit);
System.out.print(" ");
pda.batteryStatus(battery_stat);

//displays menu
pda.menu();
//checks option chosen
switch (pda.menuCh) {
case 1: credit = pda.Call(credit); break;
case 2: credit = pda.topup(credit); break;
case 3: battery_stat = pda.recharge(battery_stat); break;
case 4: emailData = pda.readEmail(emailData); break;
case 5: emailData = pda.writeEmail(emailData); break;
case 6: //switch pda off
pda.power(); break;
default: System.out.print("Invalid choice.
"); break;
}

System.out.print("
");
}
}
}[/code]

#I get the error in this class.
[code]import java.util.Scanner;
public class pdaCMD extends mobileCMD{
Scanner in = new Scanner(System.in);

String temp[];

public String splitEmail(String emailData){
temp = emailData.split("*");
return emailData;
}

public String readEmail(String emailData){
for (int i=0; i 0){
credit = credit-0.5;
}
return credit;
}

public void showCredit(double credit){
System.out.print(credit+ "euros");
}

public double topup(double credit){
credit = credit+5;
return credit;
}

public void batteryStatus(String battery_stat){
System.out.print(battery_stat);
}

public String recharge(String battery_stat){
if (battery_stat == "[#][#][#][#][#]"){
System.out.print("Battery charged.
Please unplug charger to save energy.
");
}

battery_stat = "[#][#][#][#][#]";
return battery_stat;
}

public void menu(){
System.out.print("

1. Call
2. Topup
3. Recharge
4. Power ");
menuCh = in.nextInt();
}

}[/code]

Please help.
Anyone can use the code, if used a little indication that this was made by me (jean farrugia) would be much appreciated.(:

Comments

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion