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
Code java:
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
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.
Re: What's wrong. Compile Ok but error when execute.
What errors are you facing?
Show here... Thanks
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
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?
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?)?
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,
Re: What's wrong. Compile Ok but error when execute.
Quote:
Originally Posted by
hantuapi
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.