Please scroll down for latest Programs. 👇
Week 01 : Programming Assignment 1
Write a Java program to print the area and perimeter of a rectangle.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5.6 8.5 | Perimeter is 2*(8.5 + 5.6) = 28.20\n
Area is 5.6 * 8.5 = 47.60 | Perimeter is 2*(8.5 + 5.6) = 28.20\n
Area is 5.6 * 8.5 = 47.60 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 01 : Programming Assignment 2
Write a Java program and compute the sum of an integer's digits.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 00020 | The sum of the digits is: 2 | The sum of the digits is: 2 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 01 : Programming Assignment 3
Write a Java program to display n terms of natural numbers and their sum.
(Remember to match the output given exactly, including the spaces and new lines)
(passed with presentation error means you will get full marks)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5 | The first 5 natural numbers are : \n
1\n
2\n
3\n
4\n
5\n
The Sum of Natural Number upto 5 terms : 15 | The first 5 natural numbers are : \n
1\n
2\n
3\n
4\n
5\n
The Sum of Natural Number upto 5 terms : 15 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 01 : Programming Assignment 4
Write a Java program to make such a pattern like a right angle triangle with the number increased by 1.
(Remember to match the output given exactly, including the spaces and new lines)
(Ignore presentation errors for this and all future programming assignments)
(passed with presentation error means you will get full marks)
for n=3:
1
2 3
4 5 6
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 4 | 1 \n
2 3 \n
4 5 6 \n
7 8 9 10 | 1 \n
2 3 \n
4 5 6 \n
7 8 9 10 \n
| Passed after ignoring Presentation Error |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 01 : Programming Assignment 5
Write a Java program to convert an integer number to a binary number.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 47 | Binary number is: 101111 | Binary number is: 101111 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 02 : Programming Assignment 1
Complete the code segment to call the method display() of class Former first and then call display() method of class Latter.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | This is Former Class.\n
This is Latter Class. | This is Former Class.\n
This is Latter Class. | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 02 : Programming Assignment 2
Create a class Student with private attributes for name and age.
Use a constructor to initialize these attributes and provide public getter methods to access them.
In the main method, an instance of Student is created and the student's details are printed.
Guideline to Solve:
§ Define the Student class with private attributes.
§ Use a constructor to initialize the attributes.
§ Implement getter methods for the attributes.
Follow the naming convetion used in the Fixed code.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | Alice
20 | Student Name: Alice\n
Student Age: 20 | Student Name: Alice\n
Student Age: 20 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 02 : Programming Assignment 3
Create a class Rectangle with attributes length and width.
Provide two constructors: one with no parameters (default to 1) and
another with parameters to initialize the attributes.
Use the this keyword to avoid name space collision.
Create a getArea() function that returns the area of the rectangle.
Guideline to Solve:
§ Define the Rectangle class with attributes and constructors.
§ Define a default Rectangle constructor that inializes length and width to 1.
§ Use the this keyword in the parameterized constructor.
§ Define a getArea() funtion that returns the area of there rectangle
Follow the naming convetion used in the Fixed code.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 2.5
3.5 | Default Rectangle: L, W, A : 1.0, 1.0, 1.0\n
Parameterised Rectangle: L, W, A : 2.5, 3.5, 8.75 | Default Rectangle: L, W, A : 1.0, 1.0, 1.0\n
Parameterised Rectangle: L, W, A : 2.5, 3.5, 8.75 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 02 : Programming Assignment 4
Create a class Circle that encapsulates the properties of a circle.
The class should have a private field for the radius, a constructor to initialize the radius, and methods to calculate the area and circumference of the circle.
NOTE: use Math.PI for PI calculations (DO NOT USE 22/7)
Guideline to Solve:
§ Define the Circle class with attributes and constructors.
§ Use the this keyword in the parameterized constructor.
§ Define a getArea() funtion that returns the area of there Circle (use Math.PI)
§ Define a getCircumference() funtion that returns the circumference of there Circle (use Math.PI)
Follow the naming convetion used in the Fixed code.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5.0 | Area: 78.54\n
Circumference: 31.42 | Area: 78.54\n
Circumference: 31.42 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 02 : Programming Assignment 5
Complete the code by creating the constructor and the getter functions for a class Dog as defined below.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | Tommy
German Shepard
2
Black | Hi my name is: Tommy\n
My breed is: German Shepard\n
My age is: 2\n
My color is: Black | Hi my name is: Tommy\n
My breed is: German Shepard\n
My age is: 2\n
My color is: Black | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 03 : Programming Assignment 1
Create a class Department having a method getCourses that prints "These are the department's courses". It will have two subclasses, ComputerScience and MechanicalEngineering, each having a method with the same name that prints specific courses for the respective departments.Call the method by creating an object of each of the three classes.
(Remember to match the output given exactly, including the spaces and new lines)
(passed with presentation error means you will get full marks)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | Courses: Data Structures, Algorithms, Operating Systems\n
Courses: Thermodynamics, Fluid Mechanics, Heat Transfer | Courses: Data Structures, Algorithms, Operating Systems\n
Courses: Thermodynamics, Fluid Mechanics, Heat Transfer\n
| Passed after ignoring Presentation Error |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 03 : Programming Assignment 2
There are two class cls1 and cls2 which is subclass of cls1. cls1 having a method "add" which add two numbers. Create two method inside cls2 which will take 2 parameters as input i.e. a and b and print the sum , multiplication and sum of their squares i.e (a^2) + (b2).
(Remember to match the output given exactly, including the spaces and new lines)
(passed with presentation error means you will get full marks)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 2
4 | 6\n
8\n
20 | 6\n
8\n
20\n
| Passed after ignoring Presentation Error |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 03 : Programming Assignment 3
Write a program to print the factorial of a number by defining a recursive method named 'Factorial'.
Factorial of any number n is represented by n! and is equal to 1*2*3*....*(n-1)*n. E.g.-
4! = 1*2*3*4 = 24
3! = 3*2*1 = 6
2! = 2*1 = 2
Also,
1! = 1
0! = 0
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5 | 120 | 120 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 03 : Programming Assignment 4
Write a program to take integer inputs from user until he/she presses q ( Ask to press q to quit after every integer input ). Print average and product of all numbers.
(Remember to match the output given exactly, including the spaces and new lines)
(passed with presentation error means you will get full marks)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 2
4
5
6
8
1
q | Product is: 1920\n
Average is: 4.3333335 | Product is: 1920\n
Average is: 4.3333335 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 03 : Programming Assignment 5
Write a Java program to create a class called Employee with methods called work() and getSalary(). Create a subclass called HRManager that overrides the work() method and adds a new method called addEmployee().
(Remember to match the output given exactly, including the spaces and new lines)
(passed with presentation error means you will get full marks)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | working as an employee!\n
Employee salary: 40000\n
\n
Managing employees\n
Manager salary: 70000\n
\n
Adding new employee! | working as an employee!\n
Employee salary: 40000\n
\n
Managing employees\n
Manager salary: 70000\n
\n
Adding new employee! | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 04 : Programming Assignment 1
Complete the code segment to swap two numbers using call by object reference.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5 10 | Before Swap: 5 10\n
After Swap: 10 5 | Before Swap: 5 10\n
After Swap: 10 5 | Passed |
Week 04 : Programming Assignment 2
1 - Problem Statement:
Define a class Point with members
§ private double x;
§ private double y;
and methods:
§ public Point(double x, double y){} // Constructor to create a new point?
§ public double slope(Point p2){} // Function to return the slope of the line formed from current Point and another Point
(Assume that input will always be chosen so that slope will never be infinite)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 0 0
1 1 | Slope: 1.0 | Slope: 1.0 | Passed |
Week 04 : Programming Assignment 3
This program to exercise the create static and non-static methods. A partial code is given, you have to define two methods, namely sum( ) and multiply( ). These methods have been called to find the sum and product of two numbers. Complete the code segment as instructed.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5 10 | Sum: 15\n
Product: 50 | Sum: 15\n
Product: 50 | Passed |
Week 04 : Programming Assignment 4
The program in this assignment is attempted to print the following output:
-----------------OUTPUT-------------------
This is large
This is medium
This is small
This is extra-large
-------------------------------------------------
However, the code is intentionally with some bugs in it. Debug the code to execute the program successfully.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | This is large\n
This is medium\n
This is small\n
This is extra-large | This is large\n
This is medium\n
This is small\n
This is extra-large | Passed |
Week 04 : Programming Assignment 5
Consider First n even numbers starting from zero(0).Complete the code segment to calculate sum of all the numbers divisible by 3 from 0 to n. Print the sum.
Example:
Input: n = 5
-------
0 2 4 6 8
Even number divisible by 3:0 6
sum:6
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 6 | Sum: 6 | Sum: 6 | Passed |
Week 05 : Programming Assignment 1
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 7 | Error: 7 is odd. | Error: 7 is odd. | Passed |
Test Case 2 | 8 | 8 is even. | 8 is even. | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 05 : Programming Assignment 2
Write a program to create an interface Searchable with a method search(String keyword) that searches for a given keyword in a text document.
Create two classes Document and WebPage that implement the Searchable interface and provide their own implementations of the search() method.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | You are a hard working person.
student | Document contains keyword: student false\n
Webpage contains keyword 'webpage': true | Document contains keyword: student false\n
Webpage contains keyword 'webpage': true | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 05 : Programming Assignment 3
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | Fly by my crypt | Original string: Fly by my crypt\n
Error: String does not contain any vowels. | Original string: Fly by my crypt\n
Error: String does not contain any vowels. | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 05 : Programming Assignment 4
Create three classes Spacecraft, Airplane, and Helicopter that implement the Flyable interface.
Implement the fly_obj() method for each of the three classes.
(Remember to match the output given exactly, including the spaces and new lines)
(passed with presentation error means you will get full marks)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | Spacecraft is flying\n
Airplane is flying\n
Helicopter is flying | Spacecraft is flying\n
Airplane is flying\n
Helicopter is flying\n
| Passed after ignoring Presentation Error |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 05 : Programming Assignment 5
Create three classes Football, Volleyball, and Basketball that implement the Playable interface and override the play() method to play the respective sports.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | Playing football\n
Playing volleyball\n
Playing basketball | Playing football\n
Playing volleyball\n
Playing basketball\n
| Passed after ignoring Presentation Error |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 06 : Programming Assignment 1
You have to declare a class A, which will implement the interface Number.
Note that the method findSqr(n) will return the square of the number n.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 12 | 144 | 144 | Passed |
Week 06 : Programming Assignment 2
Your function should return -1, if the argument(s) is(are) negative number(s).
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 20 30 | 10 | 10 | Passed |
Week 06 : Programming Assignment 3
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 06 : Programming Assignment 4
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 06 : Programming Assignment 5
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 07 : Programming Assignment 1
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | Believe in yourself | The longest word in the text is: yourself | The longest word in the text is: yourself | Passed |
Week 07 : Programming Assignment 2
Write a program to print Swastika Pattern in Java.
Input is 2 numbers.
R
C
(Rows and Columns)
For Example:
Input:
5
5
Output:
* ***
* *
*****
* *
*** *
NOTE: Do not print any spaces between the ‘*’
Output should match exactly as specified by the question
(Remember to match the output given exactly, including the spaces and new lines)
(passed with presentation error means you will get full marks)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 7
9 | * *****\n
* *\n
* *\n
*********\n
* *\n
* *\n
***** * | * *****\n
* *\n
* *\n
*********\n
* *\n
* *\n
***** *\n
| Passed after ignoring Presentation Error |
Week 07 : Programming Assignment 3
Write a program to remove all occurrences of an element from array in Java.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5
12 23 34 23 45
23 | Original Array: [12, 23, 34, 23, 45]\n
Array after removing 23: [12, 34, 45] | Original Array: [12, 23, 34, 23, 45]\n
Array after removing 23: [12, 34, 45] | Passed |
Week 07 : Programming Assignment 4
Write a program to compute the sum of all prime numbers in a given range.
The range value will be positive.
Follow the naming convention as given in the main method of the suffix code.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 4
13 | 36 | 36 | Passed |
Week 07 : Programming Assignment 5
Code to create two threads, one printing even numbers and the other printing odd numbers.
§ The PrintNumbers class is declared, and it implements the Runnable interface. This interface is part of Java's concurrency support and is used to represent a task that can be executed concurrently by a thread.
§ Create a constructor of this class that takes two private instance variables (start and end) to represent the range of numbers that will be printed by the thread.
§ Create a run method that is required by the Runnable interface and contains the code that will be executed when the thread is started. In this case, it should prints odd numbers within the specified range (start to end) using a for loop.
§ Hint: Thread.currentThread().getName() returns the name of the currently executing thread, which is useful for identifying which thread is printing the numbers.
Follow the naming convention as given in the main method of the suffix code.
(Remember to match the output given exactly, including the spaces and new lines)
(passed with presentation error means you will get full marks)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 2
10
3
7 | EvenThread: 2\n
EvenThread: 4\n
EvenThread: 6\n
EvenThread: 8\n
EvenThread: 10\n
OddThread: 3\n
OddThread: 5\n
OddThread: 7 | EvenThread: 2\n
EvenThread: 4\n
EvenThread: 6\n
EvenThread: 8\n
EvenThread: 10\n
OddThread: 3\n
OddThread: 5\n
OddThread: 7\n
| Passed after ignoring Presentation Error |
Week 08 : Programming Assignment 1
Complete the code segment to print the current year. Your code should compile successfully.
Note: In this program, you are not allowed to use any import statement. Use should use predefined class Calendar defined in java.util package.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | Current Year: 2024\n
Current Month: 8 | Current Year: 2024\n
Current Month: 8 | Passed |
Week 08 : Programming Assignment 2
Complete the code segment to call the default method in the interface First and Second.
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 08 : Programming Assignment 3
Modify the code segment to print the following output.
-----------------OUTPUT------------------- (this line should not be printed)
Circle: This is Shape1
Circle: This is Shape2
-------------------------------------------------
(Remember to match the output given exactly, including the spaces and new lines)
(passed with presentation error means you will always get full marks)
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 08 : Programming Assignment 4
Complete the code segment to execute the following program successfully. You should import the correct package(s) and/or class(s) to complete the code.
(Note: there is no error in the given fixed code, there is a way to print without using “System”)
(Hint: Use Static import)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | Programming in JAVA | Course: Programming in JAVA | Course: Programming in JAVA | Passed |
Week 08 : Programming Assignment 5
In the following program, there may be multiple exceptions.
You have to complete the code using ONLY ONE try-catch block to handle all the possible exceptions.
For example, if user’s input is 1, then it will throw and catch “java.lang.NullPointerException“.
(Hint: Try to catch the exception and print it)
(NOTE: DO NOT USE MORE THAN ONE TRY CATCH, there may be a penalty if you use more than one try catch block)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5 | No exception | No exception | Passed |
Test Case 2 | 1 | java.lang.NullPointerException | java.lang.NullPointerException | Passed |
Test Case 3 | 0 | java.lang.ArithmeticException: / by zero | java.lang.ArithmeticException: / by zero | Passed |
Week 09 : Programming Assignment 1
Write a Java program to display the number rhombus structure.
Input: n=2
Output:
1
212
1
(the output shown with the public test case has no spaces in the beginning,
its a fault of the swayam portal as it removes whitespaces before and after the output
you can write your program normally including spaces and it will be correct)
(passed with presentation error means you will always get full marks)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 4 | 1\n
212\n
32123\n
4321234\n
32123\n
212\n
1 | 1\n
212\n
32123\n
4321234\n
32123\n
212\n
1\n
| Passed after ignoring Presentation Error |
Week 09 : Programming Assignment 2
Write a Java program to create an abstract class Person with abstract methods eat(), sleep() and exercise().
Create subclasses Athlete and LazyPerson that extend the Person class and implement the respective methods to describe how each person eats, sleeps and exercises.
Override the respective method in each subclass.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | NA | Athlete: Include foods full of calcium, iron, potassium, and fiber.\n
Athlete: Training allows the body to gradually build up strength and endurance, improve skill levels and build motivation, ambition and confidence.\n
Athlete: sleeps for 8 hours.\n
Couch Potato: Eating while watching TV also prolongs the time period that we're eating.\n
Couch Potato: Rarely exercising or being physically active.\n
Couch Potato: sleeps for 12 hours. | Athlete: Include foods full of calcium, iron, potassium, and fiber.\n
Athlete: Training allows the body to gradually build up strength and endurance, improve skill levels and build motivation, ambition and confidence.\n
Athlete: sleeps for 8 hours.\n
Couch Potato: Eating while watching TV also prolongs the time period that we're eating.\n
Couch Potato: Rarely exercising or being physically active.\n
Couch Potato: sleeps for 12 hours.\n
| Passed after ignoring Presentation Error |
Week 09 : Programming Assignment 3
Write a Java program to create a base class Shape with methods draw() and calculateArea().
Create two subclasses Circle and Cylinder.
Override the draw() method in each subclass to draw the respective shape.
In addition, override the calculateArea() method in the Cylinder subclass to calculate and return the total surface area of the cylinder.
(Remember to match the output given exactly, including the spaces and new lines)
(passed with presentation error means you will always get full marks)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 2
3 | Drawing a circle\n
Area: 12.5664\n
Drawing a cylinder\n
Area: 62.8319 | Drawing a circle\n
Area: 12.5664\n
Drawing a cylinder\n
Area: 62.8319\n
| Passed after ignoring Presentation Error |
Week 09 : Programming Assignment 4
Write a Java program to create a class called "ElectronicsProduct" with attributes for product ID, name, and price.
Implement methods to apply a discount and calculate the final price.
Create a subclass " WashingMachine" that adds a warranty period attribute and a method to extend the warranty.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | w34
whirlpool
800
12
10 | Discount applied to Washing Machine: whirlpool\n
Product ID: w34\n
Name: whirlpool\n
Price after discount: $720.0\n
Warranty period: 12 months\n
Warranty period after extension: 24 months | Discount applied to Washing Machine: whirlpool\n
Product ID: w34\n
Name: whirlpool\n
Price after discount: $720.0\n
Warranty period: 12 months\n
Warranty period after extension: 24 months | Passed |
Week 09 : Programming Assignment 5
Write a Java program to find the length of the longest sequence of zeros in binary representation of an integer.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 12546 | 6 | 6 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Week 10 : Programming Assignment 1
Complete the code fragment to read three integer inputs from keyboard and find the sum and store the result in the variable "sum".
NOTE: Name the class W10_P1 and the file W10_P1.java
(Remember to match the output given exactly, including the spaces and new lines)
(passed with presentation error means you will always get full marks)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 1
2
3 | 6 | 6 | Passed |
Week 10 : Programming Assignment 2
A byte char array is initialized.
You have to enter an index value "n".
According to index your program will print the byte and its corresponding char value.
Complete the code segment to catch the exception in the following, if any.
On the occurrence of such an exception, your program should print “Error: Exception occoured”.
If there is no such exception, it will print the required output.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 1 | 80\n
P | 80\n
P | Passed |
Test Case 2 | 4 | 76\n
L | 76\n
L | Passed |
Test Case 3 | 24 | Error: Exception occoured | Error: Exception occoured | Passed |
Week 10 : Programming Assignment 3
A string is read from the keyboard and is assigned to variable "s1". Your program should print the "number of vowels in s1”. However, if your input is other than "String" data type it will print "0".
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | ram | 1 | 1 | Passed |
Test Case 2 | aaA | 3 | 3 | Passed |
Test Case 3 | 10 | 0 | 0 | Passed |
Week 10 : Programming Assignment 4
A string "s1" is already initialized. You have to read the index "n".
Complete the code segment to catch the exception in the following, if any.
On the occurrence of such an exception, your program should print “exception occur”.
If there is no such exception, your program should replace the char ‘a’ at the index value "n" of the "s1",
then it will print the modified string.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | -1 | exception occur | exception occur | Passed |
Test Case 2 | e | exception occur | exception occur | Passed |
Test Case 3 | 4 | NPTEaJAVA | NPTEaJAVA | Passed |
Week 10 : Programming Assignment 5
Complete the code below with a catch statement to print the following if the denominator (b) is zero
print “Cannot Divide by ZERO”
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 6
3 | 2 | 2 | Passed |
Test Case 2 | 1
0 | Cannot Divide by ZERO | Cannot Divide by ZERO | Passed |
Week 11 : Programming Assignment 1
The following code needs some package to work properly.
Write appropriate code to
§ import the required package(s) in order to make the program compile and execute successfully.
Hint: use static import
(NOTE: Ignore the fixed hidden code)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 0 | true | true | Passed |
Week 11 : Programming Assignment 2
Write the JDBC codes needed to create a Connection interface using the DriverManager class and the variable DB_URL. Check whether the connection is successful using 'isValid(timeout)' method to generate the output, which is either 'true' or 'false'.
Note the following points carefully:
§ Name the connection object as conn only.
§ Use timeout value as 1.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 0 | true | true | Passed |
Week 11 : Programming Assignment 3
Due to some mistakes in the below code, the code is not compiled/executable.
Modify and debug the JDBC code to make it execute successfully.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 0 | true | true | Passed |
Week 11 : Programming Assignment 4
Complete the code segment to create a new table named ‘STUDENTS’ in SQL database using the following information.
Column | UID | Name | Roll | Age |
Type | Integer | Varchar (45) | Varchar (12) | Integer |
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 1 | No. of columns : 4\n
Column 1 Name: UID\n
Column 1 Type : INT\n
Column 2 Name: Name\n
Column 2 Type : VARCHAR\n
Column 3 Name: Roll\n
Column 3 Type : VARCHAR\n
Column 4 Name: Age\n
Column 5 Type : INT | No. of columns : 4\n
Column 1 Name: UID\n
Column 1 Type : INT\n
Column 2 Name: Name\n
Column 2 Type : VARCHAR\n
Column 3 Name: Roll\n
Column 3 Type : VARCHAR\n
Column 4 Name: Age\n
Column 5 Type : INT | Passed |
Week 11 : Programming Assignment 5
Complete the code segment to rename an already created table named ‘STUDENTS’ into ‘GRADUATES’.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 1 | TABLE NAME = GRADUATES | TABLE NAME = GRADUATES | Passed |
Week 12 : Programming Assignment 1
In the following program, an array of integer data to be initialized.
During the initialization, if a user enters a value other than integer value, then it will throw InputMismatchException exception.
On the occurrence of such an exception, your program should print “You entered bad data.”
If there is no such exception it will print the total sum of the array.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 3
5 2 1 | 8 | 8 | Passed |
Test Case 2 | 2
1 g | You entered bad data. | You entered bad data. | Passed |
Week 12 : Programming Assignment 2
Write suitable code to develop a 2D Flip-Flop Array with dimension 5 × 5, which replaces all input elements with values 0 by 1 and 1 by 0.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 00001
00001
00001
00001
00001 | 11110\n
11110\n
11110\n
11110\n
11110 | 11110\n
11110\n
11110\n
11110\n
11110\n
| Passed after ignoring Presentation Error |
Week 12 : Programming Assignment 3
Write a program to print Butterfly star pattern.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 3 | * *\n
** **\n
******\n
******\n
** **\n
* * | * *\n
** **\n
******\n
******\n
** **\n
* *\n
| Passed after ignoring Presentation Error |
Week 12 : Programming Assignment 4
Write a program to solve the given Sudoku.
530070000
600195000
098000060
800060003
400803001
700020006
060000280
000419005
000080079
(Remember to match the output given exactly, including the spaces and new lines)
(passed with presentation error means you will always get full marks)
(DO NOT PUT spaces between the numbers in the output)
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 530070000
600195000
098000060
800060003
400803001
700020006
060000280
000419005
000080079 | 534678912\n
672195348\n
198342567\n
859761423\n
426853791\n
713924856\n
961537284\n
287419635\n
345286179 | 534678912\n
672195348\n
198342567\n
859761423\n
426853791\n
713924856\n
961537284\n
287419635\n
345286179 | Passed |
Week 12 : Programming Assignment 5
Write a program to create a Tic-Tac-Toe game.
You have to create the logic for determining the winner, INPUT and OUTPUT is already taken care of.
Read the code and find a method to determine the winner and store in the variable `winner` (x, o).
If it's a draw then set the `gameWon` variable as false.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | x x o
o o x
x x o | -------------\n
| x | x | o | \n
-------------\n
| o | o | x | \n
-------------\n
| x | x | o | \n
-------------\n
It's a draw! | -------------\n
| x | x | o | \n
-------------\n
| o | o | x | \n
-------------\n
| x | x | o | \n
-------------\n
It's a draw! | Passed |
Test Case 2 | x x o
x x x
o o x | -------------\n
| x | x | o | \n
-------------\n
| x | x | x | \n
-------------\n
| o | o | x | \n
-------------\n
Player x wins! | -------------\n
| x | x | o | \n
-------------\n
| x | x | x | \n
-------------\n
| o | o | x | \n
-------------\n
Player x wins! | Passed |
Test Case 3 | o o x
o x x
o x x | -------------\n
| o | o | x | \n
-------------\n
| o | x | x | \n
-------------\n
| o | x | x | \n
-------------\n
Player o wins! | -------------\n
| o | o | x | \n
-------------\n
| o | x | x | \n
-------------\n
| o | x | x | \n
-------------\n
Player o wins! | Passed |
No comments:
Post a Comment
Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.