Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: What's wrong. Compile Ok but error when execute.

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default What's wrong. Compile Ok but error when execute.

    can someone help me to solve this? I am very new and need to complete this as an assignment:

    I got the below error when exceute:

    Exception in thread "main" java.lang.NoSuchMethodError: main


    import java.io.*;
    import java.util.Date;
     
    public abstract class Customer {		//super class customer
    	String customerName;
    	String customerID;
    	String customerAdd;
    	String customerPhone;
    	String dateOfMembership;
     
    	public Customer(String name, String id, String add, String phone, String date) {		//constructor
    		this.customerName = name;
    		this.customerID = id;
    		this.customerAdd = add;
    		this.customerPhone = phone;
    		this.dateOfMembership = date;
    	}
     
    	public String getCustomerName() {
    		return this.customerName;
    	}
     
    	public void setCustomerName(String name) {
    		this.customerName = name;
    	}
     
    	public String getCustomerID() {
    		return this.customerID;
    	}
     
    	public void setCustomerID(String id) {
    		this.customerID = id;
    	}
     
    	public String getCustomerAdd() {
    		return this.customerAdd;
    	}
     
    	public void setCustomerAdd(String add) {
    		this.customerAdd = add;
    	}
     
    	public String getCustomerPhone() {
    		return this.customerPhone;
    	}
     
    	public void setCustomerPhone(String phone) {
    		this.customerPhone = phone;
    	}
     
    	public String getDateOfMembership() {
    		return this.dateOfMembership;
    	}
     
    	public void setDateOfMembership(String date) {
    		this.dateOfMembership = date;
    	}
     
    	public abstract int getPointsBalance(); 	//abstract method getPointsBalance() for toString method
     
    	public String toString() {			//tString method to display customer name, id, add, phone and dateofmembership
    		return("Customer name:" +getCustomerName() + "\n" + "Customer ID:" + getCustomerID() + "\n" + "Customer address:" +getCustomerAdd() + "\n" + "Customer phone:" +getCustomerPhone() + "\n" + "Customer membership date:" +getDateOfMembership() + "Customer points balance:" +getPointsBalance());
    	}
     
    }	
     
    class CherasOutletCustomer extends Customer {		//sub class CherasOutletCustomer
    	public static final int POINTS = 100;			//declare final POINTS
    	private int pointsUsed;									//later use for mutator method
     
    	public CherasOutletCustomer(String name, String id, String add, String phone, String date) {	//constructor
    		super(name, id, add, phone, date);
    	}
     
    	public int getPointsUsed() {		//customer points used
    		return this.pointsUsed ;
    	}
     
    	public void setPointsUsed(int pointsUsed) {
    		this.pointsUsed = pointsUsed;
    	}
     
    	public int getPointsBalance(){		//calculate customer points balance
    		return POINTS - pointsUsed;
    	}
     
    	public String toString() {			//toString method to display customer name, id, add, phone and dateofmembership
    		return(super.toString() + "\n" + "Branch=Cheras");
    	}
    }
     
    class CustomerLoyaltyRewards extends CherasOutletCustomer {  	//sub class CustomerLoyaltyRewards
    	private double customerPurchase;
    	double customerVoucher;
    	int extraPoints;
     
    	public CustomerLoyaltyRewards(String name, String id, String add, String phone, String date, double voucher, int extra) {		//constructor
    		super(name, id, add, phone, date);
    		this.customerVoucher = voucher;
    		this.extraPoints = extra;
    	}
     
    	public void setCustomerPurchase(double purchase) {		//customer purchase amount
    		this.customerPurchase = purchase;
    	}
     
    	public double getCustomerVoucher() {		//calculate customer voucher amount
    		if(customerPurchase > 500)
    			customerVoucher += customerVoucher + 10;
    		else
    			customerVoucher += customerVoucher + 5;
    		return this.customerVoucher;
    	}
     
    	public int getExtraPoints() {			//calculate customer extra points given
    		if(customerPurchase > 500)
    			extraPoints += extraPoints + 10;
    		else
    			extraPoints += extraPoints + 5;
    		return this.extraPoints;
    	}
     
    	public int getPointsBalance() {			//calculate final customer points balance
    		return (getPointsBalance() + getExtraPoints());
    	}
     
    	public String toString() {		//tString method to display customer name, id, add, phone and dateofmembership
    		return(super.toString() + "Customer voucher:" +getCustomerVoucher() + "Customer extra points:" +getExtraPoints());
    	}
    }
     
    class Test {
    	public static void main(String[] args) {
    		CustomerLoyaltyRewards cus = new CustomerLoyaltyRewards();
     
     
    	}
     
    }



    Question to above is :

    Design an abstract class named Customer with fields for storing a customer’s name, ID, address,
    telephone number and date of membership. It has a constructor with arguments to initialize the
    data fields. This class has a toString method to display customer’ name, ID, address, telephone
    number and date of membership. It also has an abstract method named getPointsBalance.
    Then, design a class named CherasOutletCustomer which extends the Customer class. It
    declares one final integer fields name POINTS which hold 100 as the value. This field holds the
    total redeemed points given after registering the membership. The class also declares a field to
    indicates points that customer has used. In this class, write a mutator method to store value for
    the class’s field. Next, CherasOutletCustomer class will override:
    a. abstract getPointsBalance method defined in Customer class. In this method, declare an
    integer variable to hold the remaining points left after customer use the given points.
    Calculate the remaining points.
    b. the toString method defined in Customer class and also display ‘Cheras’ as branch name
    and points used.
    As a loyalty rewards, customers can earn discount voucher and extra points on all their purchases.
    The amount of a customer’s discount voucher and extra points are determined by the amount of
    the customer’s purchases in the store as follows:
     Customer purchases RM500 - RM5 discount voucher and 5 extra points is given.
     Customer purchases RM1500 – RM10 discount voucher and 8 extra points is given.
     Customer purchases RM2000 – RM20 discount voucher and 10 extra points is given.
     Customer purchases RM2500 – RM30 discount voucher and 15 extra points is given.
    To demonstrate the loyalty rewards, design a class named CustomerLoyaltyRewards which
    extends CherasOutletCustomer class. The CustomerLoyaltyRewards class has fields for the
    amount of customer’s purchases, discount voucher level and extra points given. Provide
    appropriate constructor, mutator and accessor methods for the class’s fields.
    Demonstrate the classes by writing a program (test class) that uses a CustomerLoyaltyRewards
    object
    Last edited by KevinWorkman; March 30th, 2011 at 07:19 AM. Reason: added highlight tags


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,179
    My Mood
    Hungover
    Thanks
    141
    Thanked 600 Times in 515 Posts

    Default Re: What's wrong. Compile Ok but error when execute.

    What class are you trying to execute? What is the "main" class? Do you have all of these in one file?

    PS- When posting code, make sure you use the code or highlight tags. I added them for you this time, but please be more mindful in the future.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: What's wrong. Compile Ok but error when execute.

    What errors are you facing?
    Show here... Thanks

  4. #4
    Junior Member
    Join Date
    Mar 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong. Compile Ok but error when execute.

    Thank you for tking a look. I have no problem to compile using textpad but when i run the code, it give me "Exception in thread "main" java.lang.NoSuchMethodError: main" error.

    I tried almost everything but this error is always hunting me. Someone says the code is not complete and I do not know how to finish it according to the question that is posted here. It is a challange and I like to see the completion and output to it.

    anyone can chip in ideas to complete? Please, please , join hand to help. TQ

  5. #5
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: What's wrong. Compile Ok but error when execute.

    Beleive me i have seen this almost three to four times and not sure why it is providing error. Anyways, an advice, why don't you try putting your main in CustomerLoyaltyRewards class?

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,179
    My Mood
    Hungover
    Thanks
    141
    Thanked 600 Times in 515 Posts

    Default Re: What's wrong. Compile Ok but error when execute.

    You didn't answer my questions. What class are you trying to execute? What is the "main" class? Do you have all of these in one file? What does your directory structure look like? What are you actually typing into the command prompt (you are using the command prompt, right?)?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Junior Member
    Join Date
    Mar 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong. Compile Ok but error when execute.

    Hi KevinWorkman. I am trying to execute Customer class which is the main class. Yes, they are all in what I put in the codes. I not using command line to execute. I am using textpad to write the code and using Ctrl 1 to compile and Ctrl 2 to run. When compile, it does not give any error. When I run, it gives error as mentioned.

    Hi Mr. 777. I tried but no success.

    REgards,

  8. #8
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: What's wrong. Compile Ok but error when execute.

    Quote Originally Posted by hantuapi View Post
    Hi KevinWorkman. I am trying to execute Customer class which is the main class. Yes, they are all in what I put in the codes. I not using command line to execute. I am using textpad to write the code and using Ctrl 1 to compile and Ctrl 2 to run. When compile, it does not give any error. When I run, it gives error as mentioned.

    Hi Mr. 777. I tried but no success.

    REgards,
    How customer can be your main class? You are writing your main() in test class.

Similar Threads

  1. Could not execute the file
    By miaaa00 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 20th, 2011, 08:28 AM
  2. [SOLVED] Picture won't go with the .jar (Wrong code or compile error?)
    By Fermen in forum Object Oriented Programming
    Replies: 3
    Last Post: March 15th, 2011, 05:22 PM
  3. Code doesn't execute properly
    By fride360 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 12th, 2011, 11:36 AM
  4. unable to execute prepared statement
    By nrao in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 11th, 2010, 07:26 PM
  5. how to execute a simple display without a main method
    By chronoz13 in forum Java Theory & Questions
    Replies: 5
    Last Post: January 13th, 2010, 06:28 AM

Tags for this Thread