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
|
winner = "India"
|
Innings 1 = "India", 243, 5, 50.0
|
winner = "Australia"
|
Innings 1 = "India", 243, 5, 50.0
|
wonByWickets = false
|
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;
}
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.
}
}
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;
}
}
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;
}
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;
}