Skip to content

Instantly share code, notes, and snippets.

@iamricard
Created April 25, 2013 14:55
Show Gist options
  • Save iamricard/5460331 to your computer and use it in GitHub Desktop.
Save iamricard/5460331 to your computer and use it in GitHub Desktop.
EXAMEN UF3
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class funciones {
private static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
public int how_many_times(String movies_array[][], String rent_array[][]) throws IOException {
String input,
movie_id = "";
int times = 0;
System.out.println("============= BRRRRR MOVIE-MATIC 1.0c ================");
System.out.println("PEPE GOTERAS SAYS: BEEP BEEP MOVIE NAME PLEASE");
System.out.print(">");
input = stdin.readLine();
System.out.println("============ PIP PIP PIP CALCULATING PIP =============");
for (byte i = 0; i < 6; i++) {
if (input.equals(movies_array[i][1])) {
movie_id = movies_array[i][0];
break;
}
}
for (byte i = 0; i < 16; i++) {
if (movie_id.equals(rent_array[i][0])) {
times++;
}
}
return times;
}
public String is_borrowed(String movies_array[][], String rent_array[][]) throws IOException {
String input,
movie_id = "",
day_borrow = "";
System.out.println("============= BRRRRR MOVIE-MATIC 1.0c ================");
System.out.println("PEPE GOTERAS SAYS: BEEP BEEP MOVIE NAME PLEASE");
System.out.print(">");
input = stdin.readLine();
System.out.println("============ PIP PIP PIP CALCULATING PIP =============");
for (byte i = 0; i < 6; i++) {
if (input.equals(movies_array[i][1])) {
movie_id = movies_array[i][0];
break;
}
}
for (byte i = 0; i < 16; i++) {
if (movie_id.equals(rent_array[i][0])) {
if (rent_array[i][3] == null) {
day_borrow = rent_array[i][2];
break;
}
else {
day_borrow = "returned";
}
}
}
return day_borrow;
}
public String[][] movies_borrowed(String rent_array[][], String movies_array[][], String clients_array[][]) throws IOException {
String input,
client_id = "",
client_name = "",
movie_id = "",
movie_name = "";
String datos [][] = new String[20][2];
byte count = 0;
System.out.println("============= BRRRRR MOVIE-MATIC 1.0c ================");
System.out.println("PEPE GOTERAS SAYS: BEEP BEEP DATE PLEASE!!!");
System.out.print(">");
input = stdin.readLine();
System.out.println("============ PIP PIP PIP CALCULATING PIP =============");
for (byte i = 0; i < 16; i++) {
if (input.equals(rent_array[i][2])) {
movie_id = rent_array[i][0];
client_id = rent_array[i][1];
for (byte j = 0; j < 5; j++) {
if (client_id.equals(clients_array[j][0])) {
client_name = clients_array[j][1];
}
}
for (byte j = 0; j < 6; j++) {
if (movie_id.equals(movies_array[j][0])) {
movie_name = movies_array[j][1];
}
}
datos[count][0] = client_name;
datos[count][1] = movie_name;
count++;
}
}
return datos;
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class menus {
private static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
public byte choice() throws IOException {
String input;
byte menu_c;
System.out.println("==== PEPE GOTERAS VIDEO CLUUUUUUUUUUUB SYSTEM ====");
System.out.println("==================================================");
System.out.println("1-HOW MANY TIMES WAS A MOVIE RENTED?\n\n2-IS THE MOVIE BORROWED OR FREE?\n\n3-MOVIES RENTED ON A GIVEN DAY? WHO?");
System.out.println("============== PEPE GOTERAS DONE! ================");
input = stdin.readLine();
menu_c = Byte.parseByte(input);
return menu_c;
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Calendar;
public class videoclub {
private static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
menus menu_fun = new menus();
funciones func_fun = new funciones();
String borrowed = "";
int times = 0,
day = 0;
byte choice;
String rent [][] = {{"0001","0002","20/06/2010","21/06/2010"}, //{MOVIE_ID, CLIENT_ID, RENT_DATE, RETURN_DATE}
{"0001","0003","28/08/2010","30/08/2010"},
{"0001","0004","20/10/2010","22/10/2010"},
{"0001","0001","30/11/2010","01/12/2010"},
{"0002","0002","20/2/2011","21/2/2011"},
{"0002","0003","10/2/2011","11/2/2011"},
{"0002","0004","13/4/2011","15/2/2011"},
{"0003","0001","25/02/2012","27/02/2012"},
{"0003","0002","18/08/2011",null},
{"0004","0001","25/02/2012","26/02/2012"},
{"0004","0003","03/03/2012","04/03/2012"},
{"0004","0004","06/04/2012","06/04/2012"},
{"0004","0005","09/04/2012",null},
{"0003","0003","18/04/2012","19/04/2012"},
{"0003","0004","23/04/2012","25/04/2012"},
{"0003","0001","28/05/2012","29/05/2012"}};
String movies [][] = {{"0001","Torrente","89","Comedia"}, // {MOVIE_ID, MOVIE_NAME, MOVIE_DURATION, MOVIE_CATEGORY}
{"0002","MiB","96","Ciencia ficción"},
{"0003","Jungla de cristal 4.0","102","Acción"},
{"0004","Los vengadores","126","Acción"},
{"0005","Los cachorros","86","Dibujos animados"},
{"0006","Harry Pencas","78","X"}};
String clients [][] = {{"0001","Daniel","Ramirez Lorca","Av Diagonal 34 3ro 2da","Barcelona","666777888"}, // {CLIENT_ID, CLIENT_NAME, CLIENT_LASTNAME, CLIENT_ADDRESS. CLIENT_TOWN, CLIENT_PHONE}
{"0002","Carmen","Soler Chorro","C/ Meridiana 157 6to 4ta","Barcelona","666888999"},
{"0003","Joan","Such i Llop","Av Europa 15 1ro 1ra","Mollet","666000111"},
{"0004","Oscar","Magriña Estivill","C/ Mallorca 67 2do 4ta","Mataro","666222333"},
{"0005","Rafa","Laguna Corripio","Plaça Virreina 3 1ro 3ra","Barcelona","666444555"}};
choice = menu_fun.choice();
switch (choice) {
case 1:
times = func_fun.how_many_times(movies, rent);
switch (times) {
case 0:
System.out.println("PEPE GOTERAS SAYS: NOT RENTED EVER!!!");
break;
default:
System.out.println("PEPE GOTERAS SAYS: RENTED "+times+" TIMES!!!");
break;
}
break;
case 2:
borrowed = func_fun.is_borrowed(movies, rent);
if (borrowed.equals("returned")) {
System.out.println("PEPITO GOTERAS SAYS: MOVIE AVAILABLE!!! RENT IT NOW!!!");
}
else {
String day_s,
rest_s;
System.out.println("PEPITO GOTERAS SAYS: MOVIE BORROWED !!!");
System.out.println("MOVIE BORROWED ON: "+borrowed);
day_s = borrowed.substring(0,2);
rest_s = borrowed.substring(2);
day = Integer.parseInt(day_s);
if (day == 29) {
day = -1;
}
else if (day == 30) {
day = 0;
}
day = day + 2;
System.out.println("MOVIE TO BE RETURNED ON: "+day+rest_s);
}
break;
case 3:
String[][] borrowed_array = func_fun.movies_borrowed(rent, movies, clients);
System.out.println(Arrays.deepToString(borrowed_array));
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment