Skip to content

Commit

Permalink
Pranesh
Browse files Browse the repository at this point in the history
Added map functionality and implemented airdrop.
Abstract class
Overridden method
Packages and
Exception handling (can improve).
  • Loading branch information
Pranesh2002 authored Nov 21, 2022
1 parent 60d71ad commit b491bd2
Show file tree
Hide file tree
Showing 34 changed files with 1,595 additions and 0 deletions.
18 changes: 18 additions & 0 deletions map/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Getting Started

Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.

## Folder Structure

The workspace contains two folders by default, where:

- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies

Meanwhile, the compiled output files will be generated in the `bin` folder by default.

> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management

The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
Binary file added map/bin/App.class
Binary file not shown.
Binary file added map/bin/airdrop.class
Binary file not shown.
Binary file added map/bin/basicmap.class
Binary file not shown.
Binary file added map/bin/electricpower.class
Binary file not shown.
Binary file added map/bin/enemybase.class
Binary file not shown.
Binary file added map/bin/enemyhotspot.class
Binary file not shown.
Binary file added map/bin/fuel.class
Binary file not shown.
Binary file added map/bin/location.class
Binary file not shown.
Binary file added map/bin/safelocation.class
Binary file not shown.
Binary file added map/bin/time.class
Binary file not shown.
Binary file added map/bin/waterresources.class
Binary file not shown.
Binary file added map/src/App.class
Binary file not shown.
90 changes: 90 additions & 0 deletions map/src/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
class airdrop {
location airdroptt(location troop)
{
basicmap safe=new safelocation();
location l=new location();
l=safe.nearestlocation(troop);
System.out.printf("The package will arrive at (%d,%d).\n", l.la,l.lo);
time t= new time();
t= gettime(l);
basicmap enemy=new enemyhotspot();
System.out.printf("Local map of enemy hotspot:\n");
enemy.localmap(l);
return l;
}
time gettime(location l)
{
// set time now
time t= new time();
double distance=0; // in m
distance = Math.sqrt(((l.la-50)*(l.la-50)+(l.lo-50)*(l.lo-50))*10000); // scale *1000 m 1 km
double speed=100; //in mps
double totalseconds=distance/speed; //s
int hours = (int)totalseconds / 3600;
int minutes = (int)(totalseconds % 3600) / 60;
int seconds = (int)totalseconds % 60;
System.out.printf("The package will reach the destination at : %02d:%02d:%02d (hh:mm:ss)\n", hours, minutes, seconds);
t.hours=hours;
t.minutes=minutes;
t.seconds=seconds;
return t;
}
}
public class App {
public static void main(String[] args) throws Exception {


location troop=new location(25,25);
location l=new location(15,15);
basicmap enemy=new enemyhotspot();
basicmap safelocation=new safelocation();
basicmap electricity=new electricpower();
basicmap fuel=new fuel();
basicmap water=new waterresources();
airdrop adp=new airdrop();
time t=new time();

// enemy.setlocation(troop,0);
// enemy.printmap();
// enemy.localmap(troop);
// l=enemy.nearestlocation(troop);
// l.printlocation();

// adp.airdroptt(troop);

// safelocation.setlocation(troop,1);
// safelocation.printmap();
// safelocation.localmap(troop);
// l=safelocation.nearestlocation(troop);
// l.printlocation();

// electricity.setlocation(troop,3);
// electricity.printmap();
// electricity.localmap(troop);
// l=electricity.nearestlocation(troop);
// l.printlocation();

// fuel.setlocation(troop,3);
// fuel.printmap();
// fuel.localmap(troop);
// l=fuel.nearestlocation(troop);
// l.printlocation();

// fuel.setlocation(troop,3);
// fuel.printmap();
// fuel.localmap(troop);
// l=fuel.nearestlocation(troop);
// l.printlocation();

// water.setlocation(troop,3);
// water.printmap();
// water.localmap(troop);
// l=water.nearestlocation(troop);
// l.printlocation();

basicmap enemybase=new enemybase();
enemybase.printmap();
l=enemybase.nearestlocation(troop);
l.printlocation();
}
}
Binary file added map/src/airdrop.class
Binary file not shown.
37 changes: 37 additions & 0 deletions map/src/airdrop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
public class airdrop {
location airdroptt(location troop)
{
safelocation s=new safelocation();
location l=new location();
l=s.nearestlocation(troop);
System.out.printf("The package will arrive at (%d,%d).\n", l.la,l.lo);
time t= new time();
t= gettime(l);
enemyhotspot e=new enemyhotspot();
System.out.printf("Local map of enemy hotspot:\n");
e.localmap(l);
return l;
}
time gettime(location l)
{
// set time now
time t= new time();
double distance=0; // in m
distance = Math.sqrt(((l.la-50)*(l.la-50)+(l.lo-50)*(l.lo-50))*10000); // scale *1000 m 1 km
double speed=100; //in mps
double totalseconds=0; //s

try{
totalseconds=distance/speed; //s
}catch(ArithmeticException e){System.out.println(e);}

int hours = (int)totalseconds / 3600;
int minutes = (int)(totalseconds % 3600) / 60;
int seconds = (int)totalseconds % 60;
System.out.printf("The package will reach the destination at : %02d:%02d:%02d (hh:mm:ss)\n", hours, minutes, seconds);
t.hours=hours;
t.minutes=minutes;
t.seconds=seconds;
return t;
}
}
Binary file added map/src/basicmap.class
Binary file not shown.
17 changes: 17 additions & 0 deletions map/src/basicmap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public abstract class basicmap{ // all maps are of size 100*50 from (0 to 99) and (0 to 49)
int[][] basicmap=new int[100][50];
basicmap()
{
for(int i=0;i<50;i++)
{
for(int j=0;j<100;j++)
{
basicmap[j][i]=0;
}
}
}
abstract void setlocation(location l,int radius);
abstract void printmap();
abstract void localmap(location l);
abstract location nearestlocation(location l);
}
Binary file added map/src/electricpower.class
Binary file not shown.
Loading

0 comments on commit b491bd2

Please sign in to comment.