Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Task-6 Travel Time Calculation/.DS_Store
Binary file not shown.
17 changes: 17 additions & 0 deletions Task-6 Travel Time Calculation/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Task6</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
81 changes: 81 additions & 0 deletions Task-6 Travel Time Calculation/Calculation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
* Calculation of the arrival time of Lorry
* @author Kavyapriya
*/
public class Calculation
{
int totalTime=0, remainingTime=0, holidays=0, days=0, currentDayRemaining=0;

LocalDateTime date;
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");

/**
* Constructor
* @param date Departure date
*/
public Calculation(LocalDateTime date)
{
this.date = date;
}

/**
* Check if a day is a holiday
* @param date The day to check
* @return true if it is a holiday || false if it is not a holiday
*/
boolean isHoliday(LocalDateTime date)
{
DayOfWeek day = date.getDayOfWeek();
int dayOfMonth = date.getDayOfMonth();
int month = date.getMonthValue();

return(day == DayOfWeek.SUNDAY
|| (day == DayOfWeek.SATURDAY && (dayOfMonth>7 && dayOfMonth<=15) )
|| (month == 1 && dayOfMonth ==1)
|| (month == 1 && dayOfMonth ==26)
|| (month == 8 && dayOfMonth ==15));
}

/**
* Calculate the arrival date and time
* @param distance Distance to be covered
* @param speed Speed of the Lorry
*/
void calculateArrivalTime(int distance,int speed){
totalTime = distance/speed;
remainingTime = totalTime % 8;

currentDayRemaining = 23 - date.getHour();

if(currentDayRemaining < 8)
{
System.out.println("\nStarting date and time is "+ date.plusDays(1).format(format));
}
else
{
System.out.println("\nStarting date and time is "+ date.format(format));
}

while((totalTime/8) > days)
{
date = date.plusDays(1);

if(isHoliday(date))
{
holidays++;
}
days++;
}

date = date.plusDays(days - holidays).plusHours(remainingTime);

System.out.println("Arrival date and time would be " + date.format(format));
}
}



87 changes: 87 additions & 0 deletions Task-6 Travel Time Calculation/Lorry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Scanner;

