Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Set 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Java Reassessment Paper

DB_AMJ22_ORACLE_UNIX_1
(Set 1)

Q1 Write a Java Program to find the sum of series to nth term (input the value of n from the user)

1 + (1*2) + (1*2*3) + ………. + (1*2*3* …… * n) (Easy)


Sample Input and Output 1:
Enter n
If input is 5
Output is 153
Sample Input and Output 2:
Enter n
If input is -1 or less than 1
Output is incorrect input

Q2 Inheritance Problem -  Super (Medium)

 
Create a class Customer with following private data members
Data Type Variable Name
String name
String address
Integer age
String mobileNumber
 

Methods in class Customer.
Method Name Function
This method displays the details of the customer with
displayCustomer( the total bill amount and  discount amount
) under privilege customer and  Normal customer
 

Create a class NormalCustomer which extends the class Customer.


Use super keyword to invoke parent class constructor.
Include a 4 arguments constructor with the appropriate arguments. The order in which
the arguments should be passed is name, address, age, mobileNumber
Methods in class NormalCustomer
Return
Method Name Function
Type
getBillAmount(amount To calculate the payment amount where
discount is 15% of amount Double
)
 

Create the class PrivilegeCustomer which extends the class Customer .


Use super keyword to invoke parent class constructor.
Include a 4 arguments constructor with the appropriate arguments. The order in which
the arguments should be passed is name, address, age, mobileNumber.
Methods in class PrivilegeCustomer
Return
Method Name Function
Type
getBillAmount(amount To calculate the payment amount where
discount is 12% of amount Double
)

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


classes.
[All text in bold corresponds to input and the rest corresponds to output.]
Sample Input and Output 1:
1)Privilege Customer
2)Normal Customer

Enter Customer Type


1
Enter The Name
Ramesh
Enter The Age
28
Enter The Address
XYZ Colony
Enter The Mobile Number
9897678566
Enter The Purchased Amount
6000
Bill Details
Name Ramesh
Mobile 9897678566
Age 28
Address XYZ Colony
Your bill amount is Rs 6000.0. Your bill amount is discount under privilege customer
You have to pay Rs 4500.00

Sample Input and Output 2:


1)Privilege Customer
2)Normal Customer

Enter Customer Type


2
Enter The Name
Jagmohan
Enter The Age
48
Enter The Address
ABC Colony
Enter The Mobile Number
9897566549
Enter The Purchased Amount
700
Bill Details
Name Jagmohan
Mobile 9897566549
Age 48
Address ABC Colony
Your bill amount is Rs 700.0. Your bill amount is discount under Normal customer
You have to pay Rs 616

Sample Input and Output 3:

1)Privilege Customer
2)Normal Customer

Enter Customer Type


3
Invalid Customer Type
Q3.
Write a program to track transactions by using the Finally keyword and manual
Exception . (medium/hard)

Consider a class Transaction with private member variables.

DataType Variable Name


String accountNumber
Double amount
Include appropriate getter and setters for above class.
Include appropriate default and parameterized constructors for the above class.

Include with the following method in Transaction


Return Type method name
Boolean validate(transactionAmount)

In validate method if the transaction amount is greater than current balance or if the


current balance is in minimal balance (1000) then throw a manual exception then
display "Insufficient Balance". Otherwise return true.
Use finally to display the available balance after transaction completed.
 

Sample Input and Output :


Enter the transaction details
Enter the account number
123456
Enter the available amount
5000
Enter the transaction amount
500
Do you want to enter more?(yes/no)
yes
Enter the transaction amount
1000
Do you want to enter more ?(yes/no)
yes
Enter the transaction amount
2000
Do you want to enter more ?(yes/no)
yes
Enter the transaction amount
800
Do you want to enter more?(yes/no)
yes
Enter the transaction amount
850
Insufficient Balance
Your available balance 700.0

Q4: PROBLEM JDBC HARD

DISPLAY PRODUCTS BY CATEGORY


Display Products by Category
 
Write a program to retrieve list of products associated with the given item category from
the database.

Strictly adhere to the Object-Oriented specifications given in the problem statement. All class
names, attribute names and method names should be the same as specified in the problem
statement.
 
Consider the class ProdType with the following private attributes
 
Attributes  Datatype
id Long
name String
deposit Double
costPerDay Double
 
Consider the class Product with the following private member attributes
 
Attributes Datatype
id Long
name String
prodType ProdType
vendor String
 
The class declarations, getters, setters and constructors are available in the template
code.
 

Define the following method present in the ProdTypeDAO class


 
Method  Description
public List<ProdType> getAllProdTypes() This function finds all
records
of the
ProdType table and
returns the
ProdType
objects in a List.
 
Define the following method present in the ProductDAO class
 
Method  Description
This function accepts
category as an
argument
finds the records that
public List<Product>
match the
findProductsByCategory(String category)
given
category
returns the Product
objects in a List.
 
Consider the class DBConnection and define the following static method
Method Description
This method uses "oracle.properties" file as a resource file and
static Connection
gets connection object for the Oracle database and return the connection
getConnection()
object.
 

Consider the driver class Main. In the main method, display a List of objects in the given
format.

Table Structure:

CREATE TABLE Prod_Type(


id number(19) NOT NULL,
name varchar2(255) NOT NULL,
deposit BINARY_DOUBLE NOT NULL,
cost_per_day BINARY_DOUBLE NOT NULL,
PRIMARY KEY (id));
CREATE SEQUENCE prod_type_seq START WITH 1 INCREMENT BY 1;
 

