Semester Project - Assignment 3 & 4 .

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

COMSATS University Islamabad, Lahore Campus

Department of Computer Science

Assignment 3 & 4 – Semester Spring 2020


Course Title: Object Oriented Programming-Lab Course Code: CSC241 Credit Hours: 4(3
Course Instructor/s: Ms. Muntaha Iqbal Programme Name: BCE ,1)
Semester: 3rd Batch: FA19-BCE Session: B
Total Marks: 40 Obtained Marks: Date: December 23, 2020
Student’s Name: Eman Dar, Adnan Ahmad Reg. No. FA19-BCE-020, FA18-BCE-030
Important Instruction:

 Student is himself/herself responsible for successful submission.


 Submission deadline: January 02, 2021 at 11:59 pm

Question 1:
 Think about any management system, no need to develop an extensive system, you have to
implement simple functionality. For reference, example is given below
o Online Food Order (Customer End)
 First of all your program should display complete menu to user
 To place order, there should be complete list of food items with price
 In next step, customer will place order and provide his information for food
delivery
 Complete order information should be saved in database
 In last step customer should be able to see his bill
 First, you have to identify classes in your project and then instance variable and method for each
classes. Carefully think about access modifiers of instance variable and methods.
 Once you have identified your classes, you have to make detailed UML class diagram.
 To read and write data you have to use database connectivity
 No need to implement GUI.
 You program should handle all possible exceptions.
 You have to implement all OOP concepts in your project specifically encapsulation, inheritance,
polymorphism, abstraction and interfaces.

Submission Guideline:
 You have to submit a pdf file (project idea 40-50 words, UML diagram, your code of all
classes and screenshot of output) on cu-online.
 Upload you project folder in zip form on MS Teams.
 Submission deadline: January 02, 2021 at 11:59 pm
 Late submission will not be accepted
Project Idea:
A store that contains mainly soft drinks and food items is formed. It has a parent class
called items. Its subclass is known as food items and soft drinks. The added interface is called
CalculatebBill, which is called in the other classes. It is to be added in the main class about how
many items are to be entered in it whether which item; food items or soft drinks. Add the data
according to it. There are 2 tables made that the data is saved in the database.

Code:
package store;

public interface CalculateBill


{
double CalculateBill();
}

package store;

public class Items implements CalculateBill{

private double id;


private String name;

public Items() {
}

public Items(double id, String name) {


this.id = id;
this.name = name;

public double getId() {


return id;
}

public void setId(double id) {


this.id = id;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public double CalculateBill(){

return 0;
}
}

FoodItems:
package store;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

public class FoodItems extends Items{

private String flavour;


private double price;
private double quantity;

public FoodItems() {
}

public FoodItems(String flavour, double price, double quantity, double id, String name) {
super(id, name);
this.flavour = flavour;
this.price = price;
this.quantity = quantity;
}

public String getFlavour() {


return flavour;
}

public void setFlavour(String flavour) {


this.flavour = flavour;
}

public double getPrice() {


return price;
}

public void setPrice(double price) {


this.price = price;
}

public double getQuantity() {


return quantity;
}

public void setQuantity(double quantity) {


this.quantity = quantity;
}

public double CalculateBill() {

return getPrice()*getQuantity();

public void FoodItems() {


try{
String query = "insert into project.food_items(id,name,flavour,price,quantity,Total)
values(?,?,?,?,?,?)";
Connection con = DriverManager.getConnection("jdbc:mysql://localhost","root","ea23");
Statement stat = con.createStatement();
PreparedStatement ps = con.prepareStatement(query);
ps.setDouble(1,getId());
ps.setString(2,getName());
ps.setString(3,getFlavour());
ps.setDouble(4, getPrice());
ps.setDouble(5, getQuantity());

double bill = CalculateBill();


ps.setDouble(6, bill);
int count = ps.executeUpdate();
System.out.println(count+"Record added");
}catch(SQLException e){
System.out.println(e.getMessage());
}

}
}

SoftDrinks:
package store;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

public class SoftDrinks extends Items{

private String flavour;


private double price;
private double quantity;

public SoftDrinks() {
}

public SoftDrinks(String flavour, double price, double quantity, double id, String name) {
super(id, name);
this.flavour = flavour;
this.price = price;
this.quantity = quantity;
}

public String getFlavour() {


return flavour;
}

public void setFlavour(String flavour) {


this.flavour = flavour;
}

public double getPrice() {


return price;
}

public void setPrice(double price) {


this.price = price;
}

public double getQuantity() {


return quantity;
}

public void setQuantity(double quantity) {


this.quantity = quantity;
}

public double CalculateBill() {


return getPrice()*getQuantity();

public void SoftDrinks() {


try{
String query = "insert into project.soft_drinks(id,name,flavour,price,quantity,Total)
values(?,?,?,?,?,?)";
Connection con = DriverManager.getConnection("jdbc:mysql://localhost","root","ea23");
Statement stat = con.createStatement();
PreparedStatement ps = con.prepareStatement(query);
ps.setDouble(1,getId());
ps.setString(2,getName());
ps.setString(3,getFlavour());
ps.setDouble(4, getPrice());
ps.setDouble(5, getQuantity());

double bill = CalculateBill();


ps.setDouble(6, bill);
int count = ps.executeUpdate();
System.out.println(count+"Record added");
}catch(SQLException e){
System.out.println(e.getMessage());
}

Store:
package store;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Scanner;

public class Store {

public static void main(String[] args) {

try{
//Connection
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost","root" ,
"ea23");

Scanner i = new Scanner(System.in);


Scanner sc = new Scanner(System.in);
Scanner db = new Scanner(System.in);

System.out.println("Enter How Many Items You Want to Enter:");


int n = i.nextInt();

for(int x = 0; x < n; x++){

System.out.println("Select you want to enter food items of soft Drinks");


System.out.println("Enter 1 for food items and 2 for soft Drinks:");
int choice = i.nextInt();

if(choice==1){

System.out.println("Enter Food items ;");

System.out.println("Enter id:");
double id = db.nextDouble();

System.out.println("Enter Name:");
String name = sc.nextLine();

System.out.println("Enter Flavour:");
String flavour = sc.nextLine();

System.out.println("Enter Price:");
double price = db.nextDouble();

System.out.println("Enter Quantity:");
double quanity = db.nextDouble();

FoodItems food = new FoodItems();


food.setName(name);
food.setId(id);
food.setPrice(price);
food.setQuantity(quanity);
food.setFlavour(flavour);

food.FoodItems();
}

else{
System.out.println("Enter Food items ;");

System.out.println("Enter id:");
double id = db.nextDouble();

System.out.println("Enter Name:");
String name = sc.nextLine();

System.out.println("Enter Flavour:");
String flavour = sc.nextLine();

System.out.println("Enter Price:");
double price = db.nextDouble();

System.out.println("Enter Quantity:");
double quanity = db.nextDouble();

SoftDrinks soft = new SoftDrinks();


soft.setName(name);
soft.setId(id);
soft.setPrice(price);
soft.setQuantity(quanity);
soft.setFlavour(flavour);

soft.SoftDrinks();
}

}
}catch(SQLException e){
System.out.println(e.getMessage());
}
}
}
UML Diagram:
Screenshots of output:
DataBase Screenshots:

You might also like