/**
* Lorry's Distance to be traveled, Speed of lorry, Start date and time of the journey are fetched from user and Calculation initiated
* @author Kavyapriya
*/
public class Lorry {
/**
* Get inputs like Distance to be traveled, Speed of lorry, Start date and time of the journey
* @param args not used
*/
public static void main(String[] args) {
int distance, speed;
LocalDate date;
LocalTime time;

try (Scanner sc = new Scanner(System.in);) {
//Distance to be traveled
while(true) {
System.out.print("\nEnter the distance to be covered in kms : ");
try {
distance = Integer.parseInt(sc.next());
if(distance==0) {
System.out.print("Destination can't be as same as the arrival spot !.. ");
}else if(distance<0) {
System.out.print("Distance can't be negative !... ");
}else {
break;
}
System.out.println("Please enter a valid distance!..");
}catch(NumberFormatException e) {
System.out.println("Please enter the appropriate distance in numbers!..");
}
}

//Speed of the lorry
while(true) {
System.out.print("\nEnter the speed of lorry in kmph : ");
try {
speed = Integer.parseInt(sc.next());
if(speed==0) {
System.out.print("Speed must have some value!.. ");
}else if(speed<0) {
System.out.print("Speed can't be negative!.. ");
}else {
break;
}
System.out.println("Please enter a valid speed!..");
}catch(NumberFormatException e) {
System.out.println("Please enter the appropriate speed in numbers!..");
}
}

//Start date of the journey
while(true) {
System.out.print("\nEnter the travel start date in yyyy-mm-dd : ");
try {
date = LocalDate.parse(sc.next());
break;
}catch(Exception e) {
System.out.println("Please Enter the appropriate date in yyyy-mm-dd format !...");
}
}

//End date of the journey
while(true) {
System.out.print("\nEnter the travel start time in hh:mm (24hours format) : ");
try {
time = LocalTime.parse(sc.next());
break;
}catch(Exception e) {
System.out.println("Please Enter the appropriate time in hh:mm format !...");
}
}

LocalDateTime dateTime = LocalDateTime.parse(date + "T" + time);
Calculation destination = new Calculation(dateTime);
destination.calculateArrivalTime(distance, speed);

} catch (Exception e) {
System.out.println(e);
}
}
}
157 changes: 157 additions & 0 deletions Task-6 Travel Time Calculation/doc/Calculation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<!-- Generated by javadoc (19) on Sun Mar 26 02:38:22 IST 2023 -->
<title>Calculation</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2023-03-26">
<meta name="description" content="declaration: class: Calculation">
<meta name="generator" content="javadoc/ClassWriterImpl">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="script-dir/jquery-ui.min.css" title="Style">
<link rel="stylesheet" type="text/css" href="jquery-ui.overrides.css" title="Style">
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="script-dir/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="script-dir/jquery-ui.min.js"></script>
</head>
<body class="class-declaration-page">
<script type="text/javascript">var pathtoroot = "./";
loadScripts(document, 'script');</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<div class="flex-box">
<header role="banner" class="flex-header">
<nav role="navigation">
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="top-nav" id="navbar-top"><button id="navbar-toggle-button" aria-controls="navbar-top" aria-expanded="false" aria-label="Toggle navigation links"><span class="nav-bar-toggle-icon">&nbsp;</span><span class="nav-bar-toggle-icon">&nbsp;</span><span class="nav-bar-toggle-icon">&nbsp;</span></button>
<div class="skip-nav"><a href="#skip-navbar-top" title="Skip navigation links">Skip navigation links</a></div>
<ul id="navbar-top-firstrow" class="nav-list" title="Navigation">
<li><a href="package-summary.html">Package</a></li>
<li class="nav-bar-cell1-rev">Class</li>
<li><a href="class-use/Calculation.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="index-files/index-1.html">Index</a></li>
<li><a href="help-doc.html#class">Help</a></li>
</ul>
<ul class="sub-nav-list-small">
<li>
<p>Summary:</p>
<ul>
<li>Nested</li>
<li>Field</li>
<li><a href="#constructor-summary">Constr</a></li>
<li><a href="#method-summary">Method</a></li>
</ul>
</li>
<li>
<p>Detail:</p>
<ul>
<li>Field</li>
<li><a href="#constructor-detail">Constr</a></li>
<li>Method</li>
</ul>
</li>
</ul>
</div>
<div class="sub-nav">
<div id="navbar-sub-list">
<ul class="sub-nav-list">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor-summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method-summary">Method</a></li>
</ul>
<ul class="sub-nav-list">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor-detail">Constr</a>&nbsp;|&nbsp;</li>
<li>Method</li>
</ul>
</div>
<div class="nav-list-search"><a href="search.html">SEARCH</a>
<input type="text" id="search-input" disabled placeholder="Search">
<input type="reset" id="reset-button" disabled value="reset">
</div>
</div>
<!-- ========= END OF TOP NAVBAR ========= -->
<span class="skip-nav" id="skip-navbar-top"></span></nav>
</header>
<div class="flex-content">
<main role="main">
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<h1 title="Class Calculation" class="title">Class Calculation</h1>
</div>
<div class="inheritance" title="Inheritance Tree"><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">java.lang.Object</a>
<div class="inheritance">Calculation</div>
</div>
<section class="class-description" id="class-description">
<hr>
<div class="type-signature"><span class="modifiers">public class </span><span class="element-name type-name-label">Calculation</span>
<span class="extends-implements">extends <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a></span></div>
<div class="block">Calculation of the arrival time of Lorry</div>
<dl class="notes">
<dt>Author:</dt>
<dd>Kavyapriya</dd>
</dl>
</section>
<section class="summary">
<ul class="summary-list">
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<li>
<section class="constructor-summary" id="constructor-summary">
<h2>Constructor Summary</h2>
<div class="caption"><span>Constructors</span></div>
<div class="summary-table two-column-summary">
<div class="table-header col-first">Constructor</div>
<div class="table-header col-last">Description</div>
<div class="col-constructor-name even-row-color"><code><a href="#%3Cinit%3E(java.time.LocalDateTime)" class="member-name-link">Calculation</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalDateTime.html" title="class or interface in java.time" class="external-link">LocalDateTime</a>&nbsp;date)</code></div>
<div class="col-last even-row-color">
<div class="block">Constructor</div>
</div>
</div>
</section>
</li>
<!-- ========== METHOD SUMMARY =========== -->
<li>
<section class="method-summary" id="method-summary">
<h2>Method Summary</h2>
<div class="inherited-list">
<h3 id="methods-inherited-from-class-java.lang.Object">Methods inherited from class&nbsp;java.lang.<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a></h3>
<code><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#equals(java.lang.Object)" title="class or interface in java.lang" class="external-link">equals</a>, <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#getClass()" title="class or interface in java.lang" class="external-link">getClass</a>, <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#hashCode()" title="class or interface in java.lang" class="external-link">hashCode</a>, <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#notify()" title="class or interface in java.lang" class="external-link">notify</a>, <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#notifyAll()" title="class or interface in java.lang" class="external-link">notifyAll</a>, <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#toString()" title="class or interface in java.lang" class="external-link">toString</a>, <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#wait()" title="class or interface in java.lang" class="external-link">wait</a>, <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#wait(long)" title="class or interface in java.lang" class="external-link">wait</a>, <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#wait(long,int)" title="class or interface in java.lang" class="external-link">wait</a></code></div>
</section>
</li>
</ul>
</section>
<section class="details">
<ul class="details-list">
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<li>
<section class="constructor-details" id="constructor-detail">
<h2>Constructor Details</h2>
<ul class="member-list">
<li>
<section class="detail" id="&lt;init&gt;(java.time.LocalDateTime)">
<h3>Calculation</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="element-name">Calculation</span><wbr><span class="parameters">(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalDateTime.html" title="class or interface in java.time" class="external-link">LocalDateTime</a>&nbsp;date)</span></div>
<div class="block">Constructor</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>date</code> - Departure date</dd>
</dl>
</section>
</li>
</ul>
</section>
</li>
</ul>
</section>
<!-- ========= END OF CLASS DATA ========= -->
</main>
</div>
</div>
</body>
</html>
Loading