You are on page 1of 18

I – Anlayse

Welcome Aliens

You reside in a desert place, One day a space shuttle lands in front of your eyes. An
Alien comes out of the space shuttle. The alien was so friendly and you just want to
welcome her to our planet. Write a program to welcome the alien to our planet EARTH.

Input Format:
Input consists of a single string (char array) that corresponds to the name of the alien.

Output Format:
Refer to the sample output for formatting specifications.

Note:
[All text in bold corresponds to input and the rest corresponds to output]

Sample Input and output:


Enter your name:
Michael
Hello Michael ! Welcome to our planet Earth.
Character Pattern 1A
Nancy and Elizabeth are best friends. Nancy has learned the concept of loops in
programming languages and has solved various patterns to become a master in loops.
Elizabeth too wanted to learn how to solve the patterns and asked Nancy to send those
patterns so that she could learn them. Unfortunately, Nancy got busy with her
customers and she forgot to send the patterns to Elizabeth by mail. Meanwhile,
Elizabeth started working on some patterns to gain confidence in using nested loops.
One such pattern program is given below.

Write a program to generate the below pattern using nested "for" loops.

****
****
****
****

Input and Output Format:


Input consists of a single integer, n.

Sample Input 1:

Sample Output 1:
****
****
****
****

Sample Input 2:
5

Sample Output 2:
*****
*****
*****
*****
*****
Hint:
For the given problem, two for loops nested within each other is required .
The outer for loop is used to generate the number of rows required and the inner for
loop is used to generate the columns required. The pattern “*” must be displayed in the
inner for loop.

Customer Class
Assuming we have learned a good amount of Structured Programming (Variables,
Conditional Statements, Looping Constructs, Arrays) in Java, It's time to get Hands-on
with Object-Oriented programming thus harnessing the real power of Java.

You have been selected as a trainee in one of the well-known software majors. To
evaluate and expose you to real-world projects, the company has given you a
requirement document of the Phone Usage Tracking &  Bill Generation application.
and a series of problems to program the application in a step-by-step manner. Go
ahead and solve the problems and learn Java along the way !!!

A Class is a container to hold data members & member functions, representing a


template of a real-world entity. Choose the status of the program based on the code and
the requirement.

Consider a class named Customer has the following attributes


Data Type Variable Name
String customerName
String customerEmail
String customerType
String customerLocation

Consider a class named Main which contains the main method.


The main method does the following

 Obtaining the details of the customer


 Creating an object for the customer and assigning the values obtained
 Printing the values obtained using the object

Note :
1.Strictly adhere to the object-oriented specifications given as mentioned in the problem
statement.
2.All text in bold corresponds to input and the rest corresponds to the output

Sample Input and Output:


[All text in bold corresponds to input and the rest corresponds to output]
Enter the Customer Details
Enter the name
Marcus
Enter the email
marcus@mail.com
Enter the type
Domestic
Enter the location
India
Customer Details
Name: Marcus
E-mail: marcus@mail.com
Type: Domestic
Location: India
Player 5
 
The class named Player has the following private attributes.

 String name
 Integer age
 String country

A 3-argument is provided. The order in which the parameters are set is the name,
age, and country.
The toString method to display the player details is Overriden in the format as specified
below.

public String toString(){


return "Name:"+this.name+" Age:"+this.age;
}
Another class named Main is used to test the above class. In the main method, an
object of the Player class is created and its details is displayed.

Note: Strictly adhere to the object-oriented specifications given as a part of the


problem statement.

Input and Output Format:


Refer to sample input and output for formatting specifications.

Sample Input and Output :


[All text in bold corresponds to input and the rest corresponds to output].

Enter Name:
Henry
Enter Age:
29
Enter Country:
Australia
Name:Henry Age:29 Country:Australia
Player class
public class Player{ 
    private String name; 
    private int age; 
    private String country; 
    Player(String name,int age,String country){ 
       this.name=name; 
        this.age=age; 
      this.country=country; 
    } 
display()
    public String  { 
       return "Name:"+this.name+" Age:"+this.age+" Country:"+this.country; 
    } 

Main class

import java.io.*;                 
public class Main{                 
 public static void main(String args[]) throws IOException{                 
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));                 
 System.out.println("Enter Name:");                 
 String name=br.readLine();                 
 System.out.println("Enter Age:");                 
 int age=Integer.parseInt(br.readLine());                 
 System.out.println("Enter Country:");                 
 String country=br.readLine();                 
 Player p=new Player(name,age,country);                 
p.display()
 System.out.println( );                 
 }                 

 YODA
