Thread: I need JAVA HELP homework please its for in 2 hours thanks

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 I need JAVA HELP homework please its for in 2 hours thanks 
    Registered Member
    Join Date
    Nov 2009
    Posts
    185
    Thanks given
    5
    Thanks received
    0
    Rep Power
    1
    A- Create a class called "Salesperson", with the following attributes:



    •firstName as String
    •lastName as String
    •baseSalary as integer
    •commision as integer
    •monthSale as integer


    This class should also have the following methods:


    •A constructor - to build an instance of "Salesperon" with first name, last name, base salary and commission given as parameters. To simplify things, we are using integers for money values, so whole numbers, without decimals would be fine. The "commission" is a whole number, but will be treated as a percent. For example, a commission of 10 means 10%. "monthSales" is monthly sales and is not set in the constructor.

    •CalculatePay - This method should receive an integer as a parameter for the monthly sales and should calculate and return the total pay for that person in that month.


    B- Create a class called "MyCompany" - This class should contain your main method and do the following:


    1.Create an array of 10 Salesperons, called "myEmployees" with the following data:
    First Name
    Last Name
    Salary
    Commission

    John
    Brown
    4500
    10

    Mary
    Jones
    4725
    12

    Jack
    Taylor
    4200
    8

    Andrew
    Simms
    3900
    11

    Larry
    Black
    3800
    9

    Joan
    O'Neal
    4600
    14

    Barbara
    Madden
    4750
    9

    Alex
    Wayne
    3960
    11

    Brian
    Warner
    3780
    12

    Max
    Wills
    4100
    8


















    2.Create an a array of 10 integers, called "sales", with the following numbers:
    3450, 2800, 4600, 3568, 5112, 2978, 5211, 3987, 2994, 4957
    These are sales for a given month and correspond to the salespeople. For example, sales[0] is the sales for the first salesperson, etc.


    3.Go through a loop, call the "CalculatePay" method of each salesperson and pass this month's sales to it and print the name and monthly pay for each employee on the screen. This would serve as a monthly payroll report.


    When finished, upload your two classes here.

    Thanks
    Update: Creation X vAlpha 1.0 - 80%


    -Removed

     

  2. #2  
    Community Veteran

    Cascade's Avatar
    Join Date
    Oct 2006
    Posts
    1,023
    Thanks given
    12
    Thanks received
    27
    Rep Power
    912
    Salesperson class:
    Code:
    public class Salesperson {
    
        private String firstName;
        private String lastName;
        private int baseSalary;
        private int commision;
        private int monthSale;
    
        public Salesperson(String firstName, String lastName, int baseSalary, int commision) {
            this.firstName = firstName;
            this.lastName = lastName;
            this.baseSalary = baseSalary;
            this.commision = commision;
        }
    
        public int calculatePay(int sales) {
            return getBaseSalary() + (sales * getCommision());
        }
    
        public String getFirstName() {
            return firstName;
        }
    
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }
    
        public String getLastName() {
            return lastName;
        }
    
        public void setLastName(String lastName) {
            this.lastName = lastName;
        }
    
        public int getBaseSalary() {
            return baseSalary;
        }
    
        public void setBaseSalary(int baseSalary) {
            this.baseSalary = baseSalary;
        }
    
        public int getCommision() {
            return commision;
        }
    
        public void setCommision(int commision) {
            this.commision = commision;
        }
    
        public int getMonthSale() {
            return monthSale;
        }
    
        public void setMonthSale(int monthSale) {
            this.monthSale = monthSale;
        }
    }
    MyCompany class:
    Code:
    public class MyCompany {
    
        public static void main(String[] args) {
            Salesperson[] myEmployees = {
                new Salesperson("John", "Brown", 4500, 10),
                new Salesperson("Mary", "Jones", 4725, 12),
                new Salesperson("Jack", "Taylor", 4200, 8),
                new Salesperson("Andrew", "Simms", 3900, 11),
                new Salesperson("Larry", "Black", 3800, 9),
                new Salesperson("Joan", "O'Neal", 4600, 14),
                new Salesperson("Barbara", "Madden", 4750, 9),
                new Salesperson("Alex", "Wayne", 3960, 11),
                new Salesperson("Brian", "Warner", 3780, 12),
                new Salesperson("Max", "Wills", 4100, 8),
            };
    
            int[] sales = { 3450, 2800, 4600, 3568, 5112, 2978, 5211, 3987, 2994, 4957 };
            
            for(int i = 0; i < myEmployees.length; i++) {
                System.out.println("Employee Name: "+myEmployees[i].getFirstName()+" "+myEmployees[i].getLastName()+" Pay: "+myEmployees[i].calculatePay(sales[i]));
            }
        }
    }
    Enjoy.
     

  3. #3  
    Banned

    Join Date
    May 2008
    Posts
    823
    Thanks given
    16
    Thanks received
    31
    Rep Power
    0
    Quote Originally Posted by Cascade View Post
    Salesperson class:
    Code:
    public class Salesperson {
    
        private String firstName;
        private String lastName;
        private int baseSalary;
        private int commision;
        private int monthSale;
    
        public Salesperson(String firstName, String lastName, int baseSalary, int commision) {
            this.firstName = firstName;
            this.lastName = lastName;
            this.baseSalary = baseSalary;
            this.commision = commision;
        }
    
        public int calculatePay(int sales) {
            return getBaseSalary() + (sales * getCommision());
        }
    
        public String getFirstName() {
            return firstName;
        }
    
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }
    
        public String getLastName() {
            return lastName;
        }
    
        public void setLastName(String lastName) {
            this.lastName = lastName;
        }
    
        public int getBaseSalary() {
            return baseSalary;
        }
    
        public void setBaseSalary(int baseSalary) {
            this.baseSalary = baseSalary;
        }
    
        public int getCommision() {
            return commision;
        }
    
        public void setCommision(int commision) {
            this.commision = commision;
        }
    
        public int getMonthSale() {
            return monthSale;
        }
    
        public void setMonthSale(int monthSale) {
            this.monthSale = monthSale;
        }
    }
    MyCompany class:
    Code:
    public class MyCompany {
    
        public static void main(String[] args) {
            Salesperson[] myEmployees = {
                new Salesperson("John", "Brown", 4500, 10),
                new Salesperson("Mary", "Jones", 4725, 12),
                new Salesperson("Jack", "Taylor", 4200, 8),
                new Salesperson("Andrew", "Simms", 3900, 11),
                new Salesperson("Larry", "Black", 3800, 9),
                new Salesperson("Joan", "O'Neal", 4600, 14),
                new Salesperson("Barbara", "Madden", 4750, 9),
                new Salesperson("Alex", "Wayne", 3960, 11),
                new Salesperson("Brian", "Warner", 3780, 12),
                new Salesperson("Max", "Wills", 4100, 8),
            };
    
            int[] sales = { 3450, 2800, 4600, 3568, 5112, 2978, 5211, 3987, 2994, 4957 };
            
            for(int i = 0; i < myEmployees.length; i++) {
                System.out.println("Employee Name: "+myEmployees[i].getFirstName()+" "+myEmployees[i].getLastName()+" Pay: "+myEmployees[i].calculatePay(sales[i]));
            }
        }
    }
    Enjoy.
    Beat me to it lol.
     

  4. #4  
    Renown Programmer
    veer's Avatar
    Join Date
    Nov 2007
    Posts
    3,747
    Thanks given
    354
    Thanks received
    1,368
    Rep Power
    3032
    cascade that is atrocious.
     

  5. #5  
    Fat Cookies
    Guest
    Quote Originally Posted by super_ View Post
    cascade that is atrocious.
    this.
    this topic appeared on a different forum so i did it too, but much better.


    Salesperson.java
    Code:
    
    /**
     *
     * @author fc
     */
    public class Salesperson {
    
        private String firstName;
        private String lastName;
        private int baseSalary;
        private int commision;
        private int monthSale;
    
        public Salesperson(String firstName, String lastName, int baseSalary, int commision) {
            this.firstName = firstName;
            this.lastName = lastName;
            this.baseSalary = baseSalary;
            this.commision = commision;
        }
    
        public String getFirstName() {
            return firstName;
        }
    
        public String getLastName() {
            return lastName;
        }
    
        public int calculatePay(int monthlySales) {
            return baseSalary + (monthlySales * commision / 100);
        }
    }
    MyCompany.java
    Code:
    
    /**
     *
     * @author fc
     */
    public class MyCompany {
    
        public static Salesperson[] myEmployees = {new Salesperson("John", "Brown", 4500, 10),
            new Salesperson("Mary", "Jones", 4725, 12),
            new Salesperson("Jack", "Taylor", 4200, 8),
            new Salesperson("Jack", "Taylor", 4200, 8),
            new Salesperson("Andrew", "Simms ", 3900, 11),
            new Salesperson("Larry", "Black", 3800, 9),
            new Salesperson("Joan", " O \' Neal", 4600, 14),
            new Salesperson("Barbara", "Madden", 4750, 9),
            new Salesperson("Alex", "Wayne", 3960, 11),
            new Salesperson("Brian", "Warner", 3780, 12),
            new Salesperson("Max", "Wills", 4800, 8)
        };
        public static int[] sales = {3450, 2800, 4600, 3568, 5112, 2978, 5211, 3987, 2994, 4957};
    
        public static void main(String[] args) {
            for (int i = 0; i < sales.length; i++) {
                Salesperson sp = myEmployees[i];
                System.out.println(sp.getFirstName()+" "+sp.getLastName()+" : "+sp.calculatePay(sales[i]));
            }
        }
    }
     

  6. #6  
    Community Veteran

    Cascade's Avatar
    Join Date
    Oct 2006
    Posts
    1,023
    Thanks given
    12
    Thanks received
    27
    Rep Power
    912
    Quote Originally Posted by Fat Cookies View Post
    this.
    this topic appeared on a different forum so i did it too, but much better.


    Salesperson.java
    Code:
    
    /**
     *
     * @author fc
     */
    public class Salesperson {
    
        private String firstName;
        private String lastName;
        private int baseSalary;
        private int commision;
        private int monthSale;
    
        public Salesperson(String firstName, String lastName, int baseSalary, int commision) {
            this.firstName = firstName;
            this.lastName = lastName;
            this.baseSalary = baseSalary;
            this.commision = commision;
        }
    
        public String getFirstName() {
            return firstName;
        }
    
        public String getLastName() {
            return lastName;
        }
    
        public int calculatePay(int monthlySales) {
            return baseSalary + (monthlySales * commision / 100);
        }
    }
    MyCompany.java
    Code:
    
    /**
     *
     * @author fc
     */
    public class MyCompany {
    
        public static Salesperson[] myEmployees = {new Salesperson("John", "Brown", 4500, 10),
            new Salesperson("Mary", "Jones", 4725, 12),
            new Salesperson("Jack", "Taylor", 4200, 8),
            new Salesperson("Jack", "Taylor", 4200, 8),
            new Salesperson("Andrew", "Simms ", 3900, 11),
            new Salesperson("Larry", "Black", 3800, 9),
            new Salesperson("Joan", " O \' Neal", 4600, 14),
            new Salesperson("Barbara", "Madden", 4750, 9),
            new Salesperson("Alex", "Wayne", 3960, 11),
            new Salesperson("Brian", "Warner", 3780, 12),
            new Salesperson("Max", "Wills", 4800, 8)
        };
        public static int[] sales = {3450, 2800, 4600, 3568, 5112, 2978, 5211, 3987, 2994, 4957};
    
        public static void main(String[] args) {
            for (int i = 0; i < sales.length; i++) {
                Salesperson sp = myEmployees[i];
                System.out.println(sp.getFirstName()+" "+sp.getLastName()+" : "+sp.calculatePay(sales[i]));
            }
        }
    }
    ROFL, you have done not one thing different. You've just proved your idiocy.

    @super_:
    With something so simple I doubt there is a 'super cool way' to do it, assuming you mean the code that is.
     

  7. #7  
    Renown Programmer
    veer's Avatar
    Join Date
    Nov 2007
    Posts
    3,747
    Thanks given
    354
    Thanks received
    1,368
    Rep Power
    3032
    you had unneeded set and get methods when in truth you don't need any (String name() { return firstName + lastName; }) and used accessors when direct access was possible.
     

  8. #8  
    Community Veteran

    Cascade's Avatar
    Join Date
    Oct 2006
    Posts
    1,023
    Thanks given
    12
    Thanks received
    27
    Rep Power
    912
    Quote Originally Posted by super_ View Post
    you had unneeded set and get methods when in truth you don't need any (String name() { return firstName + lastName; }) and used accessors when direct access was possible.
    Netbeans automatically changes any direct access with the getters and setters when you use the encapsulate fields function.

    Not any doing of my own. I didn't actually notice that.
     

  9. #9  
    Registered Member

    Join Date
    Jun 2007
    Posts
    2,237
    Thanks given
    267
    Thanks received
    411
    Rep Power
    1283
    Quote Originally Posted by Cascade View Post
    Netbeans automatically changes any direct access with the getters and setters when you use the encapsulate fields function.

    Not any doing of my own. I didn't actually notice that.
    When you use the enscapulation tool in netbeans go to the bottom left and uncheck the box "Use accessors ... direct access" to stop that.
    Don't worry, Be happy.
     

  10. #10  
    Community Veteran

    Cascade's Avatar
    Join Date
    Oct 2006
    Posts
    1,023
    Thanks given
    12
    Thanks received
    27
    Rep Power
    912
    Quote Originally Posted by Daniel View Post
    When you use the enscapulation tool in netbeans go to the bottom left and uncheck the box "Use accessors ... direct access" to stop that.
    Thanks, never seen that until now, cheers.
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

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