Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Assignment/Q1.java
Original file line number Diff line number Diff line change
@@ -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<String, Integer> 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);
}
}
10 changes: 10 additions & 0 deletions Assignment/test.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
7 changes: 4 additions & 3 deletions BASICS/Multithreading.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
57 changes: 57 additions & 0 deletions First_project/Multiscreen_app.java
Original file line number Diff line number Diff line change
@@ -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"
25 changes: 25 additions & 0 deletions First_project/Notes.java
Original file line number Diff line number Diff line change
@@ -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) {

}
}
108 changes: 108 additions & 0 deletions First_project/tic_tac_toe.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
*/