info@meritcampus.com    +91-85006-22255
...
`

Intermediate Level Test 9 has these questions

Find Match Result

Write a program to find the result of a cricket match. The method takes two innings and compares them to give the results. The `Innings` class and the `MatchResult` class are already defined.
Input (Innings 1 and Innings 2 Details) (Team Name, score, wickets and overs) Output (Match Result)
``` Innings 1 = "India", 243, 5, 50.0 Innings 2 = "Australia", 231, 9, 50.0 ``` ``` winner = "India" loser = "Australia" wonByWickets = false wonByRuns = true runs = 243 - 231 = 12 wickets = 0 ```
``` Innings 1 = "India", 243, 5, 50.0 Innings 2 = "Australia", 245, 9, 48.3 ``` ``` winner = "Australia" loser = "India" wonByWickets = true wonByRuns = false runs = 0 wickets = 10 (Total Wickets) - 9 = 1 ```
``` Innings 1 = "India", 243, 5, 50.0 Innings 2 = "Australia", 243, 9, 50.0 ``` ``` wonByWickets = false wonByRuns = false runs = 0 wickets = 0 ```
``` class FindMatchResult {    public static void main(String s[])    {        Innings india = new Innings("India", 243, 5, 50.0);        Innings australia = new Innings("Australia", 231, 9, 50.0);                MatchResult result = findMatchResult(india, australia);                if(result.wonByWickets)        {            System.out.println(result.winner + " won over " + result.loser  + " by " + result.wickets + " wickets.");        }        else if (result.wonByRuns)        {            System.out.println(result.winner + " won over " + result.loser  + " by " + result.runs + " runs.");        }        else        {            System.out.println("The match between India and Australia was a tie.");        }    } public static MatchResult findMatchResult(Innings team1, Innings team2) { //Write code here to create the MatchResult by comparing the innings and return the same. } } class Innings { String teamName; int runs; int wickets; double overs; Innings(String teamName, int runs, int wickets, double overs) { this.teamName = teamName; this.runs = runs; this.wickets = wickets; this.overs = overs; } } class MatchResult { String winner; String loser; boolean wonByWickets; boolean wonByRuns; int wickets; int runs; } ```

Find Nearest Perfect Square

Write a program to find the nearest perfect square of a given number. Assume that the given number is always greater than 2.
Input (Integer) Output (Integer)
`3` `4 (Since 3 is between 1 and 4, but nearer to 4 than 1)`
`9` `9 (Since 9 it is a perfect square)`
`10` `9 (Since 10 is between 9 and 16, but nearer to 9 than 16)`
`23` `25 (Since 23 is between 16 and 25, but nearer to 25)`
`17` `16 (Since 17 is between 16 and 25, but nearer to 16)`
``` class FindNearestPerfectSquare {    public static void main(String s[])    {        int input = 23;        int result = findNearestPerfectSquare(input);                System.out.println("The nearest perfect square for " + input + " is " + result);     } public static int findNearestPerfectSquare(int input) { //Write code here to find the nearest perfect square for the given input and return the same. } } ```

Parse and create Students List

Write a program to parse the comma separated student information and create Student objects for each line of the data. The students should be in the same order as the input.
``` class ParseStudents {    public static void main(String s[])    {        String data = "Siva,2,78,A\n";        data += "Mobeen,3,92,B\n";        data += "Prem,2,87,B\n";        data += "Sasitha,2,86,A\n";        data += "Srini,8,65,A\n";        data += "Zakir,12,73,A\n";                List result = parseStudents(data);                for(int i = 0; i < result.size(); i++)        {            Student student = result.get(i);            System.out.println(student.name + " in section " + student.section + " and roll number " + student.rollNumber + " got " + student.marks + " marks.");        }    } public static List<Student> parseStudents(String data) { //Write code here to the parse the comma separated data and create the Student objects } } class Student { String name; int rollNumber; int marks; char section; Student(String name, int rollNumber, int marks, char section) { this.name = name; this.rollNumber = rollNumber; this.marks = marks; this.section = section; } } ```

Update student total marks

Write code to update the total marks of the student. A student object is passed for which the marks of different subjects are initialized.
``` class UpdateStudentTotalMarks {    public static void main(String s[])    {        Student student1 = new Student();        student1.subject1 = 57;        student1.subject2 = 84;        student1.subject3 = 93;        student1.subject4 = 76;                updateStudentTotalMarks(student1);                System.out.println("The total marks of the student are " + student1.total );    } public static void updateStudentTotalMarks(Student student) { //Write code here to update the total marks. } } class Student { int subject1; int subject2; int subject3; int subject4; int total; } ```

Give Discount on Book Price

Write a method to give 20% discount on the book price. The book will be passed as a parameter and the price has to be changed to reflect the discount. In the price was 100.0, it should become 80.0, if it was 70.0, it should become 56.0.
``` class DiscountBookPrice {    public static void main(String s[])    {        Book java = new Book();        java.name = "Java The Complete Reference";        java.author = "Herbert Schildt";        java.edition = 7;        java.numberOfPages = 1116;        java.price = 600.0;                discountBookPrice(java);                System.out.println("The price of the book " + java.name + " after discount is Rs. " + java.price );    } public static void discountBookPrice(Book input) { //Write code here to discount the price of the input book by 20%. } } class Book { String name; String author; int edition; int numberOfPages; double price; } ```