Skip to content

Commit

Permalink
Add relational model
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitra-karadima committed Dec 26, 2018
1 parent 7cd258c commit af97817
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 80 deletions.
Binary file modified Exceptions.class
Binary file not shown.
95 changes: 21 additions & 74 deletions Exceptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,13 @@ public void display(String x) {
* the above Exceptions are thrown
*/
public int outOfBoundsException(ArrayList<ArrayListLine>[] lists, int x1) {
int exitcode = 0;
int i = 0;
while (exitcode == 0) { // loops until none Exception is thrown
try {
i++;
if (i != 1) { // not entering the first time
try { // happens only if the argument throws ArrayIndexOutBoundsException
System.out.println("Try again!");
System.out.println(text);
@SuppressWarnings("resource")
Scanner input = new Scanner(System.in);
x1 = input.nextInt();
if (x1 <= lists.length & x1 > 0) {
exitcode = 1;
}
} catch (InputMismatchException e) {
System.out.println("Wrong type!");
exitcode = 0;
}
} else if (x1 <= lists.length & x1 > 0) { // checks the argument of the method
exitcode = 1;
}
} catch (ArrayIndexOutOfBoundsException e) {
exitcode = 0;
int exit = 0;
while (exit == 0) { // guarantees that ArrayOutOfBoundsException is not thrown
if (x1 > lists.length || x1 < 1) {
display("Please insert an positive integer and less than array length");
x1 = notIntegerException();
} else {
exit = 1;
}
}
return x1;
Expand All @@ -80,31 +63,13 @@ public int outOfBoundsException(ArrayList<ArrayListLine>[] lists, int x1) {
* get to second dimension of the array lists
*/
public int outOfBoundsException(ArrayList<ArrayListLine>[] lists, int x1, int list) {
int exitcode = 0;
int i = 0;
while (exitcode == 0) {
try {
if (i != 0) {
try {
System.out.println("Try again!");
System.out.println(text);
@SuppressWarnings("resource")
Scanner input = new Scanner(System.in);
x1 = input.nextInt();
if (x1 <= lists[list - 1].size() && x1 > 0) {
exitcode = 1;
}
} catch (InputMismatchException e) {
System.out.println("Wrong type!");
exitcode = 0;
}
}
i++;
if (x1 <= lists[list - 1].size() && x1 > 0) {
exitcode = 1;
}
} catch (ArrayIndexOutOfBoundsException e) {
exitcode = 0;
int exit = 0;
while (exit == 0) { // guarantees that ArrayOutOfBoundsException is not thrown
if (x1 > lists[list].size() || x1 < 1) {
display("Please insert an positive integer and less than array length");
x1 = notIntegerException();
} else {
exit = 1;
}
}
return x1;
Expand All @@ -115,31 +80,13 @@ public int outOfBoundsException(ArrayList<ArrayListLine>[] lists, int x1, int li
* to use the features for every list
*/
public int outOfBoundsException(int[] arrayNumberColumns, int x1, int list) {
int exitcode = 0;
int i = 0;
while (exitcode == 0) {
try {
if (i != 0) {
try {
System.out.println("Try again!");
System.out.println(text);
@SuppressWarnings("resource")
Scanner input = new Scanner(System.in);
x1 = input.nextInt();
if (x1 <= arrayNumberColumns[list - 1] && x1 > 0) {
exitcode = 1;
}
} catch (InputMismatchException e) {
System.out.println("Wrong type!");
exitcode = 0;
}
}
i++;
if (x1 <= arrayNumberColumns[list - 1] && x1 > 0) {
exitcode = 1;
}
} catch (ArrayIndexOutOfBoundsException e) {
exitcode = 0;
int exit = 0;
while (exit == 0) { // guarantees that ArrayOutOfBoundsException is not thrown
if (x1 > arrayNumberColumns[list] || x1 < 1) {
display("Please insert an positive integer and less than array length");
x1 = notIntegerException();
} else {
exit = 1;
}
}
return x1;
Expand Down
Binary file modified Functions.class
Binary file not shown.
9 changes: 3 additions & 6 deletions Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.io.PrintWriter;

import java.util.ArrayList;

import java.util.Scanner;

public class Functions {
Expand Down Expand Up @@ -48,8 +47,7 @@ public void addChoice(int[] arrayNumberColumns, String[][] names) {
ex.display("Enter number of table you wish to add a new object: ");
// method from exceptions called
int tableAdd = ex.notIntegerException();// guarantees that InputMismatchException is not thrown
tableAdd = ex.outOfBoundsException(lists, tableAdd);// guarantees that InputMismatchException or
//ArrayOutOfBoundsException is not thrown
tableAdd = ex.outOfBoundsException(lists, tableAdd);
String[] newObject = new String[arrayNumberColumns[tableAdd - 1]];
for (int i = 0; i < arrayNumberColumns[tableAdd - 1]; i++) {
System.out.print("Enter something for column " + names[tableAdd - 1][i] + ": ");
Expand All @@ -59,10 +57,9 @@ public void addChoice(int[] arrayNumberColumns, String[][] names) {
addLine(xx, tableAdd - 1);
}


/*
* Method that deletes an object(line)
*/
* Method that deletes an object(line)
*/
public void delete(int rem, int num) {
lists[num].remove(rem);
}
Expand Down

0 comments on commit af97817

Please sign in to comment.