0% found this document useful (0 votes)
47 views8 pages

Advanced Java Assignment Overview

The document discusses various Java programming concepts like classes, conditionals, loops, operators, converting integers to strings, finding the median of sorted arrays, wildcard matching, and bitwise operations on number ranges. It contains code snippets and explanations for implementing these concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views8 pages

Advanced Java Assignment Overview

The document discusses various Java programming concepts like classes, conditionals, loops, operators, converting integers to strings, finding the median of sorted arrays, wildcard matching, and bitwise operations on number ranges. It contains code snippets and explanations for implementing these concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Assignment – Advanced Java (Day 1)

Student Name: Vishesh Kaushik UID: 21BCS9492


Branch: CSE Section/Group: CC_648 - A
Semester: 6th Date: 24/05/24
Subject Name: Advance Java Subject Code:21CSP-351

1. Class vs. Instance

using namespace std;


#include <iostream>

class Person{
public:
int age;
Person(int initialAge);
void amIOld();
void yearPasses();
};
Person::Person(int initialAge){
// Add some more code to run some checks on initialAge
age = initialAge;
if(initialAge < 0){
initialAge = 0;
cout<< "Age is not valid, setting age to 0.\n";
}
}
void Person::amIOld(){
if(age < 13){
cout<<"You are young.\n";
}
else if(age >=13 && age <18){
cout<<"You are a teenager.\n";
}
else{
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
cout<<"You are old.\n";
} }
void Person::yearPasses(){
// Increment the age of the person in here
++age;
}

int main(){
int t;
int age;
cin >> t;
for(int i=0; i < t; i++) {
cin >> age;
Person p(age);
p.amIOld();
for(int j=0; j < 3; j++) {
p.yearPasses();
}
p.amIOld();
cout << '\n';
}
return 0;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
2. Intro to Conditional Statements

#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
if(N%2==0){
if(N>20){
cout<<"Not Weird";
}
if(N>=2 && N<=5){
cout<<"Not Weird";
}
if(N>=6 && N<=20){
cout<<"Weird";
}
}else{
cout<<"Weird";
}
return 0;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

3. Loops

#include <bits/stdc++.h>

using namespace std;

int main()
{
int n;
cin >> n;

for (int i=1;i<=10;i++){


cout<<n<<" x "<<i<<" = "<<n*i<<endl;
}
return 0;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

4. Operators

class Result {

public static void solve(double meal_cost, int tip_percent, int tax_percent) {


double meal_tip = meal_cost/100*tip_percent;
double meal_tax = meal_cost/100*tax_percent;
double total = meal_cost+meal_tip+meal_tax;
Math.round(total);
System.out.println(Math.round(total));
}
}

public class Solution {


public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
double meal_cost = Double.parseDouble(bufferedReader.readLine().trim());
int tip_percent = Integer.parseInt(bufferedReader.readLine().trim());
int tax_percent = Integer.parseInt(bufferedReader.readLine().trim());
Result.solve(meal_cost, tip_percent, tax_percent);
bufferedReader.close();
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

5. Java Int to String

import java.io.*;
import java.util.*;

public class Solution {


public static void main(String[]
args)
{
Scanner tc = new Scanner
(System.in);
int n;
n= tc.nextInt();
if (n < 100 || n > -100 )
{
String nString = "" + n;
System.out.print ("Good
job");
}
else
{
System.out.print ("Wrong
answer");
}
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
6. Median of Two Sorted Arrays

7. Wildcard Matching
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

8. Bitwise AND of Numbers Range

You might also like