In: Computer Science
JAVA CODE ---
from the book, java programming (7th edition) chapter 7 carly's question
I am getting a illegal expression error and don't know how to fix it, also may be a few other error please help
CODE BELOW
import java.util.Scanner;
public class Event
{
public static double pricePerGuestHigh = 35.00;
public static double pricePerGuestLow = 32.00;
public static final int LARGE_EVENT_MAX = 50;
public String phnum="";
public String eventNumber="";
private int guests;
private double pricePerEvent;
public void setPhoneNumber()
{
Scanner s = new Scanner(System.in);
int count = 0;
System.out.println("Enter Phone Number: ");
String pnumb=s.nextLine();
int len=pnumb.length();
for(int i=0;i
{
char c=pnumb.charAt(i);
if(Character.isDigit(c))
{
count++;
String ss=Character.toString(c);
phnum=phnum.concat(ss);
}
}
if(count!=10)
{
phnum="";
phnum=phnum.concat("0000000000");
}
}
public String getPhoneNumber()
{
String ret="("+this.phnum.charAt(0)
+""+this.phnum.charAt(1)+""+this.phnum.charAt(2)
+")"+this.phnum.charAt(3)+""+this.phnum.charAt(4)
+""+this.phnum.charAt(5)+""+this.phnum.charAt(6)
+""+this.phnum.charAt(7)+""+this.phnum.charAt(8)
+""+this.phnum.charAt(9);
return ret;
}
public void setEventNumber()
{
Scanner scanner = new Scanner(System.in);
int len;
System.out.println("Enter 4 digit event number: ");
String enumb = scanner.nextLine();
len=enumb = scanner.nextLine();
len=enumb.length();
char c1,c2,c3,c4;
String defv="A000";
c1=enumb.charAt(0);
c2=enumb.charAt(1);
c3=enumb.charAt(2);
c4=enumb.charAt(3);
if(Character.isLetter(c1) &&
Character.isDigit(c2) &&
Character.isDigit(c3) &&
Character.isDigit(c4))
{
enumb=enumb.toUpperCase();
eventNumber=eventNumber.concat(enumb);
}
else
{
eventNumber=eventNumber.concat(defv);
}
}
public void setGuests(int guests)
{
this.guests = guests;
if(isLargeEvent())
PricePerEvent=pricePerGuestHigh;
else
PricePerEvent=pricePerGuestLow;
}
public int getGuestCount()
{
return guests;
}
public boolean isLargeEvent()
{
if(guest>= LARGE_EVENT_MAX)
{
return true;
}
else if (guests < LARGE_EVENT_MAX)
{
return false;
}
return isLargeEvent();
}
public String getEventNumber()
{
String ret1="Event Number:"
+this.eventNumber;
return ret1;
}
public int getGuests(boolean largeEvent)
{
return guests;
}
}
import java.util.Scanner;
public class Event
{
public static double pricePerGuestHigh = 35.00;
public static double pricePerGuestLow = 32.00;
public static final int LARGE_EVENT_MAX = 50;
public String phnum="";
public String eventNumber="";
private int guests;
private double pricePerEvent;
public void setPhoneNumber()
{
Scanner s = new
Scanner(System.in);
int count = 0;
System.out.println("Enter Phone
Number: ");
String pnumb=s.nextLine();
int len=pnumb.length();
for(int i=0;i<len; i++)
{
char
c=pnumb.charAt(i);
if(Character.isDigit(c))
{
count++;
String ss=Character.toString(c);
phnum=phnum.concat(ss);
}
}
if(count!=10)
{
phnum="";
phnum=phnum.concat("0000000000");
}
}
public String getPhoneNumber()
{
String
ret="("+this.phnum.charAt(0)
+""+this.phnum.charAt(1)+""+this.phnum.charAt(2)
+")"+this.phnum.charAt(3)+""+this.phnum.charAt(4)
+""+this.phnum.charAt(5)+""+this.phnum.charAt(6)
+""+this.phnum.charAt(7)+""+this.phnum.charAt(8)
+""+this.phnum.charAt(9);
return ret;
}
public void setEventNumber()
{
Scanner scanner = new
Scanner(System.in);
int len;
System.out.println("Enter 4 digit
event number: ");
String enumb =
scanner.nextLine();
len=enumb.length();
char c1,c2,c3,c4;
String defv="A000";
c1=enumb.charAt(0);
c2=enumb.charAt(1);
c3=enumb.charAt(2);
c4=enumb.charAt(3);
if(Character.isLetter(c1)
&&
Character.isDigit(c2)
&&
Character.isDigit(c3)
&&
Character.isDigit(c4))
{
enumb=enumb.toUpperCase();
eventNumber=eventNumber.concat(enumb);
}
else
{
eventNumber=eventNumber.concat(defv);
}
}
public void setGuests(int guests)
{
this.guests = guests;
if(isLargeEvent())
pricePerEvent=pricePerGuestHigh;
else
pricePerEvent=pricePerGuestLow;
}
public int getGuestCount()
{
return guests;
}
public boolean isLargeEvent()
{
if(guests>=
LARGE_EVENT_MAX)
{
return
true;
}
else if (guests <
LARGE_EVENT_MAX)
{
return
false;
}
return isLargeEvent();
}
public String getEventNumber()
{
String ret1="Event Number:"
+this.eventNumber;
return ret1;
}
public int getGuests(boolean largeEvent)
{
return guests;
}
}
/************************************************************************/
/* You can add the following main method */
class Driver
{
public static void main (String[] args)
{
Event e = new Event();
e.setPhoneNumber();
e.setEventNumber();
e.setGuests(2);
}
}