DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Posts
    1

    Java - How to define classes

    I was wondering if someone could let me know if my basic template for making my own class(es) is right so far. It's an assignment for school so I was provided with the MainCoffee.java but I have to create my own class and use the Math class to compute shipping and total price. I'm not sure if the code will display below in the attachment but the file is .zip. (Ignore everything in comments, I will get back to that once I figure out the basic layout on how to do classes.)


    I'm pretty sure I'm going to need numLgBoxes, numMedBoxes, numSmBoxes, and totalPrice classes to do this.
    Attached Files

  2. #2
    Join Date
    Jul 2005
    Location
    the Netherlands
    Posts
    128
    Here's a start:
    Code:
    class MyJava {
    
        private int noBags = 0;
        private int largeBoxes = 0;
        private int mediumBoxes = 0;
        private int smallBoxes = 0;
        private int totPrice = 0;
    
        public MyJava(int n) {
            this.noBags = n;
        }
        
        public int price() {
            // return something
        }
        
        public int numLgBoxes() {
            // return something
        }
        
        public int numMedBoxes() {
            // return something
        }
        
        public int numSmBoxes() {
            // return something
        }
        
        public int totalPrice() {
            // return something
        }
    }
    Don't use the same variable- and method names. So if the method is called numLgBoxes don't use the same name for a variable.

Similar Threads

  1. java classes in windows and linux
    By DaveMere in forum Java
    Replies: 2
    Last Post: 08-09-2005, 01:11 PM
  2. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 06:46 AM
  3. VB/C Array parameters
    By Gastao Woelfert in forum VB Classic
    Replies: 2
    Last Post: 09-01-2000, 11:36 AM
  4. VB/C Array parameters
    By Gastao Woelfert in forum VB Classic
    Replies: 0
    Last Post: 09-01-2000, 08:59 AM
  5. Adding Columns to comboboxes through API
    By Lori Taylor in forum VB Classic
    Replies: 20
    Last Post: 06-14-2000, 11:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links