Creating Packages and Importing Classes The purpose of this lab is for you to learn how to become proficient in creating packages in Java and being able to import these packages into classes in other packages. Management of different source code files and folders is key to programming organization, scalable project size, and promoting reusability in software development. Steps: Create a new Java Project named “Packages” from within Eclipse.   Following the example in the Week 6 lecture, create six packages: Main, add, subtract, multiply, divide, and modulo. ALL of these packages should be within the “src” folder in the Eclipse package Explorer. ALL of the packages should be on the same “level” in the file hierarchy.   In the “Main” package, create the “Lab04.java” file and add the needed boilerplate (“Hello, World!” style) code to create the main method for the application.   For each of the arithmetic packages (add, subtract, multiply, divide, and modulo), create a single class (you should name these files the same as the package name but capitalized; e.g. “Add.java”, “Subtract.java”, “Multiply.java”, etc.)   Follow the specifications below for detailed implementation details:   Lab 4 Specifications Inside each of the arithmetic classes (Add, Subtract, Multiply, Divide, Modulo), make sure EACH class contains the following:   Two private fields // Example Fields: private int n1; private int n2;   A constructor that passes two values that can be saved in the private fields // Example Constructor: public Add(int n1, int n2){             this.n1 = n1;             this.n2 = n2; }   The following three methods must be supported by ALL arithmetic classes: public int getResult();              // This should return the result of n1 arithmetic operator n2                                                                         // n1 + n2 for add   public void changeVals(int n1, int n2);           // This should change or “reset” the values in the                                                                         // private class fields   public String toString();          // This returns a string that displays the equation with result                                                 // e.g. “3 + 5 = 8”   Inside the “Lab04.java” file should contain the following:   All package and import statements needed to reference the other packages and classes.   Inside the main method, create class objects for each of arithmetic classes // Example: Add a = new Add(5, 3);   For each class object, make sure to ALSO print out the toString method of each to verify the current equation, call the method to change the values, and print out the toString method again to verify the changes. // Example: System.out.println(a.toString()); a.changeVals(4, 4); System.out.println(a.toString());   Verify, by running the program, that everything works as expected.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Creating Packages and Importing Classes

The purpose of this lab is for you to learn how to become proficient in creating packages in Java and being able to import these packages into classes in other packages. Management of different source code files and folders is key to programming organization, scalable project size, and promoting reusability in software development.

Steps:

  • Create a new Java Project named “Packages” from within Eclipse.

 

  • Following the example in the Week 6 lecture, create six packages: Main, add, subtract, multiply, divide, and modulo. ALL of these packages should be within the “src” folder in the Eclipse package Explorer. ALL of the packages should be on the same “level” in the file hierarchy.

 

  • In the “Main” package, create the “Lab04.java” file and add the needed boilerplate (“Hello, World!” style) code to create the main method for the application.

 

  • For each of the arithmetic packages (add, subtract, multiply, divide, and modulo), create a single class (you should name these files the same as the package name but capitalized; e.g. “Add.java”, “Subtract.java”, “Multiply.java”, etc.)

 

  • Follow the specifications below for detailed implementation details:

 

Lab 4 Specifications

Inside each of the arithmetic classes (Add, Subtract, Multiply, Divide, Modulo), make sure EACH class contains the following:

 

Two private fields

// Example Fields:

private int n1;

private int n2;

 

A constructor that passes two values that can be saved in the private fields

// Example Constructor:

public Add(int n1, int n2){

            this.n1 = n1;

            this.n2 = n2;

}

 

The following three methods must be supported by ALL arithmetic classes:

public int getResult();              // This should return the result of n1 arithmetic operator n2                                                                         // n1 + n2 for add

 

public void changeVals(int n1, int n2);           // This should change or “reset” the values in the

                                                                        // private class fields

 

public String toString();          // This returns a string that displays the equation with result

                                                // e.g. “3 + 5 = 8”

 

Inside the “Lab04.java” file should contain the following:

 

All package and import statements needed to reference the other packages and classes.

 

Inside the main method, create class objects for each of arithmetic classes

// Example:

Add a = new Add(5, 3);

 

For each class object, make sure to ALSO print out the toString method of each to verify the current equation, call the method to change the values, and print out the toString method again to verify the changes.

// Example:

System.out.println(a.toString());

a.changeVals(4, 4);

System.out.println(a.toString());

 

Verify, by running the program, that everything works as expected.

Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Linux
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education