diff --git a/JAVA_TO_CSHARP_EXAMPLES.md b/JAVA_TO_CSHARP_EXAMPLES.md new file mode 100644 index 0000000..52c32c2 --- /dev/null +++ b/JAVA_TO_CSHARP_EXAMPLES.md @@ -0,0 +1,573 @@ +# Java to C# Conversion Examples + +This document provides concrete examples of converting Java code from the assignments to C# equivalents. + +## ๐Ÿ”„ **Basic Syntax Conversions** + +### 1. Hello World & Basic Output + +**Java (JavaIntroduction):** +```java +public class Main { + public static void main(String[] args) { + System.out.println("Hello World!"); + System.out.println("Welcome to Java Programming"); + } +} +``` + +**C# Equivalent:** +```csharp +using System; + +class Program +{ + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + Console.WriteLine("Welcome to C# Programming"); + } +} +``` + +### 2. User Input & Variables + +**Java (JavaBasics):** +```java +import java.util.Scanner; + +class Main { + public static void main(String[] args) { + Scanner myObj = new Scanner(System.in); + System.out.println("Enter your name:"); + String userName = myObj.nextLine(); + + String output = userName.substring(0, 1).toUpperCase() + userName.substring(1); + System.out.println("Hello " + output); + } +} +``` + +**C# Equivalent:** +```csharp +using System; + +class Program +{ + static void Main(string[] args) + { + Console.WriteLine("Enter your name:"); + string userName = Console.ReadLine(); + + string output = char.ToUpper(userName[0]) + userName.Substring(1); + Console.WriteLine("Hello " + output); + } +} +``` + +### 3. Loops & Mathematical Operations + +**Java (Factorial):** +```java +import java.util.Scanner; + +class Main { + public static void main(String[] args) { + int num; + long factorial = 1; + Scanner input = new Scanner(System.in); + + System.out.println("Enter a number:"); + num = input.nextInt(); + + for(int i = 1; i <= num; ++i) { + factorial *= i; + } + System.out.printf("Factorial of %d = %d", num, factorial); + } +} +``` + +**C# Equivalent:** +```csharp +using System; + +class Program +{ + static void Main(string[] args) + { + int num; + long factorial = 1; + + Console.WriteLine("Enter a number:"); + num = int.Parse(Console.ReadLine()); + + for(int i = 1; i <= num; ++i) + { + factorial *= i; + } + Console.WriteLine($"Factorial of {num} = {factorial}"); + } +} +``` + +### 4. Random Numbers + +**Java (RandomNum):** +```java +import java.util.Scanner; + +class Main { + public static void main(String args[]) { + int min, max; + Scanner input = new Scanner(System.in); + + System.out.println("Enter minimum value: "); + min = input.nextInt(); + System.out.println("Enter maximum value: "); + max = input.nextInt(); + + int random_int = (int) Math.floor(Math.random() * (max - min + 1) + min); + System.out.println("Random value: " + random_int); + } +} +``` + +**C# Equivalent:** +```csharp +using System; + +class Program +{ + static void Main(string[] args) + { + int min, max; + Random rand = new Random(); + + Console.WriteLine("Enter minimum value: "); + min = int.Parse(Console.ReadLine()); + Console.WriteLine("Enter maximum value: "); + max = int.Parse(Console.ReadLine()); + + int randomInt = rand.Next(min, max + 1); + Console.WriteLine("Random value: " + randomInt); + } +} +``` + +## ๐ŸŽฏ **Object-Oriented Programming Examples** + +### 5. Basic Class Creation + +**Java (ClassesForRealWorldObject):** +```java +class Body { + public Body() { + int legs = 2; + int arms = 2; + + running(legs); + training(arms); + } + + public void running(int legs) { + System.out.println("I am running using my " + legs + " legs."); + } + + void training(int arms) { + System.out.println("I train my " + arms + " arms."); + } +} + +class Main { + public static void main(String[] args) { + Body person = new Body(); + } +} +``` + +**C# Equivalent:** +```csharp +using System; + +class Body +{ + public Body() + { + int legs = 2; + int arms = 2; + + Running(legs); + Training(arms); + } + + public void Running(int legs) + { + Console.WriteLine($"I am running using my {legs} legs."); + } + + public void Training(int arms) + { + Console.WriteLine($"I train my {arms} arms."); + } +} + +class Program +{ + static void Main(string[] args) + { + Body person = new Body(); + Console.ReadKey(); // Wait for key press + } +} +``` + +### 6. Advanced OOP with Inheritance + +**Java (GuessingGameInOOP - Simplified):** +```java +abstract class GameSet { + private String name; + private String type; + + public GameSet(String name, String type) { + this.name = name; + this.type = type; + } + + public String getName() { return name; } + public String getType() { return type; } +} + +class NumberGameSet extends GameSet { + public NumberGameSet() { + super("Number", "number"); + } +} +``` + +**C# Equivalent:** +```csharp +using System; + +abstract class GameSet +{ + private string name; + private string type; + + public GameSet(string name, string type) + { + this.name = name; + this.type = type; + } + + public string Name { get { return name; } } + public string Type { get { return type; } } + + // Or using auto-properties: + // public string Name { get; private set; } + // public string Type { get; private set; } +} + +class NumberGameSet : GameSet +{ + public NumberGameSet() : base("Number", "number") + { + } +} +``` + +## ๐Ÿ“Š **Array and Collection Examples** + +### 7. Array Operations + +**Java (ArrayAndStringTask1 - Simplified):** +```java +import java.util.Arrays; + +public class Main { + public static void main(String[] args) { + int[] intArray = {1789, 2035, 1899, 1456, 2013}; + String[] strArray = {"Java", "Python", "C#", "JavaScript"}; + + System.out.println("Original array: " + Arrays.toString(intArray)); + Arrays.sort(intArray); + System.out.println("Sorted array: " + Arrays.toString(intArray)); + + Arrays.sort(strArray); + System.out.println("Sorted strings: " + Arrays.toString(strArray)); + } +} +``` + +**C# Equivalent:** +```csharp +using System; +using System.Linq; + +class Program +{ + static void Main(string[] args) + { + int[] intArray = {1789, 2035, 1899, 1456, 2013}; + string[] strArray = {"Java", "Python", "C#", "JavaScript"}; + + Console.WriteLine("Original array: [" + string.Join(", ", intArray) + "]"); + Array.Sort(intArray); + Console.WriteLine("Sorted array: [" + string.Join(", ", intArray) + "]"); + + Array.Sort(strArray); + Console.WriteLine("Sorted strings: [" + string.Join(", ", strArray) + "]"); + + // Alternative using LINQ: + // var sortedInts = intArray.OrderBy(x => x).ToArray(); + // var sortedStrings = strArray.OrderBy(x => x).ToArray(); + } +} +``` + +## ๐Ÿ” **String Algorithms Example** + +### 8. ROT13 Cipher + +**Java (ROT13Cipher - Simplified):** +```java +class Main { + static String encipher(String text) { + String result = ""; + + for (char c : text.toCharArray()) { + if (c >= 'a' && c <= 'z') { + result += (char)((c - 'a' + 13) % 26 + 'a'); + } else if (c >= 'A' && c <= 'Z') { + result += (char)((c - 'A' + 13) % 26 + 'A'); + } else { + result += c; + } + } + return result; + } + + public static void main(String[] args) { + String text = "Hello World"; + String encrypted = encipher(text); + System.out.println("Encrypted: " + encrypted); + } +} +``` + +**C# Equivalent:** +```csharp +using System; +using System.Text; + +class Program +{ + static string Encipher(string text) + { + StringBuilder result = new StringBuilder(); + + foreach (char c in text) + { + if (c >= 'a' && c <= 'z') + { + result.Append((char)((c - 'a' + 13) % 26 + 'a')); + } + else if (c >= 'A' && c <= 'Z') + { + result.Append((char)((c - 'A' + 13) % 26 + 'A')); + } + else + { + result.Append(c); + } + } + return result.ToString(); + } + + static void Main(string[] args) + { + string text = "Hello World"; + string encrypted = Encipher(text); + Console.WriteLine($"Encrypted: {encrypted}"); + } +} +``` + +## ๐Ÿ”ง **Key C# Differences and Advantages** + +### Properties vs Getter/Setter Methods +**Java:** +```java +private String name; +public String getName() { return name; } +public void setName(String name) { this.name = name; } +``` + +**C#:** +```csharp +public string Name { get; set; } +// Or with private setter: +public string Name { get; private set; } +// Or with backing field: +private string name; +public string Name +{ + get { return name; } + set { name = value; } +} +``` + +### String Interpolation +**Java:** +```java +System.out.println("Hello " + name + ", you are " + age + " years old"); +``` + +**C#:** +```csharp +Console.WriteLine($"Hello {name}, you are {age} years old"); +``` + +### LINQ for Data Operations +**Java:** +```java +// Finding elements manually with loops +for (int num : numbers) { + if (num > 5) { + result.add(num); + } +} +``` + +**C#:** +```csharp +// Using LINQ +var result = numbers.Where(num => num > 5).ToList(); +var sorted = numbers.OrderBy(x => x).ToArray(); +var sum = numbers.Sum(); +var average = numbers.Average(); +``` + +### Using Statements (Automatic Resource Management) +**C#:** +```csharp +using (var file = new StreamReader("file.txt")) +{ + string content = file.ReadToEnd(); + // File automatically closed when leaving this block +} +``` + +## ๐ŸŽฎ **Complete Example: Simple Guessing Game** + +**Java Version:** +```java +import java.util.Scanner; +import java.util.Random; + +public class GuessingGame { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + Random random = new Random(); + + int secretNumber = random.nextInt(100) + 1; + int attempts = 0; + boolean hasWon = false; + + System.out.println("Welcome to the Guessing Game!"); + System.out.println("I'm thinking of a number between 1 and 100."); + + while (!hasWon && attempts < 7) { + System.out.print("Enter your guess: "); + int guess = scanner.nextInt(); + attempts++; + + if (guess == secretNumber) { + hasWon = true; + System.out.println("Congratulations! You won in " + attempts + " attempts!"); + } else if (guess < secretNumber) { + System.out.println("Too low! Try again."); + } else { + System.out.println("Too high! Try again."); + } + } + + if (!hasWon) { + System.out.println("Game over! The number was " + secretNumber); + } + } +} +``` + +**C# Version:** +```csharp +using System; + +class GuessingGame +{ + static void Main(string[] args) + { + Random random = new Random(); + + int secretNumber = random.Next(1, 101); + int attempts = 0; + bool hasWon = false; + + Console.WriteLine("Welcome to the Guessing Game!"); + Console.WriteLine("I'm thinking of a number between 1 and 100."); + + while (!hasWon && attempts < 7) + { + Console.Write("Enter your guess: "); + if (int.TryParse(Console.ReadLine(), out int guess)) + { + attempts++; + + if (guess == secretNumber) + { + hasWon = true; + Console.WriteLine($"Congratulations! You won in {attempts} attempts!"); + } + else if (guess < secretNumber) + { + Console.WriteLine("Too low! Try again."); + } + else + { + Console.WriteLine("Too high! Try again."); + } + } + else + { + Console.WriteLine("Please enter a valid number."); + } + } + + if (!hasWon) + { + Console.WriteLine($"Game over! The number was {secretNumber}"); + } + + Console.WriteLine("Press any key to exit..."); + Console.ReadKey(); + } +} +``` + +## ๐Ÿ“ **Summary of Key Conversions** + +| Java | C# | Purpose | +|------|----|---------| +| `System.out.println()` | `Console.WriteLine()` | Output | +| `Scanner` | `Console.ReadLine()` | Input | +| `import` | `using` | Namespaces | +| `package` | `namespace` | Code organization | +| `extends` | `:` (inheritance) | Inheritance | +| `implements` | `:` (interface) | Interface implementation | +| `String` | `string` | String type | +| `int.parseInt()` | `int.Parse()` or `int.TryParse()` | String to int | +| `Math.random()` | `Random.Next()` | Random numbers | +| `Arrays.sort()` | `Array.Sort()` | Array sorting | + +This guide provides practical examples for converting Java concepts to C#. The syntax is very similar, making the transition relatively smooth for most programming concepts. \ No newline at end of file diff --git a/JAVA_TO_C_EXAMPLES.md b/JAVA_TO_C_EXAMPLES.md new file mode 100644 index 0000000..bb831c5 --- /dev/null +++ b/JAVA_TO_C_EXAMPLES.md @@ -0,0 +1,720 @@ +# Java to C Conversion Examples + +This document provides concrete examples of converting Java code from the assignments to C equivalents. Note that C is a procedural language, so object-oriented concepts need to be adapted using structures and function pointers. + +## ๐Ÿ”„ **Basic Syntax Conversions** + +### 1. Hello World & Basic Output + +**Java (JavaIntroduction):** +```java +public class Main { + public static void main(String[] args) { + System.out.println("Hello World!"); + System.out.println("Welcome to Java Programming"); + } +} +``` + +**C Equivalent:** +```c +#include + +int main() { + printf("Hello World!\n"); + printf("Welcome to C Programming\n"); + return 0; +} +``` + +### 2. User Input & Variables + +**Java (JavaBasics):** +```java +import java.util.Scanner; + +class Main { + public static void main(String[] args) { + Scanner myObj = new Scanner(System.in); + System.out.println("Enter your name:"); + String userName = myObj.nextLine(); + + String output = userName.substring(0, 1).toUpperCase() + userName.substring(1); + System.out.println("Hello " + output); + } +} +``` + +**C Equivalent:** +```c +#include +#include +#include + +int main() { + char userName[100]; + char output[100]; + + printf("Enter your name:\n"); + fgets(userName, sizeof(userName), stdin); + + // Remove newline character + userName[strcspn(userName, "\n")] = 0; + + // Copy string and capitalize first character + strcpy(output, userName); + output[0] = toupper(output[0]); + + printf("Hello %s\n", output); + return 0; +} +``` + +### 3. Loops & Mathematical Operations + +**Java (Factorial):** +```java +import java.util.Scanner; + +class Main { + public static void main(String[] args) { + int num; + long factorial = 1; + Scanner input = new Scanner(System.in); + + System.out.println("Enter a number:"); + num = input.nextInt(); + + for(int i = 1; i <= num; ++i) { + factorial *= i; + } + System.out.printf("Factorial of %d = %d", num, factorial); + } +} +``` + +**C Equivalent:** +```c +#include + +int main() { + int num; + long long factorial = 1; + + printf("Enter a number:\n"); + scanf("%d", &num); + + for(int i = 1; i <= num; ++i) { + factorial *= i; + } + + printf("Factorial of %d = %lld\n", num, factorial); + return 0; +} +``` + +### 4. Random Numbers + +**Java (RandomNum):** +```java +import java.util.Scanner; + +class Main { + public static void main(String args[]) { + int min, max; + Scanner input = new Scanner(System.in); + + System.out.println("Enter minimum value: "); + min = input.nextInt(); + System.out.println("Enter maximum value: "); + max = input.nextInt(); + + int random_int = (int) Math.floor(Math.random() * (max - min + 1) + min); + System.out.println("Random value: " + random_int); + } +} +``` + +**C Equivalent:** +```c +#include +#include +#include + +int main() { + int min, max; + + // Seed the random number generator + srand(time(NULL)); + + printf("Enter minimum value: \n"); + scanf("%d", &min); + printf("Enter maximum value: \n"); + scanf("%d", &max); + + int random_int = rand() % (max - min + 1) + min; + printf("Random value: %d\n", random_int); + + return 0; +} +``` + +### 5. Functions and Parameter Passing + +**Java (Conversions - Temperature):** +```java +class Main { + public static double celsiusToFahrenheit(double celsius) { + return (celsius * 9.0 / 5.0) + 32.0; + } + + public static void main(String[] args) { + double temp = 25.0; + double fahrenheit = celsiusToFahrenheit(temp); + System.out.printf("%.2fยฐC = %.2fยฐF", temp, fahrenheit); + } +} +``` + +**C Equivalent:** +```c +#include + +double celsiusToFahrenheit(double celsius) { + return (celsius * 9.0 / 5.0) + 32.0; +} + +int main() { + double temp = 25.0; + double fahrenheit = celsiusToFahrenheit(temp); + printf("%.2fยฐC = %.2fยฐF\n", temp, fahrenheit); + return 0; +} +``` + +## ๐ŸŽฏ **Simulating Object-Oriented Concepts in C** + +### 6. Basic "Class" Using Structures + +**Java (ClassesForRealWorldObject):** +```java +class Body { + private int legs; + private int arms; + + public Body() { + this.legs = 2; + this.arms = 2; + } + + public void running() { + System.out.println("I am running using my " + legs + " legs."); + } + + public void training() { + System.out.println("I train my " + arms + " arms."); + } +} +``` + +**C Equivalent (Using Structures and Functions):** +```c +#include +#include + +// Structure to represent a Body "class" +typedef struct { + int legs; + int arms; +} Body; + +// "Constructor" function +Body* createBody() { + Body* body = (Body*)malloc(sizeof(Body)); + body->legs = 2; + body->arms = 2; + return body; +} + +// "Method" functions +void running(Body* body) { + printf("I am running using my %d legs.\n", body->legs); +} + +void training(Body* body) { + printf("I train my %d arms.\n", body->arms); +} + +// "Destructor" function +void destroyBody(Body* body) { + free(body); +} + +int main() { + Body* person = createBody(); + + running(person); + training(person); + + destroyBody(person); + return 0; +} +``` + +### 7. Advanced "OOP" with Function Pointers + +**Java (Simple Game Interface):** +```java +abstract class Game { + protected String name; + + public Game(String name) { + this.name = name; + } + + public abstract void play(); + public abstract void stop(); +} + +class NumberGame extends Game { + public NumberGame() { + super("Number Game"); + } + + public void play() { + System.out.println("Playing " + name); + } + + public void stop() { + System.out.println("Stopping " + name); + } +} +``` + +**C Equivalent (Using Function Pointers):** +```c +#include +#include +#include + +// Forward declarations +typedef struct Game Game; + +// Function pointer types for "virtual methods" +typedef void (*PlayFunction)(Game* self); +typedef void (*StopFunction)(Game* self); + +// Base "class" structure +typedef struct Game { + char name[50]; + PlayFunction play; + StopFunction stop; +} Game; + +// Base constructor +void initGame(Game* game, const char* name, PlayFunction play, StopFunction stop) { + strncpy(game->name, name, sizeof(game->name) - 1); + game->name[sizeof(game->name) - 1] = '\0'; + game->play = play; + game->stop = stop; +} + +// NumberGame specific implementations +void numberGamePlay(Game* self) { + printf("Playing %s\n", self->name); +} + +void numberGameStop(Game* self) { + printf("Stopping %s\n", self->name); +} + +// NumberGame constructor +Game* createNumberGame() { + Game* game = (Game*)malloc(sizeof(Game)); + initGame(game, "Number Game", numberGamePlay, numberGameStop); + return game; +} + +int main() { + Game* game = createNumberGame(); + + // Call "methods" through function pointers + game->play(game); + game->stop(game); + + free(game); + return 0; +} +``` + +## ๐Ÿ“Š **Array and String Operations** + +### 8. Array Processing + +**Java (Finding Second Largest):** +```java +public class Main { + public static void main(String[] args) { + int[] array = {12, 35, 1, 10, 34, 1}; + int n = array.length; + int largest = Integer.MIN_VALUE; + int secondLargest = Integer.MIN_VALUE; + + for (int i = 0; i < n; i++) { + if (array[i] > largest) { + secondLargest = largest; + largest = array[i]; + } else if (array[i] < largest && array[i] > secondLargest) { + secondLargest = array[i]; + } + } + + System.out.printf("Largest: %d, Second Largest: %d", largest, secondLargest); + } +} +``` + +**C Equivalent:** +```c +#include +#include + +int main() { + int array[] = {12, 35, 1, 10, 34, 1}; + int n = sizeof(array) / sizeof(array[0]); + int largest = INT_MIN; + int secondLargest = INT_MIN; + + for (int i = 0; i < n; i++) { + if (array[i] > largest) { + secondLargest = largest; + largest = array[i]; + } else if (array[i] < largest && array[i] > secondLargest) { + secondLargest = array[i]; + } + } + + printf("Largest: %d, Second Largest: %d\n", largest, secondLargest); + return 0; +} +``` + +### 9. String Algorithms (ROT13 Cipher) + +**Java (ROT13Cipher - Simplified):** +```java +class Main { + static String encipher(String text) { + String result = ""; + + for (char c : text.toCharArray()) { + if (c >= 'a' && c <= 'z') { + result += (char)((c - 'a' + 13) % 26 + 'a'); + } else if (c >= 'A' && c <= 'Z') { + result += (char)((c - 'A' + 13) % 26 + 'A'); + } else { + result += c; + } + } + return result; + } + + public static void main(String[] args) { + String text = "Hello World"; + String encrypted = encipher(text); + System.out.println("Encrypted: " + encrypted); + } +} +``` + +**C Equivalent:** +```c +#include +#include + +void encipher(char* text, char* result) { + int len = strlen(text); + int j = 0; + + for (int i = 0; i < len; i++) { + char c = text[i]; + if (c >= 'a' && c <= 'z') { + result[j++] = ((c - 'a' + 13) % 26) + 'a'; + } else if (c >= 'A' && c <= 'Z') { + result[j++] = ((c - 'A' + 13) % 26) + 'A'; + } else { + result[j++] = c; + } + } + result[j] = '\0'; // Null terminate +} + +int main() { + char text[] = "Hello World"; + char encrypted[256]; + + encipher(text, encrypted); + printf("Encrypted: %s\n", encrypted); + return 0; +} +``` + +### 10. Dynamic Arrays and Memory Management + +**Java (Dynamic Array Operations):** +```java +import java.util.ArrayList; + +public class Main { + public static void main(String[] args) { + ArrayList numbers = new ArrayList<>(); + + // Add elements + numbers.add(10); + numbers.add(20); + numbers.add(30); + + // Print elements + for (int num : numbers) { + System.out.println(num); + } + + System.out.println("Size: " + numbers.size()); + } +} +``` + +**C Equivalent (Dynamic Array):** +```c +#include +#include + +typedef struct { + int* data; + int size; + int capacity; +} DynamicArray; + +DynamicArray* createArray() { + DynamicArray* arr = (DynamicArray*)malloc(sizeof(DynamicArray)); + arr->capacity = 2; + arr->size = 0; + arr->data = (int*)malloc(arr->capacity * sizeof(int)); + return arr; +} + +void addElement(DynamicArray* arr, int value) { + if (arr->size >= arr->capacity) { + arr->capacity *= 2; + arr->data = (int*)realloc(arr->data, arr->capacity * sizeof(int)); + } + arr->data[arr->size++] = value; +} + +void printArray(DynamicArray* arr) { + for (int i = 0; i < arr->size; i++) { + printf("%d\n", arr->data[i]); + } +} + +void destroyArray(DynamicArray* arr) { + free(arr->data); + free(arr); +} + +int main() { + DynamicArray* numbers = createArray(); + + // Add elements + addElement(numbers, 10); + addElement(numbers, 20); + addElement(numbers, 30); + + // Print elements + printArray(numbers); + printf("Size: %d\n", numbers->size); + + destroyArray(numbers); + return 0; +} +``` + +## ๐ŸŽฎ **Complete Example: Simple Guessing Game** + +**Java Version:** +```java +import java.util.Scanner; +import java.util.Random; + +public class GuessingGame { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + Random random = new Random(); + + int secretNumber = random.nextInt(100) + 1; + int attempts = 0; + boolean hasWon = false; + + System.out.println("Welcome to the Guessing Game!"); + + while (!hasWon && attempts < 7) { + System.out.print("Enter your guess: "); + int guess = scanner.nextInt(); + attempts++; + + if (guess == secretNumber) { + hasWon = true; + System.out.println("You won in " + attempts + " attempts!"); + } else if (guess < secretNumber) { + System.out.println("Too low!"); + } else { + System.out.println("Too high!"); + } + } + + if (!hasWon) { + System.out.println("Game over! Number was " + secretNumber); + } + } +} +``` + +**C Version:** +```c +#include +#include +#include +#include + +int main() { + srand(time(NULL)); + + int secretNumber = rand() % 100 + 1; + int attempts = 0; + bool hasWon = false; + int guess; + + printf("Welcome to the Guessing Game!\n"); + printf("I'm thinking of a number between 1 and 100.\n"); + + while (!hasWon && attempts < 7) { + printf("Enter your guess: "); + + // Input validation + if (scanf("%d", &guess) != 1) { + printf("Please enter a valid number.\n"); + // Clear input buffer + while (getchar() != '\n'); + continue; + } + + attempts++; + + if (guess == secretNumber) { + hasWon = true; + printf("Congratulations! You won in %d attempts!\n", attempts); + } else if (guess < secretNumber) { + printf("Too low! Try again.\n"); + } else { + printf("Too high! Try again.\n"); + } + } + + if (!hasWon) { + printf("Game over! The number was %d\n", secretNumber); + } + + return 0; +} +``` + +## ๐Ÿ› ๏ธ **Key C Concepts and Differences** + +### Memory Management +**C requires manual memory management:** +```c +// Allocate memory +int* numbers = (int*)malloc(10 * sizeof(int)); + +// Use the memory +numbers[0] = 42; + +// Free the memory when done +free(numbers); +``` + +### String Handling +**C strings are character arrays:** +```c +char str1[50] = "Hello"; +char str2[50]; + +strcpy(str2, str1); // Copy string +strcat(str1, " World"); // Concatenate +int len = strlen(str1); // Get length +int cmp = strcmp(str1, str2); // Compare strings +``` + +### Input/Output +**C uses different functions for I/O:** +```c +printf("Hello %s, age %d\n", name, age); // Formatted output +scanf("%d", &number); // Formatted input +fgets(buffer, size, stdin); // Safe string input +``` + +### Error Handling +**C uses return values and errno:** +```c +FILE* file = fopen("data.txt", "r"); +if (file == NULL) { + perror("Error opening file"); + return 1; +} + +int result = someFunction(); +if (result != 0) { + printf("Function failed with code %d\n", result); +} +``` + +## ๐Ÿ“ **Summary of Key Conversions** + +| Java | C | Purpose | +|------|---|---------| +| `System.out.println()` | `printf()` | Output | +| `Scanner` | `scanf()`, `fgets()` | Input | +| `String` | `char[]`, `char*` | Strings | +| `new` | `malloc()` | Memory allocation | +| Automatic GC | `free()` | Memory deallocation | +| `try-catch` | Return codes, `errno` | Error handling | +| Classes | `struct` + functions | Data structures | +| Methods | Functions | Code organization | +| Packages | Header files | Code organization | +| `ArrayList` | Dynamic arrays (manual) | Collections | + +### Compilation and Execution +**Java:** +```bash +javac Main.java +java Main +``` + +**C:** +```bash +gcc -o program main.c +./program +``` + +### Common C Libraries Needed +```c +#include // Input/output functions +#include // Memory allocation, utilities +#include // String manipulation +#include // Mathematical functions +#include // Time and random functions +#include // Boolean type (C99+) +#include // Numeric limits +``` + +This guide demonstrates how Java concepts can be translated to C. While C is more verbose and requires manual memory management, it provides fine-grained control and teaches fundamental programming concepts that are abstracted away in higher-level languages like Java. \ No newline at end of file diff --git a/LEARNING_PROGRESSION_GUIDE.md b/LEARNING_PROGRESSION_GUIDE.md new file mode 100644 index 0000000..0253e42 --- /dev/null +++ b/LEARNING_PROGRESSION_GUIDE.md @@ -0,0 +1,252 @@ +# Java to C#/C Learning Progression Guide + +This guide organizes the Java assignments in this repository from beginner to advanced levels, providing a structured learning path for converting these concepts to C# or C programming. + +## Overview + +This repository contains high school Computer Science assignments covering fundamental to advanced programming concepts. The assignments are organized here by difficulty level to create an optimal learning progression. + +--- + +## ๐ŸŸข **BEGINNER LEVEL** (Start Here) +*Focus: Basic syntax, variables, input/output, simple calculations* + +### 1. **JavaIntroduction** - Hello World & Basic Output +- **Concepts**: Basic printing, string literals, method calls +- **Java Topics**: `System.out.println()`, static methods, basic formatting +- **C# Equivalent**: `Console.WriteLine()`, static methods +- **C Equivalent**: `printf()`, function declarations + +### 2. **JavaBasics** - Input/Output & String Manipulation +- **Concepts**: User input, variables, string operations, basic math +- **Java Topics**: Scanner class, string methods, variable declarations +- **C# Equivalent**: `Console.ReadLine()`, string methods, var declarations +- **C Equivalent**: `scanf()`, string functions, variable declarations + +### 3. **SumOfFiveIntegers** - Variables & Loops +- **Concepts**: Variables, while loops, basic arithmetic +- **Java Topics**: `int` variables, `while` loop, Scanner input +- **C# Equivalent**: `int` variables, `while` loop, `Console.ReadLine()` +- **C Equivalent**: `int` variables, `while` loop, `scanf()` + +### 4. **RandomNum** - Math Functions & Loops +- **Concepts**: Random numbers, Math class, for loops +- **Java Topics**: `Math.random()`, `Math.floor()`, type casting +- **C# Equivalent**: `Random` class, `Math.Floor()`, casting +- **C Equivalent**: `rand()`, `srand()`, `floor()` function + +### 5. **MonthName** - Conditional Statements +- **Concepts**: If-else statements, switch cases, string comparison +- **Java Topics**: `if-else`, `switch`, string equality +- **C# Equivalent**: `if-else`, `switch`, string comparison +- **C Equivalent**: `if-else`, `switch`, `strcmp()` + +### 6. **Factorial** - Functions & Loops +- **Concepts**: Mathematical calculations, for loops, functions +- **Java Topics**: `for` loops, long data type, mathematical operations +- **C# Equivalent**: `for` loops, `long` type, math operations +- **C Equivalent**: `for` loops, `long long` type, math operations + +--- + +## ๐ŸŸก **INTERMEDIATE LEVEL** +*Focus: Methods, arrays, basic algorithms, object-oriented basics* + +### 7. **PerfectSquare** - Mathematical Logic +- **Concepts**: Mathematical problem solving, square root calculations +- **Java Topics**: Math library, conditional logic, method creation +- **C# Equivalent**: `Math` class, conditional statements, methods +- **C Equivalent**: `math.h`, conditional statements, functions + +### 8. **GuessingGame** - Game Logic & Control Flow +- **Concepts**: Game loops, random generation, user interaction +- **Java Topics**: do-while loops, random numbers, input validation +- **C# Equivalent**: do-while loops, Random class, input validation +- **C Equivalent**: do-while loops, rand(), input validation + +### 9. **PairOfDice** - Multiple Object Simulation +- **Concepts**: Simulation, probability, multiple random values +- **Java Topics**: Multiple random generations, loops, formatting +- **C# Equivalent**: Multiple Random calls, loops, string formatting +- **C Equivalent**: Multiple rand() calls, loops, printf formatting + +### 10. **Conversions** - Unit Conversion & Functions +- **Concepts**: Mathematical conversions, function organization +- **Java Topics**: Method creation, parameter passing, return values +- **C# Equivalent**: Method creation, parameters, return types +- **C Equivalent**: Function creation, parameters, return values + +### 11. **CurrencyConverter** - Complex Calculations +- **Concepts**: Real-world applications, decimal calculations +- **Java Topics**: Double precision, mathematical operations, formatting +- **C# Equivalent**: `double` type, math operations, string formatting +- **C Equivalent**: `double` type, math operations, printf formatting + +### 12. **DistanceFormula** - Mathematical Formulas +- **Concepts**: Complex mathematical calculations, coordinate geometry +- **Java Topics**: Math.sqrt(), Math.pow(), coordinate calculations +- **C# Equivalent**: Math.Sqrt(), Math.Pow(), calculations +- **C Equivalent**: sqrt(), pow(), mathematical calculations + +### 13. **ClassesForRealWorldObject** - Introduction to OOP +- **Concepts**: Basic classes, objects, methods, encapsulation +- **Java Topics**: Class creation, constructors, instance methods +- **C# Equivalent**: Class creation, constructors, instance methods +- **C Equivalent**: Structures, function pointers (advanced concept) + +--- + +## ๐ŸŸ  **INTERMEDIATE-ADVANCED LEVEL** +*Focus: Arrays, algorithms, data structures, advanced OOP* + +### 14. **FindSecondLargestElementInArray** - Array Algorithms +- **Concepts**: Array traversal, comparison algorithms, finding extremes +- **Java Topics**: Array iteration, comparison logic, algorithm implementation +- **C# Equivalent**: Array iteration, LINQ methods, algorithm logic +- **C Equivalent**: Array iteration, comparison logic, pointer arithmetic + +### 15. **FindSmallestAndSecondSmallestIntegerInArray** - Advanced Array Processing +- **Concepts**: Multiple pass algorithms, array analysis +- **Java Topics**: Array processing, multiple variable tracking +- **C# Equivalent**: Array processing, variable management +- **C Equivalent**: Array processing, multiple variable tracking + +### 16. **SortingArrayUsingDifferentWays** - Sorting Algorithms +- **Concepts**: Different sorting techniques, algorithm comparison +- **Java Topics**: Arrays.sort(), custom sorting logic +- **C# Equivalent**: Array.Sort(), custom sorting, LINQ OrderBy +- **C Equivalent**: qsort(), custom sorting functions + +### 17. **NumericAndStringArray** - Mixed Data Type Handling +- **Concepts**: Different data types, array sorting, type handling +- **Java Topics**: String arrays, numeric arrays, Arrays.sort() +- **C# Equivalent**: String arrays, numeric arrays, Array.Sort() +- **C Equivalent**: Character arrays, numeric arrays, sorting functions + +### 18. **ArrayAndStringTask1** - Complex Array Operations +- **Concepts**: Multiple array algorithms, comprehensive data processing +- **Java Topics**: Complex array manipulation, multiple algorithm implementation +- **C# Equivalent**: Complex array operations, LINQ usage +- **C Equivalent**: Complex array operations, multiple algorithm implementation + +--- + +## ๐Ÿ”ด **ADVANCED LEVEL** +*Focus: Advanced OOP, algorithms, data structures, GUI* + +### 19. **GuessingGameInOOP** - Advanced Object-Oriented Programming +- **Concepts**: Inheritance, abstract classes, polymorphism, design patterns +- **Java Topics**: Abstract classes, inheritance, method overriding, collections +- **C# Equivalent**: Abstract classes, inheritance, method overriding, collections +- **C Equivalent**: Function pointers, structures (simulate OOP concepts) + +### 20. **ROT13Cipher** - String Algorithms & Encryption +- **Concepts**: String manipulation, encryption algorithms, character processing +- **Java Topics**: String processing, character manipulation, algorithm implementation +- **C# Equivalent**: String processing, char manipulation, algorithm logic +- **C Equivalent**: Character arrays, ASCII manipulation, algorithm implementation + +### 21. **LinearAndQuadraticEquationCalculator** - Complex Mathematical Processing +- **Concepts**: String parsing, mathematical formula implementation, error handling +- **Java Topics**: String parsing, mathematical calculations, exception handling +- **C# Equivalent**: String parsing, Math class, exception handling +- **C Equivalent**: String parsing, mathematical functions, error handling + +### 22. **CalculateSumOfGeometricSequence** - Advanced Mathematical Algorithms +- **Concepts**: Mathematical sequences, iterative calculations, formula implementation +- **Java Topics**: Mathematical series, iterative processing, precision handling +- **C# Equivalent**: Mathematical calculations, iteration, decimal precision +- **C Equivalent**: Mathematical calculations, iteration, floating-point precision + +### 23. **FinalProjet** - GUI Application Development +- **Concepts**: Graphical user interfaces, event handling, advanced OOP integration +- **Java Topics**: Swing components, event listeners, custom painting, file I/O +- **C# Equivalent**: WinForms/WPF, event handling, custom drawing, file operations +- **C Equivalent**: GUI libraries (GTK, Qt), event handling, graphics programming + +--- + +## ๐ŸŽฏ **Recommended Learning Order** + +### Phase 1: Foundation (Weeks 1-3) +1. JavaIntroduction +2. JavaBasics +3. SumOfFiveIntegers +4. RandomNum +5. MonthName +6. Factorial + +### Phase 2: Core Programming (Weeks 4-6) +7. PerfectSquare +8. GuessingGame +9. PairOfDice +10. Conversions +11. CurrencyConverter +12. DistanceFormula + +### Phase 3: Object-Oriented Basics (Weeks 7-8) +13. ClassesForRealWorldObject + +### Phase 4: Data Structures & Algorithms (Weeks 9-12) +14. FindSecondLargestElementInArray +15. FindSmallestAndSecondSmallestIntegerInArray +16. SortingArrayUsingDifferentWays +17. NumericAndStringArray +18. ArrayAndStringTask1 + +### Phase 5: Advanced Concepts (Weeks 13-16) +19. GuessingGameInOOP +20. ROT13Cipher +21. LinearAndQuadraticEquationCalculator +22. CalculateSumOfGeometricSequence +23. FinalProjet + +--- + +## ๐Ÿ’ก **Key Learning Tips** + +### For C# Conversion: +- **Syntax Similarities**: C# and Java have very similar syntax +- **Main Differences**: + - `Console.WriteLine()` vs `System.out.println()` + - `using` statements vs `import` + - Properties vs getter/setter methods + - LINQ for advanced data operations + +### For C Conversion: +- **Key Differences**: + - Manual memory management + - Pointers instead of references + - Function-based instead of object-oriented + - Manual string handling + - Different input/output functions + +### General Progression Strategy: +1. **Start Simple**: Master basic syntax and concepts first +2. **Build Gradually**: Each level builds on previous knowledge +3. **Practice Conversion**: Try converting each Java program to your target language +4. **Understand Concepts**: Focus on understanding the logic, not just translating syntax +5. **Add Features**: Once you convert a program, try adding new features + +--- + +## ๐Ÿ“š **Additional Resources** + +### For C# Learning: +- Microsoft's C# documentation +- .NET Framework/Core documentation +- Visual Studio IDE features + +### For C Learning: +- GCC compiler usage +- Memory management concepts +- Standard library functions +- Debugging tools (GDB) + +### Development Tools: +- **C#**: Visual Studio, Visual Studio Code, JetBrains Rider +- **C**: GCC, Visual Studio Code, Code::Blocks, CLion + +--- + +*This progression guide helps you systematically learn programming concepts while transitioning from Java to C# or C. Each assignment builds foundational knowledge for the next level.* \ No newline at end of file diff --git a/QUICK_REFERENCE_GUIDE.md b/QUICK_REFERENCE_GUIDE.md new file mode 100644 index 0000000..097c7fe --- /dev/null +++ b/QUICK_REFERENCE_GUIDE.md @@ -0,0 +1,275 @@ +# Quick Reference: Java โ†’ C# โ†’ C Syntax Comparison + +This quick reference guide helps you quickly translate between Java, C#, and C syntax for common programming tasks. + +## ๐Ÿ“‹ **Basic Program Structure** + +| Concept | Java | C# | C | +|---------|------|----|----| +| **Program Entry** | `public static void main(String[] args)` | `static void Main(string[] args)` | `int main()` | +| **Imports/Includes** | `import java.util.*;` | `using System;` | `#include ` | +| **Package/Namespace** | `package mypackage;` | `namespace MyNamespace` | N/A (header files) | + +## ๐Ÿ”ค **Data Types** + +| Type | Java | C# | C | +|------|------|----|----| +| **Integer** | `int x = 5;` | `int x = 5;` | `int x = 5;` | +| **Long** | `long x = 5L;` | `long x = 5L;` | `long long x = 5LL;` | +| **Float** | `float x = 5.0f;` | `float x = 5.0f;` | `float x = 5.0f;` | +| **Double** | `double x = 5.0;` | `double x = 5.0;` | `double x = 5.0;` | +| **String** | `String s = "hello";` | `string s = "hello";` | `char s[] = "hello";` | +| **Boolean** | `boolean b = true;` | `bool b = true;` | `bool b = true;` (C99+) | +| **Character** | `char c = 'a';` | `char c = 'a';` | `char c = 'a';` | + +## ๐Ÿ“ฅ๐Ÿ“ค **Input/Output** + +| Operation | Java | C# | C | +|-----------|------|----|----| +| **Print** | `System.out.println("Hello");` | `Console.WriteLine("Hello");` | `printf("Hello\n");` | +| **Print with format** | `System.out.printf("%d", x);` | `Console.WriteLine($"Value: {x}");` | `printf("%d", x);` | +| **Read string** | `Scanner.nextLine()` | `Console.ReadLine()` | `fgets(str, size, stdin)` | +| **Read integer** | `Scanner.nextInt()` | `int.Parse(Console.ReadLine())` | `scanf("%d", &x)` | + +## ๐Ÿ”„ **Control Structures** + +### If Statements +| Language | Syntax | +|----------|--------| +| **Java** | `if (condition) { } else if (condition) { } else { }` | +| **C#** | `if (condition) { } else if (condition) { } else { }` | +| **C** | `if (condition) { } else if (condition) { } else { }` | + +### Loops +| Type | Java | C# | C | +|------|------|----|----| +| **For loop** | `for (int i = 0; i < n; i++)` | `for (int i = 0; i < n; i++)` | `for (int i = 0; i < n; i++)` | +| **While loop** | `while (condition)` | `while (condition)` | `while (condition)` | +| **For-each** | `for (int x : array)` | `foreach (int x in array)` | N/A (manual loop) | + +## ๐Ÿ“š **Arrays** + +| Operation | Java | C# | C | +|-----------|------|----|----| +| **Declaration** | `int[] arr = new int[5];` | `int[] arr = new int[5];` | `int arr[5];` | +| **Initialize** | `int[] arr = {1,2,3};` | `int[] arr = {1,2,3};` | `int arr[] = {1,2,3};` | +| **Length** | `arr.length` | `arr.Length` | N/A (track manually) | +| **Access** | `arr[0]` | `arr[0]` | `arr[0]` | +| **Sort** | `Arrays.sort(arr)` | `Array.Sort(arr)` | `qsort()` (with compare function) | + +## ๐Ÿ”ง **Functions/Methods** + +| Concept | Java | C# | C | +|---------|------|----|----| +| **Basic function** | `public static int add(int a, int b)` | `public static int Add(int a, int b)` | `int add(int a, int b)` | +| **Call function** | `int result = add(5, 3);` | `int result = Add(5, 3);` | `int result = add(5, 3);` | +| **Return** | `return value;` | `return value;` | `return value;` | + +## ๐ŸŽฏ **Object-Oriented Programming** + +### Class Definition +**Java:** +```java +public class Person { + private String name; + + public Person(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} +``` + +**C#:** +```csharp +public class Person +{ + private string name; + + public Person(string name) + { + this.name = name; + } + + public string Name { get { return name; } } + // Or: public string Name { get; set; } +} +``` + +**C (Struct simulation):** +```c +typedef struct { + char name[50]; +} Person; + +Person createPerson(const char* name) { + Person p; + strcpy(p.name, name); + return p; +} + +char* getName(Person* p) { + return p->name; +} +``` + +## ๐Ÿ”— **String Operations** + +| Operation | Java | C# | C | +|-----------|------|----|----| +| **Concatenation** | `str1 + str2` | `str1 + str2` | `strcat(dest, src)` | +| **Length** | `str.length()` | `str.Length` | `strlen(str)` | +| **Compare** | `str1.equals(str2)` | `str1 == str2` | `strcmp(str1, str2) == 0` | +| **Substring** | `str.substring(start, end)` | `str.Substring(start, length)` | Manual (copy characters) | +| **To uppercase** | `str.toUpperCase()` | `str.ToUpper()` | `toupper()` (character by character) | + +## ๐ŸŽฒ **Random Numbers** + +| Language | Code | +|----------|------| +| **Java** | `Random rand = new Random(); int x = rand.nextInt(10);` | +| **C#** | `Random rand = new Random(); int x = rand.Next(10);` | +| **C** | `srand(time(NULL)); int x = rand() % 10;` | + +## ๐Ÿ’พ **Memory Management** + +| Operation | Java | C# | C | +|-----------|------|----|----| +| **Allocate** | `new Type()` (automatic GC) | `new Type()` (automatic GC) | `malloc(sizeof(Type))` | +| **Free** | Automatic | Automatic | `free(pointer)` | +| **Array allocation** | `new int[size]` | `new int[size]` | `malloc(size * sizeof(int))` | + +## โŒ **Error Handling** + +| Method | Java | C# | C | +|--------|------|----|----| +| **Exceptions** | `try { } catch (Exception e) { }` | `try { } catch (Exception e) { }` | N/A | +| **Return codes** | Not common | Not common | `if (function() != 0) { }` | +| **Check null** | `if (obj != null)` | `if (obj != null)` | `if (ptr != NULL)` | + +## ๐Ÿ“ **File Operations** + +| Operation | Java | C# | C | +|-----------|------|----|----| +| **Open file** | `Scanner file = new Scanner(new File("file.txt"))` | `StreamReader file = new StreamReader("file.txt")` | `FILE* file = fopen("file.txt", "r")` | +| **Read line** | `String line = file.nextLine()` | `string line = file.ReadLine()` | `fgets(buffer, size, file)` | +| **Close file** | `file.close()` | `file.Close()` | `fclose(file)` | + +## ๐Ÿ”ข **Common Math Operations** + +| Operation | Java | C# | C | +|-----------|------|----|----| +| **Square root** | `Math.sqrt(x)` | `Math.Sqrt(x)` | `sqrt(x)` | +| **Power** | `Math.pow(x, y)` | `Math.Pow(x, y)` | `pow(x, y)` | +| **Absolute** | `Math.abs(x)` | `Math.Abs(x)` | `abs(x)` or `fabs(x)` | +| **Min/Max** | `Math.min(a, b)` | `Math.Min(a, b)` | Manual: `(a < b) ? a : b` | + +## ๐Ÿ”„ **Type Conversion** + +| Conversion | Java | C# | C | +|------------|------|----|----| +| **String to int** | `Integer.parseInt(str)` | `int.Parse(str)` | `atoi(str)` | +| **Int to string** | `Integer.toString(x)` | `x.ToString()` | `sprintf(str, "%d", x)` | +| **Cast** | `(int) x` | `(int) x` | `(int) x` | + +## ๐Ÿ“Š **Common Algorithms** + +### Finding Maximum in Array +**Java:** +```java +int max = Integer.MIN_VALUE; +for (int x : array) { + if (x > max) max = x; +} +``` + +**C#:** +```csharp +int max = int.MinValue; +foreach (int x in array) { + if (x > max) max = x; +} +// Or: int max = array.Max(); +``` + +**C:** +```c +int max = INT_MIN; +for (int i = 0; i < size; i++) { + if (array[i] > max) max = array[i]; +} +``` + +### Sorting Array +**Java:** +```java +Arrays.sort(array); +``` + +**C#:** +```csharp +Array.Sort(array); +// Or: array = array.OrderBy(x => x).ToArray(); +``` + +**C:** +```c +qsort(array, size, sizeof(int), compare_function); +``` + +## ๐Ÿš€ **Quick Start Templates** + +### Java Template +```java +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + // Your code here + scanner.close(); + } +} +``` + +### C# Template +```csharp +using System; + +class Program +{ + static void Main(string[] args) + { + // Your code here + Console.ReadKey(); // Pause before exit + } +} +``` + +### C Template +```c +#include +#include +#include + +int main() +{ + // Your code here + return 0; +} +``` + +## ๐ŸŽฏ **Compilation & Execution** + +| Language | Compile | Run | +|----------|---------|-----| +| **Java** | `javac Program.java` | `java Program` | +| **C#** | `csc Program.cs` or `dotnet build` | `Program.exe` or `dotnet run` | +| **C** | `gcc -o program program.c` | `./program` | + +--- + +*This quick reference covers the most commonly used syntax differences between Java, C#, and C. Use this as a handy guide while converting programs between languages.* \ No newline at end of file diff --git a/README.md b/README.md index f21f63a..fdb934b 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,14 @@ From basic console apps to interactive games, this repo documents my early journey into programming with Java, Python, and web technologies. Each project reflects skills I was learning at the time โ€” including logic building, loops, functions, file I/O, and UI basics. -This archive isn't just about the code โ€” itโ€™s about growth, curiosity, and the start of my path into computer science. \ No newline at end of file +This archive isn't just about the code โ€” itโ€™s about growth, curiosity, and the start of my path into computer science. +## ๐Ÿ“š Learning Resources + +Want to learn these concepts in C# or C? Check out these comprehensive guides: + +- **[๐Ÿ“‹ Learning Progression Guide](LEARNING_PROGRESSION_GUIDE.md)** - Organized curriculum from beginner to advanced +- **[๐Ÿ”ท Java to C# Examples](JAVA_TO_CSHARP_EXAMPLES.md)** - Complete code conversions and explanations +- **[โšก Java to C Examples](JAVA_TO_C_EXAMPLES.md)** - Low-level programming concepts and translations +- **[๐Ÿ“– Quick Reference Guide](QUICK_REFERENCE_GUIDE.md)** - Side-by-side syntax comparison + +These guides provide a structured learning path to understand the Java assignments and convert them to other languages, progressing from basic concepts to advanced topics.