Table of Contents

    Assignment - Class 8 - Programming

    ASSIGNMENT — CLASS 8

    Assignment — Programming (Java & BlueJ)

    Practice, Code and Master Java Programming! This complete assignment covers Java basics — variables, data types, operators, input/output, and simple programs. Complete all three sections and aim for 100 marks!

    Assignment Overview

    Assignment Details:
    • Total Marks: 100
    • Section A (Theory): 30 marks
    • Section B (Programs): 50 marks
    • Section C (Output Prediction): 20 marks
    • Language: Java (BlueJ IDE)
    • Duration: 1 week

    Motivational Message

    This assignment is your gateway to becoming a programmer! Every question and program you complete builds your coding skills. Take it seriously, and you'll enjoy programming for life!

    Objectives

    Learning Goals

    • ✅ Understand programming basics.
    • ✅ Learn Java syntax and structure.
    • ✅ Use variables and data types.
    • ✅ Apply arithmetic and assignment operators.
    • ✅ Handle input and output.
    • ✅ Write and run Java programs in BlueJ.

    Section A: Theory Questions (30 Marks)

    Q1. What is programming? Name any two programming languages. (6 marks)

    Answer

    Programming is the process of writing instructions in a specific language that a computer can understand and execute to perform a task.

    Examples of programming languages: Java, Python (or C, C++, JavaScript, etc.)

    Q2. What is a variable? Give its syntax with an example. (6 marks)

    Answer

    A variable is a named storage location in memory that holds a value which can be changed during program execution.

    Syntax: datatype variableName = value;

    int age = 15;
    String name = "Ravi";
    double marks = 85.5;
    char grade = 'A';

    Q3. Name any four data types in Java with examples. (6 marks)

    Answer
    Data Type Description Example
    int Whole numbers int age = 15;
    double Decimal numbers double price = 99.99;
    char Single character char grade = 'A';
    String Sequence of characters String name = "Ravi";
    boolean true or false boolean isPass = true;

    Q4. What are arithmetic operators? List them with examples. (6 marks)

    Answer

    Arithmetic operators perform mathematical operations on values.

    Operator Meaning Example
    +Addition5 + 3 = 8
    -Subtraction5 - 3 = 2
    *Multiplication5 * 3 = 15
    /Division10 / 2 = 5
    %Modulo (Remainder)10 % 3 = 1

    Q5. What is the assignment operator? Give an example. (6 marks)

    Answer

    The assignment operator = assigns the value on its right side to the variable on its left side.

    Example:

    int age = 15;      // Assigns 15 to age
    double price = 99.99;  // Assigns 99.99 to price
    String name = "Ravi";  // Assigns "Ravi" to name

    Compound assignment operators: +=, -=, *=, /=, %=

    int x = 5;
    x += 3;   // Same as x = x + 3, now x = 8

    Section B: Program Writing (50 Marks)

    P1. Write a program to display "Hello, World!". (10 marks)

    public class HelloWorld {
        public static void main(String[] args) {
            System.out.println("Hello, World!");
        }
    }
    Output Hello, World!

    P2. Program to add two numbers entered by user. (10 marks)

    import java.util.Scanner;
    
    public class AddTwoNumbers {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
    
            System.out.print("Enter first number: ");
            int a = sc.nextInt();
    
            System.out.print("Enter second number: ");
            int b = sc.nextInt();
    
            int sum = a + b;
            System.out.println("Sum = " + sum);
        }
    }
    Sample Run
    • Input: 10, 20 → Output: Sum = 30
    • Input: 5, 7 → Output: Sum = 12

    P3. Program to calculate area of a rectangle. (10 marks)

    import java.util.Scanner;
    
    public class RectangleArea {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
    
            System.out.print("Enter length: ");
            double length = sc.nextDouble();
    
            System.out.print("Enter breadth: ");
            double breadth = sc.nextDouble();
    
            double area = length * breadth;
            System.out.println("Area of Rectangle = " + area);
        }
    }
    Sample Run
    • Input: 5, 4 → Output: Area = 20.0
    • Input: 10.5, 3 → Output: Area = 31.5

    P4. Program to convert temperature from Celsius to Fahrenheit. (10 marks)

    import java.util.Scanner;
    
    public class TemperatureConverter {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
    
            System.out.print("Enter temperature in Celsius: ");
            double celsius = sc.nextDouble();
    
            // Formula: F = (C * 9/5) + 32
            double fahrenheit = (celsius * 9.0 / 5.0) + 32;
    
            System.out.println("Temperature in Fahrenheit = " + fahrenheit);
        }
    }
    Sample Run
    • Input: 0 → Output: 32.0°F
    • Input: 100 → Output: 212.0°F
    • Input: 37 → Output: 98.6°F

    P5. Program to check if a person is eligible to vote (age >= 18). (10 marks)

    import java.util.Scanner;
    
    public class VotingEligibility {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
    
            System.out.print("Enter your age: ");
            int age = sc.nextInt();
    
            if (age >= 18) {
                System.out.println("You are eligible to vote!");
            } else {
                System.out.println("You are not eligible to vote.");
                System.out.println("You need " + (18 - age) + " more years.");
            }
        }
    }
    Sample Run
    • Input: 20 → Output: You are eligible to vote!
    • Input: 15 → Output: You are not eligible to vote. You need 3 more years.

    Section C: Output Prediction (20 Marks)

    Q1. Predict the output. (4 marks)

    int a = 10, b = 5;
    System.out.println(a + b);
    Answer: 15 Explanation: The + operator adds a (10) and b (5). Result: 15.

    Q2. Predict the output. (4 marks)

    int x = 10;
    int y = 3;
    System.out.println(x / y);
    Answer: 3 Explanation: Integer division truncates decimals. 10 / 3 = 3.333..., but as int, it's 3.

    Q3. Predict the output. (4 marks)

    int p = 15;
    int q = 4;
    System.out.println(p % q);
    Answer: 3 Explanation: The % operator gives remainder. 15 ÷ 4 = 3 remainder 3. So 15 % 4 = 3.

    Q4. Predict the output. (4 marks)

    String name = "Java";
    System.out.println("Welcome to " + name);
    Answer: Welcome to Java Explanation: The + operator concatenates strings. "Welcome to " + "Java" = "Welcome to Java".

    Q5. Predict the output. (4 marks)

    int m = 5;
    m += 3;
    System.out.println(m);
    Answer: 8 Explanation: m += 3 is same as m = m + 3. So m = 5 + 3 = 8.

    Output Prediction Summary

    Question Answer Reason
    Q11510 + 5
    Q23Integer division: 10/3
    Q3315 % 4 = remainder 3
    Q4Welcome to JavaString concatenation
    Q585 + 3 = 8

    Submission Format

    How to Submit

    • ✅ Handwritten in notebook OR typed in A4 sheets.
    • ✅ Java code with proper indentation.
    • ✅ Include test cases and outputs.
    • ✅ Screenshots of BlueJ outputs (if possible).
    • ✅ Clean handwriting/formatting.
    • ✅ Submit on time.
    • ✅ Include your name, roll number, class.

    Evaluation Criteria (Total: 100 Marks)

    Section Marks
    Section A (Theory)30
    Section B (Programs)50
    Section C (Output)20
    Total100

    Tips for Success

    Best Practices

    • 📖 Read each question carefully.
    • 📝 Write neat, readable code.
    • 📐 Use proper indentation.
    • 💬 Add comments to explain your logic.
    • 🧪 Test each program with different inputs.
    • 🎯 Follow Java naming conventions.
    • ✏️ Double-check syntax before submitting.
    • 📅 Start early, don't wait until the last minute.
    • 👨‍🏫 Ask your teacher if you get stuck.
    • 🔄 Practice similar programs beforehand.

    Common Mistakes to Avoid

    Watch Out for These!

    • ❌ Missing semicolons (;)
    • ❌ Missing braces { }
    • ❌ Incorrect class name (must match file name)
    • ❌ Not importing Scanner (for input)
    • ❌ Case-sensitive errors (Java is case-sensitive)
    • ❌ Using wrong data type
    • ❌ Integer division confusion
    • ❌ Forgetting to compile before running

    How to Run Programs in BlueJ

    1

    Create New Project

    Set up workspace

    Open BlueJ → Project → New Project → Choose location.

    2

    Create New Class

    Add your program

    Click "New Class" → Enter class name (same as file) → OK.

    3

    Write Java Code

    Enter your program

    Double-click class → Delete default → Type your code.

    4

    Compile & Run

    Test your code

    Click "Compile" → Fix errors → Right-click → main() → OK.

    Suggested Timeline (1 Week)

    Day Tasks
    Day 1Theory Questions (Q1-Q3)
    Day 2Theory Questions (Q4-Q5)
    Day 3Programs P1-P2 (Hello World, Add)
    Day 4Programs P3-P4 (Area, Temperature)
    Day 5Program P5 (Voting)
    Day 6Output Prediction (Q1-Q5)
    Day 7Review, organize, and submit!

    Did You Know?

    Fun Fact

    Java was created in 1995 by James Gosling at Sun Microsystems! It was originally called "Oak" but was later renamed to "Java" — after the coffee. Today, Java runs on over 3 billion devices worldwide!

    Bonus Challenges (Optional)

    Extra Practice

    • 🌟 Write a program to calculate simple interest (SI = P × R × T / 100).
    • 🌟 Write a program to swap two numbers using a temporary variable.
    • 🌟 Write a program to check if a number is even or odd.
    • 🌟 Write a program to find the square of a number.
    • 🌟 Write a program to calculate the perimeter of a rectangle.
    • 🌟 Write a program to find the average of three numbers.
    • 🌟 Write a program to check if a year is a leap year.
    • 🌟 Write a program to convert kilometers to miles.

    Frequently Asked Questions

    Q1. Can I use my own variable names?

    Yes! Use meaningful names. Follow camelCase (like studentName).

    Q2. What if my program has errors?

    Read the error message carefully. Common issues: missing semicolons, wrong case, or missing braces.

    Q3. Should I add comments?

    Yes! Comments earn marks and show understanding. Use // for single-line comments.

    Q4. How many test cases should I show?

    At least 2-3 different test cases showing your program works for various inputs.

    Q5. Can I use Notepad instead of BlueJ?

    Yes, but BlueJ is easier for beginners because of its visual interface. Ask your teacher's preference.

    Q6. What if I don't understand a question?

    Ask your teacher or a classmate for clarification. Don't guess — understand first.

    Q7. Should I write the class name same as file name?

    YES! In Java, if you use public class, the class name MUST match the file name (case-sensitive).

    Q8. Can I use online IDE like Replit?

    Yes, but BlueJ is standard for ICSE Class 8. If BlueJ isn't available, ask your teacher.

    Key Takeaways

    • Complete all 3 sections for full 100 marks.
    • Section A: Theory (30 marks).
    • Section B: 5 Java programs (50 marks).
    • Section C: 5 output predictions (20 marks).
    • Use proper syntax and indentation.
    • Test programs with multiple inputs.
    • Add comments to explain code.
    • Try bonus challenges for extra practice.
    • Submit on time with proper format.
    • Learn while you complete!

    Key Takeaway

    Practice, Code, and Master Java Programming! Every program you write brings you closer to being a great programmer.

    This assignment covers all the essential Java basics. Complete it thoroughly and you'll have a strong foundation to tackle more complex programming challenges ahead!

    Complete all sections. Give your best effort. You will excel in programming!

    CODE SMART, THINK CLEAR, WRITE BETTER!

    Best of Luck! Practice daily, understand deeply, and code confidently! 👍😊

    Flowchart → Visual Thinking → Smart Solutions → Better Results! 🚀