7 Replies - 464 Views - Last Post: 27 April 2011 - 06:26 PM Rate Topic: -----

#1 Lestweremember  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 27-April 11

Inheritance java help

Posted 27 April 2011 - 10:47 AM

Hi everytimeI try to compile I keep receiving the error"
customer.java:41: class, interface, or enum expected
return onMailingList;
^"

Truly Frustrating and would be very grateful for any help!!!

public class Person 

{

	   private String Name;    			// The Name Of The Person
	   private int phoneNumber;       	// The Phone Number
	   private String address;       	// The Address
	   
	   public Person()
		{
			Name = "";
    		phoneNumber = 0;
    		address = "";
		}
		
	   public Person (String n, int pn, String ad) 
	   {
	      Name = n;
	      phoneNumber = pn;
	      address = ad;
	   }
	   public void setName(String n)
	   {
	      Name = n;  
	   }
	   public void setidnumber(int pn)
	   {
		   phoneNumber = pn;
	   } 
	   public void setdepartmen(String ad)
	   {
		   address = ad;
	   }
	   public String getName()
	   {
	      return Name;
	   }
	   public int getphoneNumber()
	   {
	      return phoneNumber;
	   }
	   public String getaddress()
	   {
	      return address;
	   }
}




public class customer extends Person 

{

private int customerNumber; // Phone Number
private String eMail; // Email
private boolean onMailingList; //Test if on Mailing List

public customer()
{
customerNumber = 0;
eMail = "";
}

public customer (String n, int pn, String ad, int cn, String em, boolean ml)
{
super(n,pn,ad);
customerNumber = cn;
eMail = em;
onMailingList = ml;
}

public int getcustomerNumber() {
return customerNumber;
}

public String geteMail() {
return eMail;
}

public void setcustomerNumber(int customerNumber) {
this.customerNumber = customerNumber;
}

public void seteMail(String eMail) {
this.eMail = eMail;
}

public boolean getMailingList();
}
return onMailingList;
{

}



public class TestCustomer 
{

public static void main (String [] Args){

customer customer = new customer("Les Paul",818224841,
"19920 Gibson Road", 1, "Stringsforlife@gmail.com", true );

System.out.println(" Name Phone Number Address customer Number customer E-Mail On ML");
System.out.println("__________________");
System.out.println(" " + customer.getName() + " " + customer.getphoneNumber() + " " 
+ customer.getaddress() + " " + customer.getcustomerNumber() + " " + customer.geteMail() 
+ " " + customer.getMailingList());

}
}



it's supposed to be able to run with the following code:

import java.util.Scanner;
import java.util.ArrayList;

public class JavaProgram
{
	public static void main( String[] args )
	{
		ArrayList<Customer> customerList = new ArrayList<Customer>();
		Scanner cin = new Scanner( System.in );

		while( getYesNo( cin, "\nAdd customer?" ) )
		{
			Customer newCustomer = getCustomer( cin );
			customerList.add( newCustomer );
		}
		
		for( Customer customer : customerList )
		{
			System.out.println( "\n" 
					+ "------------------------------\n"
					+ customer );
		}
								
	}
	
	private static customer getcustomerNumber( Scanner cin )
	{
		String name, address, phone, customerID;
		boolean mailingList;
		char yesNo;
				
		System.out.print( "Enter name               : " );
		name = cin.nextLine();
		
		System.out.print( "Enter street address     : " );
		String addressLine1 = cin.nextLine();
		
		System.out.print( "Enter City, State Zipcode: " );
		String addressLine2 = cin.nextLine();
		
		address = addressLine1 + "\n" + addressLine2;

		System.out.print( "\nEnter customer ID: " );
		customerID = cin.nextLine();
		
		System.out.print( "Enter phone: " );
		phone = cin.nextLine();
				
		mailingList = getYesNo( cin, "Mailing list?" );
		
		Customer newCustomer = new Customer( name, 
														 address, 
														 phone, 
														 customerID, 
														 mailingList );

		return newCustomer;

	}

	private static boolean getYesNo( Scanner cin, String prompt )
	{
		char yesNo;
		
		do
		{
			System.out.print( prompt + " (y/n): " );
			String reply = cin.nextLine() + " ";
			yesNo = Character.toUpperCase( reply.charAt(0) );
			
		} while( yesNo != 'Y' && yesNo != 'N' );
		
		return yesNo=='Y';
	
	}
	
}





Thanks again in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Inheritance java help

#2 Brewer  Icon User is offline

  • Awesome
  • member icon

Reputation: 178
  • View blog
  • Posts: 1,044
  • Joined: 14-June 10

Re: Inheritance java help

Posted 27 April 2011 - 11:04 AM

In Customer.java your braces for public void getMailingList() are backwards. You have a closing brace where you should have an opening brace and vise-versa.

This post has been edited by Brewer: 27 April 2011 - 11:05 AM

Was This Post Helpful? 1
  • +
  • -

#3 Lestweremember  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 27-April 11

Re: Inheritance java help

Posted 27 April 2011 - 11:13 AM

View PostBrewer, on 27 April 2011 - 11:04 AM, said:

In Customer.java your braces for public void getMailingList() are backwards. You have a closing brace where you should have an opening brace and vise-versa.


do I reverse the braces for lines 40 and 42?
Again I really appreciate the help, i've been working on this for hours.
Was This Post Helpful? 0
  • +
  • -

#4 Lestweremember  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 27-April 11

Re: Inheritance java help

Posted 27 April 2011 - 12:59 PM

can anyone help me please? I feel so frustrated!
Was This Post Helpful? 0
  • +
  • -

#5 Brewer  Icon User is offline

  • Awesome
  • member icon

Reputation: 178
  • View blog
  • Posts: 1,044
  • Joined: 14-June 10

Re: Inheritance java help

Posted 27 April 2011 - 01:00 PM

Why not try it and find out?
Was This Post Helpful? 1
  • +
  • -

#6 Lestweremember  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 27-April 11

Re: Inheritance java help

Posted 27 April 2011 - 01:28 PM

View PostBrewer, on 27 April 2011 - 01:00 PM, said:

Why not try it and find out?

I tried it and now it says "customer.java:44: reached end of file while parsing",
any suggestions?

Thanks again,
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10194
  • View blog
  • Posts: 37,646
  • Joined: 27-December 08

Re: Inheritance java help

Posted 27 April 2011 - 02:50 PM

It means you are missing ending curly braces at the bottom of your class.
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8316
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Inheritance java help

Posted 27 April 2011 - 06:26 PM

How many times will we have to repeat it:

"Indent your code properly it will become obvious"

You might think saving time by not doing the exercise while you write your code but... you then lost a lot of time trying to figure out what happens

public class customer extends Person 

{

	private int customerNumber; // Phone Number
	private String eMail; // Email
	private boolean onMailingList; //Test if on Mailing List

	public customer()
	{
		customerNumber = 0;
		eMail = "";
	}

	public customer (String n, int pn, String ad, int cn, String em, boolean ml)
	{
		super(n,pn,ad);
		customerNumber = cn;
		eMail = em;
		onMailingList = ml;
	}

	public int getcustomerNumber() {
		return customerNumber;
	}

	public String geteMail() {
		return eMail;
	}

	public void setcustomerNumber(int customerNumber) {
		this.customerNumber = customerNumber;
	}

	public void seteMail(String eMail) {
		this.eMail = eMail;
	}

	public boolean getMailingList();
}
return onMailingList;
{

}



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1