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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ private boolean filter(double a) {
}

private int findMin() {
//todo реализовать
return 0;
int index = 0;
do {
index++;
System.out.println(getA(index));
} while (!filter(getA(index)));
return index;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Table {
public Table(double start, double end, double step) {

if (end <= start)
throw new RuntimeException("End value shoult be bigger then start, but it's not.");
throw new RuntimeException("End value should be bigger then start, but it's not.");

this.start = start;
this.end = end;
Expand All @@ -27,8 +27,18 @@ static double function(double x) {
}

public double[][] getTable() {

//todo реализовать
return new double[0][0];
int ROWS = (int) (((end - start) / step + 1));
int COLUMNS = 2;
double[][] DataAndResult = new double[ROWS][COLUMNS];
for (int row = 0; row < ROWS; row += step) {
for (int column = 0; column < COLUMNS; column++) {
if (column == 0) {
DataAndResult[row][column] = row;
} else {
DataAndResult[row][column] = function(row);
}
}
}
return DataAndResult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,44 @@ private void printTable(int quantity, PrintStream out) {
}

private void printBottom(int quantity, PrintStream out) {
out.print("+-------------------------+");
}
out.print("+");
for (int i = 0; i < 2 * quantity + 3; i++){
out.print("-");
}
out.print("+");
}

private void printTop(int quantity, PrintStream out) {
out.println("+-------------------------+"); // TODO: Сделать ширину каждого заголовка равной quantity
out.println("| x | f(x) |");
out.println("+-------------------------+");
out.print("+");
for (int i = 0; i < 2 * quantity + 3; i++)
out.print("-");
out.print("+\n|");

for (int i = 0; i < 2 * quantity; i++){
if (i == quantity / 2){
out.print("x");
continue;
}
else if (i == quantity){
out.print("|");
continue;
}
else if (i == quantity + quantity / 2){
out.print("f(x)");
continue;
}
else out.print(" ");
}
out.print("|\n+");

for (int i = 0; i < 2 * quantity + 3; i++)
out.print("-");
out.println("+");
}

public static void main(String[] args) {
TablePrinter tp= new TablePrinter(0,10, 1);
tp.printTable(11);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.epam.courses.java.fundamentals.intro.practice.task4;

public class Main {
public static void main(String[] args) {
MaxFinder mf = new MaxFinder(1, 2, 3, 3, 4);
System.out.println(mf.getMaximum());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ public MaxFinder(double... as) {
}

public double getMaximum() {
//todo реализовать!
return 0;
double max;
if (as.length >= 2) {
max = as[0] + as[1];
} else {
max = as[0];
}
for (int i = 1; i <= as.length - 2; i++) {
if (max < as[i] + as[i + 1]) {
max = as[i] + as[i + 1];
}
}
return max;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ public CrossMatrix(int size) {
}

public boolean get(int x, int y) {
//todo: реализовать!
return false;
if (x == y || (size - 1) == (x + y) ) {
return true;
}
return false;
}

@Override
Expand All @@ -25,4 +27,9 @@ public String toString() {
}
return result;
}

public static void main(String[] args) {
CrossMatrix matrix = new CrossMatrix(7);
System.out.print(matrix.toString());
}
}
6 changes: 3 additions & 3 deletions intro/start.cmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
md target/classes
rem javac ...
rem java ...
md target\classes
javac -d target\classes src\main\java\com\epam\courses\java\fundamentals\intro\practice\task1\*
java -classpath target\classes com.epam.courses.java.fundamentals.intro.practice.task1.Main
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.epam.courses.java.fundamentals.oop.practice.task6;

import java.util.Arrays;

public class Main {
public static void main(String[] args) {
NotePad np = new NotePad();
np.addNote("0", "0");
np.addNote("1", "1");
np.addNote("2", "2");
np.addNote("3", "3");

System.out.println(Arrays.toString(np.getNotes()));
System.out.println("===================");
np.removeNote(1);
System.out.println(Arrays.toString(np.getNotes()));
System.out.println("===================");
np.removeNote(1);
System.out.println(Arrays.toString(np.getNotes()));
System.out.println("===================");
np.editNote(2, "6", "6");
System.out.println(Arrays.toString(np.getNotes()));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import lombok.experimental.NonFinal;

/**
* independent Object Note
*/
public class Note {

@NonFinal
Expand Down Expand Up @@ -51,8 +54,8 @@ public int hashCode() {
@Override
public String toString() {
return "Note{" + "title='" + title + '\'' +
", body='" + body + '\'' +
", id=" + id +
'}';
", body='" + body + '\'' +
", id=" + id +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.util.Arrays;
import lombok.experimental.NonFinal;

/**
* include Notes. Default capacity 16 or choose another size.
*/
public class NotePad {

private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
Expand All @@ -22,10 +25,41 @@ public NotePad() {
this(16);
}

/**
* addNote - create and add new Note or null
*
* @param title set Title
* @param body set Body
*/
public Note addNote(String title, String body) {
Note note = new Note(index++).setTitle(title).setBody(body);
return isPossibleToAdd() ? notes[note.getId()] = note :
null; // throw new RuntimeException("It`s impossible to add the Note - array already have a maximum size!");
null; // throw new RuntimeException("It`s impossible to add the Note - array already have a maximum size!");
}

/**
* remove Note and return null
*
* @param id using id for search
*/
public void removeNote(int id) {
if (getNote(id) != null) {
notes[id] = null;
} else System.out.println("It`s impossible to remove the Note with id = " + id);
}

/**
* editNote - changed Note or null-link
*
* @param id using id for search
* @param title set Title
* @param body set Body
*/
public void editNote(int id, String title, String body) {
if (id >= 0 && id < index) {
Note note = new Note(id).setTitle(title).setBody(body);
notes[id] = note;
} else System.out.println("It`s impossible to edit the Note with id = " + id);
}

private boolean isPossibleToAdd() {
Expand All @@ -52,6 +86,9 @@ public Note getNote(int id) {
return notes[id];
}

/**
* show allNotes
*/
public Note[] getNotes() {
return Arrays.copyOf(notes, index); // better then clone for that case: result haven`t null`s at his tail
}
Expand Down