[go: up one dir, main page]

0% found this document useful (0 votes)
34 views7 pages

PIZZA HUT Assignment Part 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views7 pages

PIZZA HUT Assignment Part 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

PIZZA HUT- JAVA INCREMENTAL ASSIGNMENT

Programming Foundations: Core Java Incremental Assignment – Part 2


Interfaces
Create an Interface Deliverable in com.pune.pizzahut package having following
data
deliveryAreaLimit int(Eg.2 km where home delivery is available)
Define a method Boolean delivery()

Create a class Order implementing Deliverable with following private variables


and methods
orderNo int
orderDate Date
cost int
custName String
custAddress String
approxDistance int
Define parameterized constructor to initialize all variables.
Override delivery() to define the delivery mode. Method returns true if
approx.distance matches with the deliveryAreaLimit. Else display a message
“Home Delivery not available for this distance.

Create a class Reception having main method and perform following functionality
in it
Accept values from user to create an order object with appropriate values
Reply to the user request by calling delivery() method i.e. whether order is
deliveriable or not.
Solution:
let's break down the steps to create the requested Java classes and interface.
1. Create the Interface Deliverable:
// File: com/pune/pizzahut/Deliverable.java
package com.pune.pizzahut;

public interface Deliverable {


int deliveryAreaLimit = 0; // Default value, can be set in implementing classes
boolean delivery();
}

2. Create the Class Order implementing Deliverable:


// File: com/pune/pizzahut/Order.java
package com.pune.pizzahut;

import java.util.Date;

public class Order implements Deliverable {


private int orderNo;
private Date orderDate;
private int cost;
private String custName;
private String custAddress;
private int approxDistance;

// Parameterized constructor to initialize all variables


public Order(int orderNo, Date orderDate, int cost, String custName, String
custAddress, int approxDistance) {
this.orderNo = orderNo;
this.orderDate = orderDate;
this.cost = cost;
this.custName = custName;
this.custAddress = custAddress;
this.approxDistance = approxDistance;
}

// Override delivery() method


@Override
public boolean delivery() {
if (approxDistance <= deliveryAreaLimit) {
return true;
} else {
System.out.println("Home Delivery not available for this distance.");
return false;
}
}
}

3. Create the Class Reception with the main method:


// File: com/pune/pizzahut/Reception.java
package com.pune.pizzahut;

import java.util.Date;
import java.util.Scanner;
public class Reception {
public static void main(String[] args) {
// Accept values from the user to create an Order object
Scanner scanner = new Scanner(System.in);
System.out.print("Enter Order No: ");
int orderNo = scanner.nextInt();

System.out.print("Enter Order Date (in milliseconds): ");


long orderDateMillis = scanner.nextLong();
Date orderDate = new Date(orderDateMillis);

System.out.print("Enter Cost: ");


int cost = scanner.nextInt();

scanner.nextLine(); // Consume the newline character


System.out.print("Enter Customer Name: ");
String custName = scanner.nextLine();

System.out.print("Enter Customer Address: ");


String custAddress = scanner.nextLine();

System.out.print("Enter Approximate Distance: ");


int approxDistance = scanner.nextInt();

// Create an Order object with user-provided values


Order order = new Order(orderNo, orderDate, cost, custName, custAddress,
approxDistance);
// Reply to the user request by calling the delivery() method
boolean isDeliverable = order.delivery();
if (isDeliverable) {
System.out.println("Your order is deliverable!");
} else {
System.out.println("Sorry, your order cannot be delivered.");
}
} }
4. Compile and Run the Program:
 Save each of the above code snippets in their respective files with the
specified package structure.
 Compile the files using the javac command in the terminal or command
prompt.
javac com/pune/pizzahut/Deliverable.java
javac com/pune/pizzahut/Order.java
javac com/pune/pizzahut/Reception.java
 Run the program using the java command.
java com.pune.pizzahut.Reception
Example Input and Output:
Sample Input:
Enter Order No: 101
Enter Order Date (in milliseconds): 1637347200000
Enter Cost: 1500
Enter Customer Name: John Doe
Enter Customer Address: 123 Main St
Enter Approximate Distance: 3
Sample Output:
Home Delivery not available for this distance.
Sorry, your order cannot be delivered.
Exception Handling
Create a class InvalidPizzaTypeException and InvalidPizzaSizeException which will be
user defined exception.
 Modify Pizza class created in previous day assignment as bellow
 In case validation for type fails in constructor, throw a user defined checked
exception called InvalidPizzaTypeException.
 In case validation for size of pizza fails, throw a user defined checked exception
calledInvalidPizzaSizeException.
Handle these exceptions in main.
Create a class Bill with following private variables and methods
billNo int
custName String
date Date
total int
items String[]
Create getters and setters for all of the variables.
Create a class BillReports with following private variables and public methods
Bill bills[]i.e. array of type bill
Define methods as follows
void addBill(Bill) method to add bill object into an array
booleanupdateBill(billNo,newTotal) accepts billNo and modifies the total of
particular bill, returns true if successfully updated
Bill[] getBills()return an array of type Bill
Bill search Bill(billNo) accepts bill no and returns details of Bill
 In searching,in case Bill is not found in array throw user defined exception
BillNotFoundException. Handle this exception in main.
Create a class Reports having main method with following functionality
1. Accept values from user and create object of Bill.
2. Store objects into array of BillReports class by using addBill() method.
3. Print details of an array by using getBills() method.
4. Accept billNo from the user along with modified bill amount. Find corresponding
bill in array and update the amount. Print updated details. Use updateBill()for
achieving this.
5. Accept billNo from the user and print details of bill. Use serachBill() method for
achieving this.

You might also like