Description: As a young jedi you must learn to converse with Yoda. You have found a
simple rule that helps change a “normal” sentence into “Yoda talk”. Take the first two
words in the sentence and place them at the end. A program that uses this rule to
change the normal sentences into “Yoda talk”, but unfortunately it is shuffled. Rearrange
the program in the correct order to get the expected output based on the input.

Input:
Input consists of a string that you must change into “Yoda talk”.

Note:
The maximum length of the input string is 100

Output:
Print the corresponding sentence in Yoda talk.

Sample Input:
I will go now to find the Wookiee

Sample Output:
go now to find the Wookiee I will
Abstract Practical Problem 1
 
Let us consider the concept of cricket for our first Abstract Practical Problem. Consider
the climax of the cricket match is going on (i.e second innings of the match) and we
need to calculate the required run rate for the team to win.

If we consider cricket match there are 3 international formats Test, ODI and T20 each
has 90overs per day, 50overs and 20overs respectively. Each over has 6 balls. In our
scenario, we will consider it as its 5th day of the Test match, so the team needs to
achieve the particular runs in 90overs.

Create an abstract class Match with 3 private attributes


currentScore of type int
currentOver of type float
target of type int

Include the following methods in the class Match


display() to display the details.
      an abstract method calculateRunrate() of return type as float
calculateBalls() of return type as int.

Create the class ODI which extends the class Match .

Create the class T20 which extends the class Match .

Create the class Test which extends the class Match.

Use Appropriate Getters Setters for the above classes.

Create a driver class named Main which creates an instance of the above mentioned


classes. Require run rate and remaining balls must be calculated separately for all the
base class  (value must be round to 2 decimal place).

Input and Output format:


The required run rate is calculated as runs required/ remaining balls.
Display the double value correct to 2 decimal place
Refer to sample Input and Output for formatting specifications.

Note: All text in bold corresponds to input and the rest corresponds to output.

Sample Input and Output 1:

Enter the Cricket Format


1.ODI
2.T20
3.Test
2
Enter the Current Score
195
Enter the Current over
19.5
Enter the Target
196
Requirements:
Need 1 Run in 1 ball
Require Run Rate - 6.00

Sample Input and Output 2:

Enter the Cricket Format


1.ODI
2.T20
3.Test
1
Enter the Current Score
156
Enter the Current over
45.1
Enter the Target
185
Requirements:
Need 29 Runs in 29 balls
Require Run Rate - 6.00

Sample Input and Output 3:

Enter the Cricket Format
1.ODI
2.T20
3.Test
5

Invalid Format type
Exception All Around !
 
You start thinking -- Are exceptions around to catch only the alternate flows /
mistakes made by end-users. Exceptions mean exceptions !!! It can even be
used in business rules. A simple example would be to raise an exception
when a customer's unpaid credit card amount cross $2000 or is unpaid upto
45 days. Lets write a program that would check these details and raise a
custom exception stating "Further Transactions Not Possible until clearance of
bill.". Assume that the current date is '01/12/2015'.

1. Create a custom Exception class "OverLimitException" which extends


Exception.
2. Add a constructor which takes a Throwable Object, calls the super class
construtor using super() and prints the output as described in Problem
statement.
Create a class Account with following data members.
Data Type Variable Name
String accountNumber
String accountName
Double dueAmount

Create a class Account with following methods.


Return
Metod Name Function
Type       
Create a 3 argument constructor.
check the both conditions
validate(String dueDate, Double
Boolean (unpaid amount > $2000 || date
unpaidAmount, Double amount)
crossed more than 45 days).
void display() display the account details

Sample Input and Output:


Enter the transaction details
Enter the account number
123456
Enter the account holder name
Madhan
Enter the last due date
01/01/2016
Enter the unpaid amount
500
Enter the transaction amount
5000
Transaction successsfully completed.
Account Number : 123456
Account Name : Madhan
Unpaid Amount : 5500.0

3 ‘ } ‘ need at last

You might also like