From 220ac8439ecb5ddf004ce0b549b42b10812161d5 Mon Sep 17 00:00:00 2001 From: Harshit Date: Thu, 27 Jul 2023 15:07:57 +0530 Subject: [PATCH] new folders --- Assignment/Q1.java | 59 ++++++++++++++++ Assignment/test.java | 10 +++ BASICS/Multithreading.java | 7 +- First_project/Multiscreen_app.java | 57 +++++++++++++++ First_project/Notes.java | 25 +++++++ First_project/tic_tac_toe.java | 108 +++++++++++++++++++++++++++++ 6 files changed, 263 insertions(+), 3 deletions(-) create mode 100644 Assignment/Q1.java create mode 100644 Assignment/test.java create mode 100644 First_project/Multiscreen_app.java create mode 100644 First_project/Notes.java create mode 100644 First_project/tic_tac_toe.java diff --git a/Assignment/Q1.java b/Assignment/Q1.java new file mode 100644 index 0000000..72a48cb --- /dev/null +++ b/Assignment/Q1.java @@ -0,0 +1,59 @@ +package Assignment; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class Q1 { + public static void main(String[] args) throws IOException { +// String door_fitting[] = {"Room Number 1", "Secret room"}; +// String codes[] = {"910", "811"}; + String door_fitting[] = {"Room 666", "Don't enter"}; + String codes[] = {"313", "800"}; +// String door_fitting[] = {"Portal 1", "Portal 2", "Portal 3"}; +// String codes[] = {"501"}; +// String door_fitting[] = {"Door to nowhere", "Door to nowhere 2"}; +// String codes[] = {"1203", "1203"}; + + int n = door_fitting.length; + Map mp = new HashMap<>(); + + for (int i = 0; i < n; i++) { + mp.put(codes[i], mp.getOrDefault(codes[i], 0) + 1); + } + + StringBuilder ans = new StringBuilder(); + + for (int i = 0; i < n; i++) { + int m = door_fitting[i].length(); + int l = 0; + int d = 0; + boolean r = false; + + for (int j = 0; j < m; j++) { + if (Character.isLowerCase(door_fitting[i].charAt(j))) { + l++; + } + if (Character.isDigit(door_fitting[i].charAt(j))) { + d++; + } + } + + for (int j = 0; j < n - 4; j++) { + String data = door_fitting[i].substring(j, j + 4).toLowerCase(); + if (data.equals("room")) { + r = true; + break; + } + } + + String x = l + (r ? "1" : "0") + d; + if (mp.getOrDefault(x, 0) == 0) { + continue; + } + + ans.append(door_fitting[i]).append("-").append(l).append((r ? "1" : "0")).append(d).append(";"); + } + + System.out.println(ans); + } +} diff --git a/Assignment/test.java b/Assignment/test.java new file mode 100644 index 0000000..5424205 --- /dev/null +++ b/Assignment/test.java @@ -0,0 +1,10 @@ +package Assignment; + +public class test { + static int val = 10; + public static void main(String[] args) { + double num = 2.413; + int whole = (int) num; + int fraction = whole- (int)num; + } +} diff --git a/BASICS/Multithreading.java b/BASICS/Multithreading.java index c2f80e1..37fc478 100644 --- a/BASICS/Multithreading.java +++ b/BASICS/Multithreading.java @@ -18,16 +18,17 @@ public void run(){ class MyThreadRun1 implements Runnable{ public void run(){ - int n = 100; + int n = 10; while(n-- != 0) System.out.println("Im Harshit Bansal"); } } class MyThreadRun2 implements Runnable{ + final int n = 100; public void run(){ - int n = 100; + int n = 10; while(n-- != 0) - System.out.println("Im Vanshika M"); + System.out.println(this.n); } } diff --git a/First_project/Multiscreen_app.java b/First_project/Multiscreen_app.java new file mode 100644 index 0000000..7a0fc69 --- /dev/null +++ b/First_project/Multiscreen_app.java @@ -0,0 +1,57 @@ +/* +package com.example.multiple_screen_app; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.EditText; + +public class MainActivity extends AppCompatActivity { + public static final String MSG = "com.example.multiple_screen_app.ORDER"; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } + + public void PlaceHolder(View view){ + Intent intent = new Intent(this, OrderActivity.class); + EditText editText1 = findViewById(R.id.editText1); + EditText editText2 = findViewById(R.id.editText2); + EditText editText3 = findViewById(R.id.editText3); + String message = "Order for " + editText1.getText().toString() + ", " + editText2.getText().toString() + + " & " + editText3.getText().toString() + " is placed."; + + intent.putExtra(MSG, message); + startActivity(intent); + } +} + */ +/* +package com.example.multiple_screen_app; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.widget.TextView; + +public class OrderActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_order); + + Intent intent = getIntent(); + String message = intent.getStringExtra(MainActivity.MSG); + + TextView textview = findViewById(R.id.OrderId); + textview.setText(message); + } +} + */ +//Note : to add a going back option from new page, go to Android Manifest and write +// android:parentActivityName=".MainActivity" next to android:name=".OrderActivity" \ No newline at end of file diff --git a/First_project/Notes.java b/First_project/Notes.java new file mode 100644 index 0000000..6aa534c --- /dev/null +++ b/First_project/Notes.java @@ -0,0 +1,25 @@ +package First_project; +/* +APK : it is collection of different files(like code, audio, video) complied and bundled into single file +AVD : Android virtual device, it is an emulator configuration that simulated a physical Android Device +view group : Holds View and View groups + +findViewById(R.id.) +Toast.makeText(this, "Message", Toast.LENGTH_SHORT).show() +button.setOnClickListener(new View.OnClickListener(){ + @Override + public void onClick(View view) { + } +}); + +Use gravity in linear layout +right click in TextView, and get borderline constrain, to align all text views in a same line + +use Layout weight to assign how much weight an attribute wil take in the layout +E.x. 3 attributes with weight 1, 2, 1 then the top and bottom will take 25% space each and mid will take 50% + */ +public class Notes { + public static void main(String[] args) { + + } +} diff --git a/First_project/tic_tac_toe.java b/First_project/tic_tac_toe.java new file mode 100644 index 0000000..317faad --- /dev/null +++ b/First_project/tic_tac_toe.java @@ -0,0 +1,108 @@ +/* +package com.example.tic_tac_toe; + +import androidx.appcompat.app.AppCompatActivity; + +import android.media.Image; +import android.os.Bundle; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import org.w3c.dom.Text; + +import java.util.Arrays; + +public class MainActivity extends AppCompatActivity { + // 1 - X + // 0 - 0 + // 2 - Blank + boolean gameActive = true; + int activePlayer = 1; + int[] gameState = {2, 2, 2, 2, 2, 2, 2, 2, 2}; + int[][] win_pos = {{0,1,2}, {3,4,5}, {6,7,8}, + {0,3,6}, {1,4,7}, {2,5,8}, + {0,4,8}, {2,4,6}}; + + public void taptap(View view){ + if(!gameActive){ + gameReset(view); + return; + } + + TextView status = findViewById(R.id.status); + + ImageView img = (ImageView) view; + int tapperImg = Integer.parseInt(img.getTag().toString()) ; + + if(gameState[tapperImg] == 2 && gameActive){ + gameState[tapperImg] = activePlayer; + img.setTranslationY(-1000f); + + if(activePlayer == 1){ + img.setImageResource(R.drawable.x); + activePlayer = 0; + status.setText(R.string.o_turn); + } + else{ + img.setImageResource(R.drawable.o); + activePlayer = 1; + status.setText(R.string.X_turn); + } + img.animate().translationYBy(1000f).setDuration(200); + + //Check if any player has won + for(int[] win : win_pos){ + if(gameState[win[0]] == gameState[win[1]] && gameState[win[1]] == gameState[win[2]] + && gameState[win[0]] != 2){ + //Somebody has won + String winnerStr; + if(gameState[win[0]] == 1){ + winnerStr = "X has WON!"; + } + else{ + winnerStr = "O has WON!"; + } + //Updating the status bar for winner announcement + status.setText(winnerStr); + gameActive = false; + return; + } + } + + //Draw condition + gameActive = false; + for(int ch : gameState){ + if(ch == 2) { + gameActive= true; + break; + } + } + if(!gameActive) + status.setText("Game Drawn!"); + } + } + + public void gameReset(View view){ + gameActive = true; + activePlayer = 1; + Arrays.fill(gameState, 2); + TextView status = findViewById(R.id.status); + status.setText(R.string.X_turn); + ((ImageView)findViewById(R.id.imageView1)).setImageResource(0); + ((ImageView)findViewById(R.id.imageView2)).setImageResource(0); + ((ImageView)findViewById(R.id.imageView3)).setImageResource(0); + ((ImageView)findViewById(R.id.imageView4)).setImageResource(0); + ((ImageView)findViewById(R.id.imageView5)).setImageResource(0); + ((ImageView)findViewById(R.id.imageView6)).setImageResource(0); + ((ImageView)findViewById(R.id.imageView7)).setImageResource(0); + ((ImageView)findViewById(R.id.imageView8)).setImageResource(0); + ((ImageView)findViewById(R.id.imageView9)).setImageResource(0); + } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } +} + */ \ No newline at end of file