Skip to content

The-Java-Bootcamp/3.0.2-lab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lab: 3.0.2

Objective:

  • Understand the concept and importance of Arithmetic Operators and Expressions in Java development.
  • Learn how to implement Arithmetic Operators and Expressions using Java's basic syntax.
  • Explore practical applications of Arithmetic Operators and Expressions in simple calculations.
  • Identify common pitfalls and best practices when working with Arithmetic Operators and Expressions.
  • Gain hands-on experience with a complete Java example that demonstrates Arithmetic Operators and Expressions.

Prerequisites:

  • Basic understanding of Java programming.
  • Familiarity with variables and data types in Java.
  • Basic knowledge of how to run a Java program.

What You'll Achieve:

  • Develop a solid understanding of Arithmetic Operators and Expressions in Java.
  • Implement practical examples that can be applied in real-world scenarios.
  • Enhance your skills in basic Java programming and mathematical operations.

Assignment Details

In this assignment, you will create a simple Java program that demonstrates the use of various arithmetic operators and expressions. Follow these steps:

  1. Create a new Java file named ArithmeticOperatorsDemo.java.
  2. In the main method, declare and initialize the following variables:
    • int a = 10;
    • int b = 5;
    • double c = 7.5;
  3. Perform the following operations and store the results in appropriately named variables:
    • Add a and b
    • Subtract b from a
    • Multiply a and b
    • Divide a by b
    • Calculate the remainder when a is divided by b
    • Add a and c
    • Divide a by c
  • Create a more complex expression that uses multiple operators and parentheses. For example: (a + b) * (c - b) / 2
  • Use the increment (++) and decrement (--) operators on a and b.
  • Print all the results to the console with appropriate labels.

Example Output

Addition: 15
Subtraction: 5
Multiplication: 50
Division: 2
Remainder: 0
Adding int and double: 17.5
Dividing int by double: 1.3333333333333333
Complex expression result: 31.25
a after increment: 11
b after decrement: 4

Starter Code

The ArithmeticOperatorsDemo.java file contains the following starter code:

package academy.javapro.lab;

public class ArithmeticOperatorsDemo {
    public static void main(String[] args) {
        int a = 10;
        int b = 5;
        double c = 7.5;

        // TODO: Perform arithmetic operations and print results

        // TODO: Create and evaluate a complex expression

        // TODO: Use increment and decrement operators
    }
}

Hints

  • Remember that when dividing two integers, the result will be an integer (truncated).
  • When mixing integer and double operands, the result will be a double.
  • Be careful with the order of operations. Use parentheses when in doubt.
  • The increment and decrement operators can be used both as prefix (++a) and postfix (a++). They behave differently in expressions.
  • When printing results, use descriptive labels to make your output clear and readable.

Submission Instructions

  1. Fork the repository
  2. Clone your fork
  3. Navigate into the repository
  4. Implement the required methods in both ArithmeticOperatorsDemo classes
  5. Test your implementation with various inputs
  6. Git add, commit, and push to your fork
  7. Submit a pull request
    • Set the title of the pull request to your first name and last name
    • In the comment, briefly explain your implementation approach and any challenges you faced

Remember, the goal is to learn and have fun! Don't hesitate to ask for help if you get stuck.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages