<?xml version="1.0" encoding="UTF-8"?>
<quiz>
  <question type="category">
    <category><text>$course$/top/CodeLab Starter/Java and C# OOP Basics</text></category>
  </question>
  <question type="codelab">
    <name><text>01. Java: Product of two integers (prefix/suffix)</text></name>
    <questiontext format="html"><text><![CDATA[<p>A <code>Scanner in</code> is already open. Read two integers and print their product (write only the statements).</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>java</language>
    <template></template>
    <solution>        int a = in.nextInt();
        int b = in.nextInt();
        System.out.println(a * b);
</solution>
    <prefix>import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
</prefix>
    <suffix>    }
}
</suffix>
    <tests>[{"stdin":"6 7\n","expected":"42\n","code":"","hidden":false,"weight":1},{"stdin":"-3 5\n","expected":"-15\n","code":"","hidden":false,"weight":1},{"stdin":"1000 1000\n","expected":"1000000\n","code":"","hidden":true,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>02. Java: Factorial loop</text></name>
    <questiontext format="html"><text><![CDATA[<p>Read an integer <code>n</code> (0 &le; n &le; 20) and print <code>n!</code>.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>java</language>
    <template>import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
    }
}
</template>
    <solution>import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long f = 1;
        for (int i = 2; i &lt;= n; i++) {
            f *= i;
        }
        System.out.println(f);
    }
}
</solution>
    <prefix></prefix>
    <suffix></suffix>
    <tests>[{"stdin":"5\n","expected":"120\n","code":"","hidden":false,"weight":1},{"stdin":"0\n","expected":"1\n","code":"","hidden":false,"weight":1},{"stdin":"12\n","expected":"479001600\n","code":"","hidden":true,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>03. Java: Rectangle class</text></name>
    <questiontext format="html"><text><![CDATA[<p>Read width and height (integers), create a <code>Rectangle</code> object with <code>area()</code> and <code>perimeter()</code> methods, and print <code>area perimeter</code>.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>java</language>
    <template></template>
    <solution>import java.util.Scanner;

class Rectangle {
    int w, h;
    Rectangle(int w, int h) { this.w = w; this.h = h; }
    int area() { return w * h; }
    int perimeter() { return 2 * (w + h); }
}

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Rectangle r = new Rectangle(in.nextInt(), in.nextInt());
        System.out.println(r.area() + " " + r.perimeter());
    }
}
</solution>
    <prefix></prefix>
    <suffix></suffix>
    <tests>[{"stdin":"3 4\n","expected":"12 14\n","code":"","hidden":false,"weight":1},{"stdin":"10 5\n","expected":"50 30\n","code":"","hidden":false,"weight":1},{"stdin":"1 1\n","expected":"1 4\n","code":"","hidden":true,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>04. Java: Sum positive numbers</text></name>
    <questiontext format="html"><text><![CDATA[<p>Read <code>n</code> followed by <code>n</code> integers and print the sum of the strictly positive ones.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>java</language>
    <template></template>
    <solution>import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int sum = 0;
        for (int i = 0; i &lt; n; i++) {
            int x = in.nextInt();
            if (x &gt; 0) sum += x;
        }
        System.out.println(sum);
    }
}
</solution>
    <prefix></prefix>
    <suffix></suffix>
    <tests>[{"stdin":"5\n-2 4 0 7 -1\n","expected":"11\n","code":"","hidden":false,"weight":1},{"stdin":"3\n-1 -2 -3\n","expected":"0\n","code":"","hidden":false,"weight":1},{"stdin":"2\n10 20\n","expected":"30\n","code":"","hidden":true,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>05. C#: Star triangle</text></name>
    <questiontext format="html"><text><![CDATA[<p>Read an integer <code>n</code> and print a right triangle of <code>*</code> with <code>n</code> rows.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>csharp</language>
    <template>using System;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
    }
}
</template>
    <solution>using System;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        for (int i = 1; i &lt;= n; i++)
        {
            Console.WriteLine(new string('*', i));
        }
    }
}
</solution>
    <prefix></prefix>
    <suffix></suffix>
    <tests>[{"stdin":"3\n","expected":"*\n**\n***\n","code":"","hidden":false,"weight":1},{"stdin":"1\n","expected":"*\n","code":"","hidden":false,"weight":1},{"stdin":"4\n","expected":"*\n**\n***\n****\n","code":"","hidden":true,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>06. C#: Count words</text></name>
    <questiontext format="html"><text><![CDATA[<p>Read a line of text and print how many whitespace-separated words it contains.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>csharp</language>
    <template></template>
    <solution>using System;

class Program
{
    static void Main()
    {
        string line = Console.ReadLine() ?? "";
        string[] words = line.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        Console.WriteLine(words.Length);
    }
}
</solution>
    <prefix></prefix>
    <suffix></suffix>
    <tests>[{"stdin":"Hello from CodeLab\n","expected":"3\n","code":"","hidden":false,"weight":1},{"stdin":"  spaced   out  \n","expected":"2\n","code":"","hidden":false,"weight":1},{"stdin":"one\n","expected":"1\n","code":"","hidden":true,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>07. C#: BankAccount class</text></name>
    <questiontext format="html"><text><![CDATA[<p>Read initial balance, deposit amount, and withdrawal amount (integers). Implement a <code>BankAccount</code> class where withdrawal succeeds only if balance is sufficient, and print the final balance.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>csharp</language>
    <template></template>
    <solution>using System;

class BankAccount
{
    public int Balance { get; private set; }
    public BankAccount(int initial) { Balance = initial; }
    public void Deposit(int amount) { Balance += amount; }
    public void Withdraw(int amount) { if (amount &lt;= Balance) Balance -= amount; }
}

class Program
{
    static void Main()
    {
        var parts = Console.ReadLine().Split();
        var acc = new BankAccount(int.Parse(parts[0]));
        acc.Deposit(int.Parse(parts[1]));
        acc.Withdraw(int.Parse(parts[2]));
        Console.WriteLine(acc.Balance);
    }
}
</solution>
    <prefix></prefix>
    <suffix></suffix>
    <tests>[{"stdin":"100 50 30\n","expected":"120\n","code":"","hidden":false,"weight":1},{"stdin":"50 10 100\n","expected":"60\n","code":"","hidden":false,"weight":1},{"stdin":"0 25 25\n","expected":"0\n","code":"","hidden":true,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
  <question type="codelab">
    <name><text>08. C#: Minimum and maximum of array</text></name>
    <questiontext format="html"><text><![CDATA[<p>Read space-separated integers on one line and print <code>min max</code>.</p>]]></text></questiontext>
    <generalfeedback format="html"><text></text></generalfeedback>
    <defaultgrade>1.0000000</defaultgrade>
    <penalty>0.1000000</penalty>
    <hidden>0</hidden>
    <language>csharp</language>
    <template></template>
    <solution>using System;
using System.Linq;

class Program
{
    static void Main()
    {
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine($"{a.Min()} {a.Max()}");
    }
}
</solution>
    <prefix></prefix>
    <suffix></suffix>
    <tests>[{"stdin":"4 9 -2 7\n","expected":"-2 9\n","code":"","hidden":false,"weight":1},{"stdin":"5\n","expected":"5 5\n","code":"","hidden":false,"weight":1},{"stdin":"-10 -3 -20\n","expected":"-20 -3\n","code":"","hidden":true,"weight":1}]</tests>
    <showtests>1</showtests>
    <comparison>spaces</comparison>
    <tolerance>0.001</tolerance>
    <cputime>0</cputime>
    <memorylimit>0</memorylimit>
    <noassist>0</noassist>
    <parsons>0</parsons>
    <distractors></distractors>
    <aihints>0</aihints>
    <timelimit>0</timelimit>
    <ordercheck>0</ordercheck>
    <files>[]</files>
    <gaps>0</gaps>
    <compiler></compiler>
    <std></std>
    <rules></rules>
  </question>
</quiz>
