Skip to content

Commit

Permalink
Add project
Browse files Browse the repository at this point in the history
  • Loading branch information
hoseinmrh committed Jul 14, 2022
1 parent b79c5db commit 60c4c69
Show file tree
Hide file tree
Showing 56 changed files with 1,530 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
38 changes: 38 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
plugins {
id 'com.android.application'
}

android {
compileSdk 32

defaultConfig {
applicationId "com.example.os_project"
minSdk 24
targetSdk 32
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.os_project;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.example.os_project", appContext.getPackageName());
}
}
29 changes: 29 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.os_project">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.OS_Project">
<activity
android:name=".Second"
android:exported="false" />
<activity
android:name=".First"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Binary file added app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
108 changes: 108 additions & 0 deletions app/src/main/java/com/example/os_project/C_LOOK.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.example.os_project;

import java.util.ArrayList;
import java.util.Collections;

public class C_LOOK {
private String direction;
private int max;
private int head_place;
private String name;
private ArrayList<Integer> disks = new ArrayList<Integer>();
private int moving_time;
public ArrayList<Integer> changing_disk = new ArrayList<Integer>();
public ArrayList<Integer> less_disks = new ArrayList<Integer>();
public ArrayList<Integer> big_disks = new ArrayList<Integer>();
public ArrayList<Integer> result = new ArrayList<Integer>();
public int time = 0;

public C_LOOK(String direction, int max, int head_place, String name, ArrayList<Integer> disks, int moving_time) {
this.direction = direction;
this.max = max;
this.head_place = head_place;
this.name = name;
this.disks = disks;
this.moving_time = moving_time;
}

public void copy_disk(){
this.changing_disk = this.disks;

}

public String print_result(){
String toPrint = "";
for(int i = 0; i < result.size(); i++){
if (i != result.size() -1)
toPrint = toPrint + String.valueOf(result.get(i)) + " -> ";
else{
toPrint = toPrint + String.valueOf(result.get(i));
}
}
return toPrint;

}

public int printTime() {
return time;
}

public void ascendingScan(){
int current_head = head_place;
for(int i = 0; i<big_disks.size(); i++){
time = time + moving_time*Math.abs(current_head - big_disks.get(i));
result.add(big_disks.get(i));
current_head = big_disks.get(i);
}
current_head = less_disks.get(0);
result.add(less_disks.get(0));

for(int j = 1; j < less_disks.size() ; j++){
time = time + moving_time*Math.abs(current_head - less_disks.get(j));
result.add(less_disks.get(j));
current_head = less_disks.get(j);
}

}

public void descendingScan(){
int current_head = head_place;
for(int j = less_disks.size()-1; j > -1; j--){
time = time + moving_time*Math.abs(current_head - less_disks.get(j));
result.add(less_disks.get(j));
current_head = less_disks.get(j);
}

current_head = big_disks.get(big_disks.size() - 1);
result.add(big_disks.get(big_disks.size() - 1));

for(int i = big_disks.size() - 2; i > -1; i--){
time = time + moving_time*Math.abs(current_head - big_disks.get(i));
result.add(big_disks.get(i));
current_head = big_disks.get(i);
}



}

public void algorithm(){
result.add(head_place);
copy_disk();
Collections.sort(changing_disk);
for(int i=0; i<changing_disk.size(); i++){
if (changing_disk.get(i) < head_place)
less_disks.add(changing_disk.get(i));
else{
big_disks.add(changing_disk.get(i));
}
}

if ((direction.toUpperCase()).equals("UP"))
ascendingScan();
else if((direction.toUpperCase()).equals("DOWN")){
descendingScan();
}

}
}
111 changes: 111 additions & 0 deletions app/src/main/java/com/example/os_project/C_SCAN.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.example.os_project;

import java.util.ArrayList;
import java.util.Collections;

public class C_SCAN {
private String direction;
private int max;
private int head_place;
private String name;
private ArrayList<Integer> disks = new ArrayList<Integer>();
private int moving_time;
public ArrayList<Integer> changing_disk = new ArrayList<Integer>();
public ArrayList<Integer> less_disks = new ArrayList<Integer>();
public ArrayList<Integer> big_disks = new ArrayList<Integer>();
public ArrayList<Integer> result = new ArrayList<Integer>();
public int time = 0;

public C_SCAN(String direction, int max, int head_place, String name, ArrayList<Integer> disks, int moving_time) {
this.direction = direction;
this.max = max;
this.head_place = head_place;
this.name = name;
this.disks = disks;
this.moving_time = moving_time;
}

public void copy_disk(){
this.changing_disk = this.disks;

}

public String print_result(){
String toPrint = "";
for(int i = 0; i < result.size(); i++){
if (i != result.size() -1)
toPrint = toPrint + String.valueOf(result.get(i)) + " -> ";
else{
toPrint = toPrint + String.valueOf(result.get(i));
}
}
return toPrint;

}

public int printTime() {
return time;
}

public void ascendingScan(){
int current_head = head_place;
for(int i = 0; i<big_disks.size(); i++){
time = time + moving_time*Math.abs(current_head - big_disks.get(i));
result.add(big_disks.get(i));
current_head = big_disks.get(i);
}
time = time + moving_time*Math.abs(current_head - (max - 1));
result.add(max - 1);
current_head = 0;
result.add(0);

for(int j = 0; j < less_disks.size() ; j++){
time = time + moving_time*Math.abs(current_head - less_disks.get(j));
result.add(less_disks.get(j));
current_head = less_disks.get(j);
}

}

public void descendingScan(){
int current_head = head_place;
for(int j = less_disks.size()-1; j > -1; j--){
time = time + moving_time*Math.abs(current_head - less_disks.get(j));
result.add(less_disks.get(j));
current_head = less_disks.get(j);
}
time = time + moving_time*Math.abs(current_head - 0);
result.add(0);
current_head = max - 1;
result.add(max-1);

for(int i = big_disks.size() - 1; i > -1; i--){
time = time + moving_time*Math.abs(current_head - big_disks.get(i));
result.add(big_disks.get(i));
current_head = big_disks.get(i);
}



}

public void algorithm(){
result.add(head_place);
copy_disk();
Collections.sort(changing_disk);
for(int i=0; i<changing_disk.size(); i++){
if (changing_disk.get(i) < head_place)
less_disks.add(changing_disk.get(i));
else{
big_disks.add(changing_disk.get(i));
}
}

if ((direction.toUpperCase()).equals("UP"))
ascendingScan();
else if((direction.toUpperCase()).equals("DOWN")){
descendingScan();
}

}
}
Loading

0 comments on commit 60c4c69

Please sign in to comment.