Results 1 to 4 of 4
  1. #1
    Indigrace is offline Member
    Join Date
    Feb 2013
    Location
    Scenic Flint, MI
    Posts
    6
    Rep Power
    0

    Default 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;  
        }  
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,002
    Blog Entries
    7
    Rep Power
    20

    Default Re: Problem with Enum assignment

    Change line#4 to:

    Java Code:
       public static void main(String[] args) {
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Indigrace is offline Member
    Join Date
    Feb 2013
    Location
    Scenic Flint, MI
    Posts
    6
    Rep Power
    0

    Default Re: Problem with Enum assignment

    Quote Originally Posted by JosAH View Post
    Change line#4 to:

    Java Code:
       public static void main(String[] args) {
    kind regards,

    Jos
    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)

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    6

    Default 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

  1. Replies: 1
    Last Post: 10-03-2012, 09:38 PM
  2. problem with enum in my coin toss program.
    By Azaera in forum New To Java
    Replies: 5
    Last Post: 06-21-2012, 05:09 AM
  3. Creating axis2 webservice-Enum type problem
    By sertacyilmaz in forum Advanced Java
    Replies: 1
    Last Post: 09-13-2011, 10:51 AM
  4. public static enum vs enum class
    By Dipke in forum New To Java
    Replies: 3
    Last Post: 08-30-2011, 10:45 AM
  5. enum problem
    By guilty in forum New To Java
    Replies: 3
    Last Post: 09-19-2010, 12:44 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •