Results 1 to 3 of 3
  1. #1
    Dan C is offline Member
    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Default controlling classes

    Let me start by saying I am new to Java. I am using Netbeans IDE
    I am wondering who to create an additional class from this code I created. I am a bit confused how to create at least one class aside from the controlling class which presides in the main method. This code compiles but I need the additional class. Can anyone steer me in the right direction

    Here is my code I have as of now
    import java.util.Scanner;

    /**
    *
    * @author ***** ******
    */
    public class Week2IndAss {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {

    // This method displays the salesperson's fixed annual salary
    double monthlySalary; // Salesperson's fixed monthly salary
    monthlySalary = 4166.6666667; // monthly Salary

    double annualSalary; // Salesperson's fixed annual salary
    annualSalary = monthlySalary * 12; // 12 represents months in a year

    System.out.println("The Salesperson earns a fixed monthly salary of $"
    + monthlySalary + ".");
    System.out.println("The Salesperson earns a fixed annual salary of $"
    + annualSalary + ".");

    // This method displays the salesperson's commission rate
    int commission;
    commission = 12;

    System.out.println("The Salesperson will receive a commission of "
    + commission + "%.");
    // Creates Scanner to collect annual sales input from salesperson
    Scanner input = new Scanner(System.in);

    double annualSales; // Salesperson's annual sales

    System.out.print("Enter annual sales: ");
    annualSales = input.nextDouble();

    double commissionCalc; // Calculates commission of annual sales
    double percentCalc = commission/100.0; // Makes commission calculable
    commissionCalc = annualSales * percentCalc;

    System.out.println("The annual sales of the salesperson is $"
    + commissionCalc + " using a " + commission
    + "% commission.");

    double totalAnnualSum; // Salesperson's total annual compensation
    totalAnnualSum = annualSalary + commissionCalc;

    System.out.println("The total annual compensation of the salesperson "
    + "is: $" + totalAnnualSum + ".");

    } // end main method
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,250
    Rep Power
    19

    Default Re: controlling classes

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: controlling classes

    Your question is fairly vague and open ended. Basically you need to create an instance of class 2 in class 1 and then you can call its methods.
    Java Code:
    class Foo {
        public void doStuff() {
            System.out.println("Hello");
        }
    }
    
    class Bar {
        public static void main(String[] args) {
            Foo f = new Foo();
            f.doStuff();
        }
    }

Similar Threads

  1. Controlling GUI from another Class?
    By LucienMontierre in forum AWT / Swing
    Replies: 2
    Last Post: 06-06-2012, 12:14 AM
  2. Cursor controlling?
    By UJJAL DHAR in forum Advanced Java
    Replies: 2
    Last Post: 01-31-2011, 05:19 AM
  3. Controlling cmd from java...HELP!!
    By eponcedeleon in forum Advanced Java
    Replies: 12
    Last Post: 02-23-2010, 06:33 PM
  4. Controlling the running os process
    By Muralidharan in forum Threads and Synchronization
    Replies: 1
    Last Post: 03-26-2009, 07:03 AM
  5. controlling GC
    By ravian in forum Eclipse
    Replies: 2
    Last Post: 01-03-2008, 08:13 AM

Posting Permissions

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