Menu
Topics Index
...
`

Intermediate Level Test 8 has these questions


Create Book objects and assign data

Write code for creating the Book object and assigning it to the object reference java. Using the dot operator on the reference java, set the name to "Java The Complete Reference", author to "Herbert Schildt", edition to 7, numberOfPages to 1116 and the price to 527.5
class BookTester

{    public static void main(String s[])
    {
        Book java = createJavaBook();
        System.out.println("Book Name = " + java.name);
        System.out.println("Author = " + java.author);
        System.out.println("Edition = " + java.edition);
        System.out.println("Pages = " + java.numberOfPages);
        System.out.println("Price = Rs. " + java.price);

    }


public static Book createJavaBook()
{
//Write code here to create a Book object and initialize the member variables as mentioned in the question. Also write the code for returning the created book.
}
}
class Book
{
String name;
String author;
int edition;
int numberOfPages;
double price;
}



Print Perfect Squares In The Given Range

Write a program to print perfect squares in the given range. For e.g., 4, 9, 16, 25 etc are perfect squares. Spaces between the numbers are important. All the numbers should be in one line. Use System.out.println or System.out.print for printing.
Input (Integer, Integer) Printed Output
1 to 10 4 9
9 to 49 9 16 25 36 49
3000 to 3300 3025 3136 3249
class PrintPerfectSquaresInRange

{    public static void main(String s[])
    {
        printPerfectSquaresInRange(10, 100);

    }


public static void printPerfectSquaresInRange(int startValue, int endValue)
{
//Write code here to print the required perfect squares between the start value and end value. Use System.out.println or System.out.print for printing.
}
}



Define Mobile Class

Define a Mobile class with member variables model, numberOfSims, memory and hasCamera. There respective data types are String, int, double and boolean.
class MobileTester

{    public static void main(String s[])
    {
        Mobile mobile = new Mobile();
        mobile.model = "Nokia 2430";
        mobile.numberOfSims = 1;
        mobile.memory = 512.0;
        mobile.hasCamera = false;
        
        System.out.print(mobile.model + " has " + mobile.numberOfSims + " sims and has a memory of " + mobile.memory + " MB.");
        System.out.println(mobile.hasCamera ? " It has a camera." : " It has no camera.");

    }


}
class Mobile
{
//Write code here to define the member variables - model, numberOfSims, memory and hasCamera
}



Find Modulus Of Every Array Element

Write a program to find modulus every array element with 7.
Input (Integer Array) Output (Integer Array)
{2, 14, 8, 42, 15} {2, 0, 1, 0, 1}
{21, 34, 3, 8, 16} {0, 6, 3, 1, 2}
class ModulesEveryArrayElement

{    public static void main(String s[])
    {
        int[] input = { 3, 15, 16, 7 };
        int[] output = getModulusOfEveryArrayElement(input);
        System.out.print("Modulus of every element is : ");
        for(int element : output)
        {
            System.out.print(element + ", ");
        }

    }


public static int[] getModulusOfEveryArrayElement(int[] input)
{
int[] result = null;
//Write code here to create an array of modulus of every element with 7 and assign it to result.
return result;
}
}



Find if an array is a palindrome

Write a program which finds if the given array is a palindrome. A palindrome array is in which the elements either printed from the beginning or printed from the end should be the same.
Input (Integer Array) Output (Boolean) (TRUE / FALSE)
{ 6, 7, 8, 7, 6 } true
{ 6, 7, 8, 9, 10 } false
{ 88, 34, 145, 145, 34, 88 } true
{ 88, 34, 145, 34, 88 } true
class CheckIfArrayIsPalindrome

{    public static void main(String s[])
    {
        int [] input = { 6, 7, 8, 7, 6 };
        
        System.out.println("The array { 6, 7, 8, 7, 6 } is palindrome : " + isArrayPalindrome(input));

    }


public static boolean isArrayPalindrome(int[] input)
{
boolean result = false;
//Write code here to check if the array is a palindrome and assign the value to the result.
return result;
}
}



© meritcampus 2019

All Rights Reserved.

Open In App