Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assignment 2 #107

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/java-backend-bootcamp-fork.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions session-02-big-picture/student-notes-repos.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
- https://github.com/Raj04/Spring-Bootcamp
- https://github.com/shawchandankumar/Java-Backend-Development
- https://github.com/bogdanbilcan/JavaBrains-BootCampNotes
- https://github.com/sahilpandith/java-backend-bootcamp/blob/main/README.md
3 changes: 3 additions & 0 deletions session-03-java-basics/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions session-03-java-basics/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions session-03-java-basics/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions session-03-java-basics/.idea/session-03-java-basics.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions session-03-java-basics/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions session-03-java-basics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@
## Contents
### Basic Syntax:
Explains the basic syntax of the Java programming language, including how to declare variables, use control structures, and perform input/output operations.

public class Main {
public static void main(String[] args){
//variable declaration
int i =0;
String s = "str";

if(i==0) {
System.out.println(i)
}
}
}
There are two types of variable declaration in java
1) Primitives : These are immutable.
1. int
2. double
3. float
4. long
5. boolean
6. short
7. byte
8. chat

### Data Types:
Explains the different data types in Java, including primitive types (such as int, double, and boolean) and non-primitive types (such as Strings).
### Operators:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.javabrains.javabasics;

public class A {
String var = "string";
private String privateVar = "privateString";
protected String protectedVar = "protectedString";

public String publicVar = "publicString";

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,29 @@
Create an anonymous inner class implementation of `Animal2` and then call the `makeSound` method
*/

abstract class Animal2{
abstract void makesound();
}
public class AnonymousInnerClasses {
public static void main(String[] args) {
Animal2 cat = new Animal2(){
@Override
public void makesound(){
System.out.println("meow");

}
};
cat.makesound();

Animal2 dog = new Animal2(){
@Override
public void makesound(){
System.out.println("bow");

}
};
dog.makesound();


}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
package io.javabrains.javabasics;

import java.util.Arrays;

public class ArrayChallenge {
public static void main(String[] args) {
// Step 1: Create an array of integers

int[] arr = {10,20,33,10};

// Step 2: Use arrays and array operations to find the sum, average, and largest number in the array
int sum = 0;
double avg;
int largest =arr[0];
for (int i :arr){
sum+=i;
if(i>largest){
largest =i;
}
}
avg = sum / arr.length;

System.out.println("sum = " + sum);
System.out.println("avg = " + avg);
System.out.println("largest = " + largest);
int[] arrCopy = new int[3] ;
System.arraycopy(arr,1,arrCopy,0,3);
System.out.println("arrCopy = " + Arrays.toString(arrCopy));
System.out.println("arr = " + Arrays.toString(arr));

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package io.javabrains.javabasics;

import org.w3c.dom.css.Rect;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;


public class Assigments {

public static void main(String[] args) throws IOException {

// Assignment1
Scanner scanner = new Scanner(System.in);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

//
// System.out.println("Enter first number");
// double num1 = Double.parseDouble(scanner.nextLine());
//
// System.out.println("Enter second number");
// double num2 = Double.parseDouble(bufferedReader.readLine());
//
//
// System.out.println("sum " + (num1+num2));
// System.out.println("sub " + (num1-num2));
// System.out.println("product " + (num1*num2));
// System.out.println("quotient " + (num1/num2));
//
//
// //assognemtn2
//
// System.out.println("Enter name");
// String name = scanner.nextLine();
// System.out.println("Enter age");
// int age = Integer.parseInt(bufferedReader.readLine());
// System.out.println("Enter salary");
// double salary = Double.parseDouble(scanner.nextLine());
//
// System.out.println("name = " + name);
// System.out.println("age = " + age);
// System.out.println("salary = " + salary);
//
//
// //assignemt 3
//
// if(num1==0){
// System.out.println("zero");
// }else if (num1>0){
// System.out.println("positive");
// }else {
// System.out.println("negative");
// }
//
//
// //Assignent 4
// System.out.println("enter the size of array");
// int length = Integer.parseInt(scanner.nextLine());
//
// ArrayList<Integer> list = new ArrayList<Integer>();
//// Integer[] list = {};
// for (int i =0; i<length;i++){
// System.out.println("Enter Element " + i );
// list.add(Integer.parseInt(scanner.nextLine()));
// }
//
// System.out.println(list);
//


//Assignemnt 5

// System.out.println("Enter a string");
// String str = scanner.nextLine();
//
// ArrayList<Character> vowels = new ArrayList<>();
// vowels.add('a');
// vowels.add('e');
// vowels.add('i');
// vowels.add('o');
// vowels.add('u');
// int count=0;
// for(char c : str.toCharArray()){
// if(vowels.contains(Character.toLowerCase(c))){
// count++;
// }
// }
//
// System.out.println("count = " + count);
//
//
// scanner.close();
// bufferedReader.close();
//

// Assignment 6
Rectangle1 rect = new Rectangle1(12,23);
System.out.println(rect.calculateArea());

//Assignment 6
Animal1 loin = new Lion1("timothy",178,21);
Animal1 cow = new Cow("jersey",154,20);

loin.feed();;
cow.feed();
}
}

class Rectangle1{
int height;
int width;
Rectangle1(int height,int width){
this.height = height;
this.width = width;
}

public int calculateArea(){
return this.height* this.width;
}
}

class Animal1 {
String name;
double weight;
int age;
Animal1(String name,double weight,int age){
this.name = name;
this.weight = weight;
this.age = age;
}
public void feed(){
System.out.println("Animal eats food");
}
}

class Lion1 extends Animal1{
Lion1(String name,double weight, int age){
super(name,weight,age);
}
public void feed(){
System.out.println("Loin eats meat");
}

}

class Cow extends Animal1{
Cow(String name,double weight, int age){
super(name,weight,age);
}
public void feed(){
System.out.println("Cow eats grass");
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.javabrains.javabasics;

class B {
public void accessVars(){
A a = new A();
// System.out.println("a.privateVar = " + a.privateVar); // can't perform this since it is private var
System.out.println("a.var = " + a.var);
System.out.println("a.protectedVar = " + a.protectedVar);
System.out.println("a.publicVar = " + a.publicVar);
}
public static void main(String[] args) {
B b = new B();
b.accessVars();
}
}


Loading