Program 1- Define a class called Library with the following description: Instance variables/data members: Int acc_num – stores the accession number of the book String title – stores the title of the book stores the name of the author Member Methods: (i) void input() – To input and store the accession number, title and author. (ii)void compute – To accept the number of days late, calculate and display and fine charged at the rate of Rs.2 per day. (iii) void display() To display the details in the following format: Accession Number Title Author Write a main method to create an object of the class and call the above member methods. Solution - public class Library { int acc_num; String title; String author; public void input() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter accession number: "); acc_num = Integer.parseInt(br.readLine
02 (Two) Marks Questions Question 1- Give one example each of a primitive data type and a composite data type. Ans. Primitive Data Types – byte, short, int, long, float, double, char, boolean Composite Data Type – Class, Array, Interface Question 2- Give one point of difference between unary and binary operators. Ans. A unary operator requires a single operand whereas a binary operator requires two operands. Examples of Unary Operators – Increment ( ++ ) and Decrement ( — ) Operators Examples of Binary Operators – +, -, *, /, % Question 3- Differentiate between call by value or pass by value and call by reference or pass by reference. Ans. In call by value, a copy of the data item is passed to the method which is called whereas in call by reference, a reference to the original data item is passed. No copy is made. Primitive types are passed by value whereas reference types are passed by reference. Question 4- Write a Java expression for (under root
QUESTION -1 A Goldbach number is a positive even integer that can be expressed as the sum of two odd primes. Note: All even integer numbers greater than 4 are Goldbach numbers. Example: 6 = 3 + 3 10 = 3 + 7 10 = 5 + 5 Hence, 6 has one odd prime pair 3 and 3. Similarly, 10 has two odd prime pairs, i.e. 3 and 7, 5 and 5. Write a program to accept an even integer ‘N’ where N > 9 and N < 50. Find all the odd prime pairs whose sum is equal to the number ‘N’. Test your program with the following data and some random data: Example 1: INPUT: N = 14 OUTPUT: PRIME PAIRS ARE: 3, 11 7, 7 Example 2: INPUT: N = 30 OUTPUT: PRIME PAIRS ARE 7, 23 11, 19 13, 17 Example 3: INPUT: N = 17 OUTPUT: INVALID INPUT. NUMBER IS ODD. Example 4: INPUT: N = 126 OUTPUT: INVALID INPUT. NUMBER OUT OF RANGE. import java.util.*; public class Goldbach { boolean isPrime(int n) { if(n<=1) //All numbers that are less than or equal to one are non-pr
Address Calculation in single (one) Dimension Array: Array of an element of an array say “A[ I ]” is calculated using the following formula: Address of A [ I ] = B + W * ( I – LB ) Where, B = Base address W = Storage Size of one element stored in the array (in byte) I = Subscript of element whose address is to be found LB = Lower limit / Lower Bound of subscript, if not specified assume 0 (zero) Example: Given the base address of an array B[1300…..1900] as 1020 and size of each element is 2 bytes in the memory. Find the address of B[1700] . Solution: The given values are: B = 1020, LB = 1300, W = 2, I = 1700 Address of A [ I ] = B + W * ( I – LB ) = 1020 + 2 * (1700 – 1300) = 1020 + 2 * 400 = 1020 + 800 = 1820 [Ans] Address Calculation in Double (Two) Dimensional Array: While storing the elements of a 2-D array in memory, these are allocated contiguous memory locations. Therefore, a 2-D array must be linearized so as to enable their s
1. Give two examples of real-world objects. Also specify their characteristics and behaviour. Ans. Real Life Objects Example1: Object Name: Pen Characteristics: Company made, Colour, Body Shape and Nip. Behaviour: 1) Used for writing. 2) Used for correction 3) Used for drawing or sketching Example 2: Object Name: Dog Characteristics: Name, Colour and Breed. Behaviour: 1) Barking 2) Wagging its tail 3) Running speed 2. What do you understand by state of an object? Explain with an example. Ans. State of an object refers to the condition in which an object is in. Thus the values/attributes of its characteristics is represented For example, a book is an object, which may be either in “open” or “closed” state, similarly a bulb may be in switched on or switched off state. 3. How are objects implemented in Software? Ans. Every object in real life has certain charac
Propositional Logic Logic is a formal method of reasoning. A proposition is an elementary atomic sentence that may either be true or false but may take no other value. A simple proposition is one that does not contain any other proposition as a part. A compound proposition is one with two or more simple propositions as parts. An operator or connective joins simple propositions into compounds. Following are the various types of connectives: 1. Disjunctive (OR) : It means at least one of the two arguments is true. OR is represented by + or ∨ . 2. Conjunctive (AND) : It means that both the arguments are true. AND is represented by or & or ∧ . 3. Conditional (Implication or If Then) : It means that if one argument is true then other argument is true. Implication is represented by ⇒ or → or ⊃ . 4. Bi-conditional (Equivalence or If And Only If): It means that either both arguments are true or both are false. Equivalence is represented
Question 1: A Circular Prime is a prime number that remains prime under cyclic shifts of its digits. When the leftmost digit is removed and replaced at the end of the remaining string of digits, the generated number is still prime. The process is repeated until the original number is reached again. A number is said to be prime if it has only two factors I and itself. Example: 131 311 113 Hence, 131 is a circular prime. Test your program with the sample data and some random data: Example 1 INPUT : N = 197 OUTPUT: 197 971 719 197 IS A CIRCULAR PRIME Example 2 INPUT : N = 1193 OUTPUT: 1193 1931 9311 3119 1193 IS A CIRCULAR PRIME Example 3 INPUT : N = 29 OUTPUT: 29 92 29 IS NOT A CIRCULAR PRIME Programming Code: import java.util.*; class CircularPrime_Q1_ISC2016 { boolean isPrime(int n) // Function for checking whether a number is prime or not { int c = 0; for(int i = 1; i<=n; i++)
1. What is the significance of WWW? Ans. WWW or World Wide Web allows a huge pool of information (as web pages) to shared by multiple users over a World Wide Network (Internet) and the introduction of Java makes the web pages dynamic and interactive in a secured manner. 2. What is Browsing? Ans. Browsing over the internet allows surfing through the internet, thus enabling the users to see information in different pages and interact with it. 3. Name two types of Java programs. 4. Why is Java choice for the Web? Ans. The introduction of active web pages makes Java an attractive addition to the web page. When we click on a web page containing a Java applet, it is not that we just read it, listen to it, or watch it– we can interact with it. The dynamic, interactive content to the web was brought about by Java: So much so web applications made in Java runs as if it is a computer program installed in the local computer. 5. What is Jav
Comments
Post a Comment