Nothing Special   »   [go: up one dir, main page]

Assignment 05: Wednesday 05-12-2020 Warning

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

Department of Computer Science CSC-210:Object-Oriented Programming

Bahria University, Karachi Campus Semester 02 (Fall 2020)

ASSIGNMENT 05
Marks: 10

NAME : Muhammad Ashar Rashid

CLASS : BS(CS)-2B

REG. No. 67750

COURSE: CSC-210

COURSE CODE: OBJECT ORIENTED PROGRAMING

Read Carefully:
• The deadline for this assignment is before or on Wednesday 05-12-2020.

WARNING: This is an individual assignment; you must solve it by yourself. Any form of
plagiarism will result in receiving zero in the assignment.

WARNING: Late submission will not be accepted. Any assignment submitted after the cutoff
time will receive zero.

• This assignment has 02 questions that you have to perfrom in JAVA and submit the word file
on LMS

1|Page
CS Department, BUKC 2/4 Semester 2 (Fall 2020)
CSC-210: OOP Assignment 05

QUESTION NO. 1 (Class Relationship) (5 Marks)


Implement Java classes Lecturer and Income along with application class to acquire output given in
Figure 1. Calculate and display the Lecturer income based on the given output, UML and following
formulas.
 Tax= 2.5% x Income Amount
 Net Income= Total Income Amount – Total Taxes

INPUT FORMAT OUTPUT FORMAT


Enter Lecturer Name: Name: Sameena ID: P310
Sameena
Enter Lecturer ID: Income Income Amount Tax
P310
Salary 3000 75
Enter Income Type: Allowance 700 17.50
Salary Bonus 1000 25
Enter Income Amount:
3000
Total Income : 4700
Enter Allowance Type: Total Tax : 117.50
House Allowance Net Income : 4582.50
Enter Allowance Amount:
700

Enter other Income Name:


Bonus
Enter other Income Amount:
1000
Figure 1: Output of the Task
CS Department, BUKC 3/4 Semester 2 (Fall 2020)
CSC-210: OOP Assignment 05

Lecturer Income

- name: Stirng - incomeType: String


- id: String - amount: double
- income: Income[] - tax : double

+ Lecturer(name:String, +
id:String, income: Income(incomeType:String,
Income[]) amount:double, tax:
double)

+ getName():String
+ getId(): String + getIncomeType():String
+ + getAmount():double
calculateTotalIncome():doub + getTax():double
le
+
calculateNetIncome():double
+ displayIncomeInfo(): void

TestClass

+ main(args:
String[]):void

Figure 2: UML diagram


CS Department, BUKC 4/4 Semester 2 (Fall 2020)
CSC-210: OOP Assignment 05

QUESTION NO. 2 [5 Marks]

You are given the following UML diagram of a retail store:

Write a Java class Customer that contains the following attributes and methods:
 customerName: the name of customer
 customerAddress: the address of customer
 orderList[]: array of orders placed by the customer. Maximum of 20 orders
considered.
 nbOfOrders: the number of orders placed by the customer
 Customer(String, String): two argument constructor having name and address as its
arguments
 getCustomerName(): returns the customer name
 setCustomerName(): change the customer name
 addOrder(Order): can add orders into the orderList
 printOrders(): print out the customer and order details with total order cost

SOURCE CODE:

CUSTOM CLASS:
package assignment5;

public class Customer {

private String customerName, customerAddress;


private Order[] orderList = new Order[20];
private int nbOfOrder;

public Customer() {
CS Department, BUKC 5/4 Semester 2 (Fall 2020)
CSC-210: OOP Assignment 05

public Customer(String CN, String CA) {


this.customerName = CN;
this.customerAddress = CA;
}

public String getCustomerName() {


return customerName;
}

public void setCustomerName(String CN) {


this.customerName = CN;
}

public void addOrder(Order o) {


for (int i = 0; i < nbOfOrder; i++) {
Product p = null;
this.orderList[i].addProduct(p);
}
}

public void printOrders(){


System.out.println("Customer Name : "+getCustomerName());
System.out.println("Customer Address : "+this.customerAddress);
System.out.println("Number of Order : "+this.nbOfOrder);
Order o=null;
o.getOrderDetails();
}

ORDER CLASS:
package assignment5;

import java.util.ArrayList;

public class Order {

private int orderNumber, noOfProduct;


private String orderDate;
private ArrayList<Product> productList = new ArrayList<Product>();

public Order() {

public Order(int ON,String OD){


this.orderNumber = ON;
CS Department, BUKC 6/4 Semester 2 (Fall 2020)
CSC-210: OOP Assignment 05

this.orderDate = OD;
}

public int getOrderNumber() {


return orderNumber;
}

public void addProduct(Product p){


productList.add(p);
}

public double getTotalPrice(){


Product p = null;
double r= p.getProductPrice();

return r;
}

public void getOrderDetails(){


System.out.println("Order Number : "+getOrderNumber());
System.out.println("Order Date : "+this.orderDate);
System.out.println("Total Price : "+getTotalPrice());
}

Product Class :

package assignment5;

public class Product {


private String productName;
private double productPrice;

public Product(){

public Product(String PN,double PP){


this.productName=PN;
this.productPrice=PP;
}

public String getProductName() {


return productName;
}

public double getProductPrice() {


return productPrice;
}
CS Department, BUKC 7/4 Semester 2 (Fall 2020)
CSC-210: OOP Assignment 05

APPLICATION CLASS:

package application_class;

import assignment5.Customer;
import assignment5.Order;
import assignment5.Product;

public class Application_Class {

public static void main(String[] args) {

Customer cus = new Customer();


cus.getCustomerName();
cus.printOrders();
cus.setCustomerName("Ali");

Order or = new Order();


or.getOrderDetails();
or.getOrderNumber();
or.getTotalPrice();

Product pr = new Product();


pr.getProductName();
pr.getProductPrice();

You might also like