Results 1 to 4 of 4
Thread: Problem with Enum assignment
- 02-07-2013, 09:03 AM #1
Member
- Join Date
- Feb 2013
- Location
- Scenic Flint, MI
- Posts
- 6
- Rep Power
- 0
Problem with Enum assignment
Hello! I'm working on my assignment. For some reason, I get everything together, get rid of all the red underline and it's just NOW giving me this error code:
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:7: error: missing method body, or declare abstract
public static void main(String[] args);
1 error
I truly appreciate any input because I'm hitting a wall. I'm pretty sure I'm overtired and over-thinking it but here are the instructions and code:
1. Create an enumeration named CustomerType. This enumeration should contain constraints that represent three types of customers: retail, trade, and college.
2. Open the CustomerTypeApp class and add a method to this class that returns a discount percent (0.10 for retail, 0.30 for trade, and 0.20 for college) depending on the CustomerType variable that’s passed to it.
3. Add code to the main method that declares a CustomerType variable, assigns a customerType to it, gets the discount percent for that customer type, and displays the discount percent. Complie and run the application to be sure that it runs correctly.
4. Add a statement to the main method that displays the string returned by the toString method of the customer type. Then, compile and run the application again to see the result of this method.
5. Add a toString method to the CustomerType enumeration. This method should return a string that contains “Retail customer”, “Trade customer”, or “College customer” depending on the customer type. Compile this class, then run the CustomerTypeApp class again to view the results of the toString method.
Java Code:public class CustomerTypeApp { public static void main(String[] args); // instance variables here double discountPercent = 0; String customerType = "retail"; private Object CustomerType; private static class CustomerType { public CustomerType() { } { } public static final Object Retail = new Object(); public static final Object Trade = new Object(); public static final Object College = new Object(); private CustomerType retail; { // display a welcome message System.out.println("Welcome to the Customer Type Test application\n"); // get and display the discount percent for a customer type { double discountPercent = getDiscountPercent(retail); System.out.println("discountPercent: " + discountPercent + "\n"); } // display the value of the toString method of a customer type System.out.println("toString: " + retail.toString() + "\n"); } private double getDiscountPercent(CustomerType retail) { throw new UnsupportedOperationException("Not yet implemented"); } // a method that accepts a CustomerType enumeration } public void setDiscount(String custType){ String customerType = custType; switch (customerType) { case "retail": discountPercent = 0.10; break; case "trade": discountPercent = 0.30; break; case "college": discountPercent = 0.20; break; } } public double getDiscount(){ return discountPercent; } }Java Code:public enum CustomerType { RETAIL("Retail customer"), TRADE("Trade customer"), STUDENT("Student customer"); private final String description; private CustomerType(String description) { this.description = description; } @Override public String toString() { return description; } }
- 02-07-2013, 09:11 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: Problem with Enum assignment
Change line#4 to:
kind regards,Java Code:public static void main(String[] args) {
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-07-2013, 10:14 AM #3
Member
- Join Date
- Feb 2013
- Location
- Scenic Flint, MI
- Posts
- 6
- Rep Power
- 0
Re: Problem with Enum assignment
Thank you so much Jos! That figures it was a silly oversight. That fixed that error, however, when I went to re-test it, all of these errors popped up! Quite frustrating because I feel like I've added too much code to a simple assignment!
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:9: error: illegal start of expression
{private Object CustomerType;
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:10: error: illegal start of expression
private static class CustomerType {
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:10: error: illegal start of expression
private static class CustomerType {
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:10: error: ';' expected
private static class CustomerType {
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:10: error: not a statement
private static class CustomerType {
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:10: error: ';' expected
private static class CustomerType {
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:11: error: illegal start of expression
public CustomerType() {
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:11: error: ';' expected
public CustomerType() {
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:14: error: illegal start of expression
} public static final Object Retail = new Object();
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:14: error: illegal start of expression
} public static final Object Retail = new Object();
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:14: error: ';' expected
} public static final Object Retail = new Object();
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:15: error: illegal start of expression
public static final Object Trade = new Object();
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:15: error: illegal start of expression
public static final Object Trade = new Object();
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:15: error: ';' expected
public static final Object Trade = new Object();
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:16: error: illegal start of expression
public static final Object College = new Object();
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:16: error: illegal start of expression
public static final Object College = new Object();
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:16: error: ';' expected
public static final Object College = new Object();
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:17: error: illegal start of expression
private CustomerType retail;
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:32: error: illegal start of expression
private double getDiscountPercent(CustomerType retail) {
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:32: error: ';' expected
private double getDiscountPercent(CustomerType retail) {
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:32: error: ';' expected
private double getDiscountPercent(CustomerType retail) {
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:39: error: illegal start of expression
public void setDiscount(String custType){
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:39: error: illegal start of expression
public void setDiscount(String custType){
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:39: error: ';' expected
public void setDiscount(String custType){
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:39: error: ';' expected
public void setDiscount(String custType){
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:54: error: illegal start of expression
public double getDiscount(){
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:54: error: ';' expected
public double getDiscount(){
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\src\CustomerTypeApp.java:60: error: reached end of file while parsing
}
28 errors
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\nbproject\build-impl.xml:900: The following error occurred while executing this line:
C:\Users\ArtisticMess\Desktop\Java Program\java\netbeans\ex_starts\ch10_ex4_Enumerati on\nbproject\build-impl.xml:265: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)
- 02-07-2013, 10:22 AM #4
Re: Problem with Enum assignment
Correct indentation and count your curly brackets.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
Similar Threads
-
having problem with a class, interface, or enum expected error msg plss help
By victorious in forum New To JavaReplies: 1Last Post: 10-03-2012, 09:38 PM -
problem with enum in my coin toss program.
By Azaera in forum New To JavaReplies: 5Last Post: 06-21-2012, 05:09 AM -
Creating axis2 webservice-Enum type problem
By sertacyilmaz in forum Advanced JavaReplies: 1Last Post: 09-13-2011, 10:51 AM -
public static enum vs enum class
By Dipke in forum New To JavaReplies: 3Last Post: 08-30-2011, 10:45 AM -
enum problem
By guilty in forum New To JavaReplies: 3Last Post: 09-19-2010, 12:44 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks