What is Programming in Java?
Java is a popular object-oriented programming language that was first released in 1995. It is used for developing a wide range of applications, including desktop applications, mobile applications, web applications, and enterprise applications.
Here are some key features and concepts of Java programming:
Object-oriented programming: Java is an object-oriented language, which means that it focuses on the creation of objects that contain both data and methods that operate on that data.
Platform independence: Java programs can run on any platform that supports a Java Virtual Machine (JVM), which makes it a popular choice for cross-platform development.
Memory management: Java uses automatic memory management through a garbage collector, which helps to prevent memory leaks and makes it easier to write memory-safe code.
Exception handling: Java has a built-in mechanism for handling runtime errors or exceptions, which helps to ensure that programs can recover gracefully from unexpected errors.
Multi-threading: Java supports multi-threading, which allows programs to execute multiple threads of execution simultaneously, making it well-suited for developing concurrent applications.
Standard libraries: Java provides a large number of standard libraries that developers can use to build applications more quickly and easily, including libraries for networking, database access, and user interface development.
To get started with Java programming, you will need to install the Java Development Kit (JDK) on your computer. Once you have installed the JDK, you can use an Integrated Development Environment (IDE) like Eclipse or IntelliJ IDEA to write and debug your code.
To learn Java programming, you can start with the basics of the language, such as data types, control structures, and object-oriented programming concepts. There are many online resources and tutorials available for learning Java, including Oracle's official Java tutorials, which cover everything from the basics to advanced topics like concurrency and networking.
Week 12 : Programming Assignment 1
Complete the code to develop an extended version of the ADVANCED CALCULATOR with added special functions that emulates all the functions of the GUI Calculator as shown in the image.
Note the following points carefully:
1. Use only double datatype to store all numeric values.
2. Each button on the calculator should be operated by typing the characters from 'a' to 't'.
3. You may use the already defined function gui_map(char).
4. Use predefined methods from java.lang.Math class wherever applicable.
5. Without '=' binary operations won't give output as shown in Input_3 and Output_3 example below.
5. The calculator should be able to perform required operations on one or two operands as shown in the below example:
Input_1:
okhid
Output_1:
100.0
Input_2:
ia
Output_2:
Solution :
// Perform calculaton operations
outerloop:
for(int i=0; i<seq.length; i++){
int r=0;
if(seq[i]=='+'||seq[i]=='-'||seq[i]=='/'||seq[i]=='X'||seq[i]=='='){
for(int j=0; j<i; j++){
o1+=Character.toString(seq[j]);
}
operand1=Double.parseDouble(o1);
for(int k=i+1; k<seq.length; k++){
if(seq[k]=='='){
outflag=1;
operand2=Double.parseDouble(o2);
if(seq[i]=='+'){
output=operand1+operand2;
}else if(seq[i]=='-'){
output=operand1-operand2;
}else if(seq[i]=='/'){
output=operand1/operand2;
}else if(seq[i]=='X'){
output=operand1*operand2;
}
break outerloop;
}else{
o2+=Character.toString(seq[k]);
}
}
}
else if(seq[i]=='R' || seq[i]=='S' || seq[i]=='F'){
for (int j=0;j<i;j++)
o1+=Character.toString(seq[j]);
operand1=Double.parseDouble(o1);
if (seq[i]=='R')
System.out.print(Math.sqrt(operand1));
else if(seq[i]=='S')
System.out.print(operand1*operand1);
else if (seq[i]=='F')
System.out.print(1/operand1);
}
} |
Week 12 : Programming Assignment 2
A partial code fragment is given. The URL class object is created in try block.You should write appropriate method( ) to print the protocol name and host name from the given url string.
For example:
https://www.xyz.com:1080/index.htm
protocol://host:port/filename
Solution :
try{
URL url=new URL("http://www.Nptel.com/java-tutorial");
//use appropriate code to print the protocol name and host name from url
System.out.println("Protocol: "+url.getProtocol());
System.out.println("Host Name: "+url.getHost());
}
catch(Exception e){System.out.println(e);}
}
} |
Week 12 : Programming Assignment 3
Write a program to create a record by taking inputs using Scanner class as first name as string ,last name as string ,roll number as integer ,subject1 mark as float,subject2 mark as float. Your program should print in the format
"name rollnumber avgmark".
For example:
input:
ram
das
123
25.5
24.5
output:
ramdas 123 25.0
Solution :
//Read your first name
String f = s1.next();
//Read your last name
String l = s1.next();
//Read rollnumber
int n = s1.nextInt();
//Read 1st subject mark
double db = s1.nextDouble();
//Read 2nd subject mark
double db1 = s1.nextDouble();
double avg=(db+db1)/2;
System.out.println(f + l +" "+ n +" "+avg ); |
Week 12 : Programming Assignment 4
A program code is given to call the parent class static method and instance method in derive class without creating object of parent class. You should write the appropriate code so that the program print the contents of static method() and instance method () of parent class.
Solution :
public static void main(String[] args) {
// Call the instance method in the Parent class
Child c= new Child();
c.testInstanceMethod();
// Call the static method in the Parent class
Parent.testClassMethod();
//Parent ob=c;
//ob.testClassMethod();
}
} |
Week 12 : Programming Assignment 5
Write a recursive function to print the sum of first n odd integer numbers. The recursive function should have the prototype
" int sum_odd_n(int n) ".
For example :
input : 5
output: 25
input : 6
output : 36
Solution :
//Call the method recursively.
int c=n,sum=0;
if(c==n){
sum=n*2-1;
}
return sum+sum_odd_n(n-1); |
CRITERIA TO GET A CERTIFICATE
Average assignment score = 25% of the average of the best 8 assignments out of the total 12 assignments given in the course.
Exam score = 75% of the proctored certification exam score out of 100
Final score = Average assignment score + Exam score
YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF THE AVERAGE ASSIGNMENT SCORE >=10/25 AND THE EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.
| Programming in JAVA | Answers |
| Assignment 1 | Click Here |
| Assignment 2 | Click Here |
| Assignment 3 | Click Here |
| Assignment 4 | Click Here |
| Assignment 5 | Click Here |
| Assignment 6 | Click Here |
| Assignment 7 | Click Here |
| Assignment 8 | Click Here |
| Assignment 9 | Click Here |
| Assignment 10 | Click Here |
| Assignment 11 | Click Here |
| Assignment 12 | Click Here |
Comments
Post a Comment