CREATE  TABLE Product(


id number(19) NOT NULL,
name VARCHAR2(255) NOT NULL,
vendor VARCHAR2(255) NOT NULL,
type_id number(19) NULL,
foreign key(type_id) references Prod_type(id),
PRIMARY KEY (id));
CREATE SEQUENCE prod_seq START WITH 1 INCREMENT BY 1;
 
The following code snippet is provided to establish DBConnection:
 
import java.util.ResourceBundle;
ResourceBundle rb = ResourceBundle.getBundle("oracle");
String url = rb.getString("db.url");
String username = rb.getString("db.username");
String password = rb.getString("db.password");

oracle.properties:
 
db.url = jdbc:oracle:thin:@localhost:1521:xe
db.username = root
db.password = student
 
Note:
 Use System.out.format("%-5s %-15s %-12s %s\n","ID","Name","Deposit","Cost per day")  to
display ItemType details.
 Use System.out.format("%-5s %-15s %-12s %s\n","ID","Name","Prod Type","Vendor")  to
display Item details.
 All double values should be formatted to 1 decimal place.
 If the given item category doesn’t match with the existing item categories, then display
“No such category is present”.
 
[All text in bold corresponds to the input and rest corresponds to the output]
 
Sample Input and Output 1:
 
ID Name Deposit Cost per day
1 Food 50000.0 10000.0
2 Electronics 85000.0 15000.0
3 Fashion 36000.0 8000.0
4 Grooming 15000.0 5000.0
5 Books 20000.0 7500.0
Enter the category:
Food
ID Name Item Type  vendor
1 Chocolate Food Foodies Court
2 Lollypop Food Foodies Court
 
Sample Input and Output 2:
 
ID Name Deposit Cost per day
1 Food 50000.0 10000.0
2 Electronics 85000.0 15000.0
3 Fashion 36000.0 8000.0
4 Grooming 15000.0 5000.0
5 Books 20000.0 7500.0
Enter the category:
Mobiles
No such category is present

Code Snippet

DBConnection.java

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.util.ResourceBundle;

public class DBConnection {

public static Connection getConnection() throws ClassNotFoundException, SQLException {

ResourceBundle rb = ResourceBundle.getBundle("oracle");

String url = rb.getString("db.url");

String username = rb.getString("db.username");

String password = rb.getString("db.password");

//fill your code here

ProductDao.java

import java.util.ArrayList;

import java.util.List;

public class ProductDAO {

public List<User> getAllUser() {

List<Product> prodList = new ArrayList<Product>();


//fill your code here

return prodList;

public void insertDetails(User user) {

//fill your code here

Oracle.sql

CREATE TABLE Prod_Type(


id number(19) NOT NULL,
name varchar2(255) NOT NULL,
deposit BINARY_DOUBLE NOT NULL,
cost_per_day BINARY_DOUBLE NOT NULL,
PRIMARY KEY (id));
CREATE SEQUENCE prod_type_seq START WITH 1 INCREMENT BY 1;
 

CREATE  TABLE Product(


id number(19) NOT NULL,
name VARCHAR2(255) NOT NULL,
vendor VARCHAR2(255) NOT NULL,
type_id number(19) NULL,
foreign key(type_id) references Prod_type(id),
PRIMARY KEY (id));
CREATE SEQUENCE prod_seq START WITH 1 INCREMENT BY 1;

Insert the following data into prod_type tables


1 Food 50000.0 10000.0
2 Electronics 85000.0 15000.0
3 Fashion 36000.0 8000.0
4 Grooming 15000.0 5000.0
5 Books 20000.0 7500.0
Insert the following data into Product table
1 Chocolate Food Foodies Court
2 Lollypop Food Foodies Court
3. TV Electronics Whirlpool
4. The Girl Next Door Books Book Bay
Product.java

public class Product {


private Long id;
private String name;
ProdType prodtype;
private String vendor;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ProdType getProdtype() {
return prodtype;
}
public void setProdtype(ProdType prodtype) {
this.prodtype = prodtype;
}
public String getVendor() {
return vendor;
}
public void setVendor(String vendor) {
this.vendor = vendor;
}
public Product(Long id, String name, ProdType prodtype, String vendor) {
super();
this.id = id;
this.name = name;
this.prodtype = prodtype;
this.vendor = vendor;
}
@Override
public String toString() {
return "Product [id=" + id + ", name=" + name + ", prodtype=" + prodtype + ", vendor="
+ vendor + "]";
}
}

ProdType.java

public class ProdType {


private long id;
private String name;
private Double deposit;
private Double costPerDay;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getDeposit() {
return deposit;
}
public void setDeposit(Double deposit) {
this.deposit = deposit;
}
public Double getCostPerDay() {
return costPerDay;
}
public void setCostPerDay(Double costPerDay) {
this.costPerDay = costPerDay;
}
public ProdType(long id, String name, Double deposit, Double costPerDay) {
super();
this.id = id;
this.name = name;
this.deposit = deposit;
this.costPerDay = costPerDay;
}
@Override
public String toString() {
return "ProdType [id=" + id + ", name=" + name + ", deposit=" + deposit + ",
costPerDay=" + costPerDay + "]";
}
}

ProdTypeDAO.java

public class ProdTypeDAO {


public List<ProdType> getAllItemTypes(){
List<ProdType> itemTypeList =new ArrayList<ProdType>();
//your code goes here...
return itemTypeList;
}
}

Main.java

public class Main {

public static void main(String[] args){

//Your code here

You might also like