Merge pull request #24 from TiagoRG/dev-tiagorg

POO aula03; removed poo/datafiles and poo/out; some minor changes
This commit is contained in:
Tiago Garcia 2023-02-25 15:29:59 +00:00 committed by GitHub
commit 6cb26d089a
Signed by untrusted user who does not match committer: TiagoRG
GPG Key ID: DFCD48E3F420DB42
46 changed files with 264 additions and 83 deletions

View File

@ -1,4 +1,6 @@
def isPrime(n):
if n == 1:
return False
for x in range(2, n):
if n % x == 0:
return False

View File

@ -1,8 +1,8 @@
# Laboratório de Informática
## Aula 01
# Laboratórios de Sistemas Digitais
## Trabalho prático 01
### Tópico principal da aula: Introdução às FPGAs
* [Slides](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/lsd/aula01/LSD_2022-23_AulaTP01.pdf)
* [Slides](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/lsd/slides/LSD_2022-23_AulaTP01.pdf)
* [Guião](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/lsd/aula01/LSD_2022-23_TrabPrat01-2.pdf)
---

Binary file not shown.

View File

@ -6,10 +6,8 @@
## Organização do diretório
* [src](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src) • Código fonte das aulas/projetos
* [out](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/out) • Output da compilação da [src](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src)
* [guides](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/guides) • Guiões das aulas práticas
* [slides](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/slides) • Slides das aulas teóricas
* [datafiles](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/datafiles) • Ficheiros extra com texto/dados
---
## Índice
@ -17,6 +15,7 @@
|-----------------------------------------------------------------------------------------|----------------------|
| [01](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src/aula01) | Introduction, Basics |
| [02](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src/aula02) | Flux Control |
| [03](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src/aula03) | Classes |
---
*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new)

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -1,6 +0,0 @@
# Programação Orientada a Objetos
## Código fonte para as diversas aulas de POO
### Métodos extra no diretório [*utils*](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src/utils)
---
*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new)

View File

@ -1,9 +0,0 @@
# Programação Orientada a Objetos
## Aula 01
### Tópico principal da aula: Introduction, Basics
* [Guião](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/guides/POO-2021-aula01.pdf)
* [Slides](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/slides/POO_01_Introdução.pdf)
---
*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new)

View File

@ -1,18 +0,0 @@
# Programação Orientada a Objetos
## Aula 02
### Tópico principal da aula: Flux Control
* [Guião](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/guides/POO-2021-aula02.pdf)
* [Slides](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/slides/POO_02_ControloFluxo.pdf)
### Exercise List
| Exercise Number | File Name | Exercise Number | File Name |
|-----------------|----------------------------------------------------------------------------------------------------------------------------------------|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| 1 | [KmToMiles.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/KmToMiles.java) | 6 | [SecsToHMS.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/SecsToHMS.java) |
| 2 | [CelciusToFahrenheit.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/CelciusToFahrenheit.java) | 7 | [DistanceBetweenPoints.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/DistanceBetweenPoints.java) |
| 3 | [EnergyToHeatWater.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/EnergyToHeatWater.java) | 8 | [PythagoreanTheorem.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/PythagoreanTheorem.java) |
| 4 | [Investment.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/Investment.java) | 9 | [Countdown.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/Countdown.java) |
| 5 | [AverageSpeed.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/AverageSpeed.java) | 10 | [RealNumbers.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula02/RealNumbers.java) |
---
*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new)

View File

@ -1,6 +0,0 @@
# Programação Orientada a Objetos
## Exercícios TP
### Resoluções para exercícios sugeridos nas aulas Teórico-Práticas
---
*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new)

View File

@ -1,23 +0,0 @@
# Exercícios de Arrays
## Ex1
```java
final int LENGHT = 100;
int[] a = new int[LENGHT];
// Code for filling a ommited
for (int = 99; i >= 0; i--)
{
System.out.print(a[i]);
if (i > 0) { System.out.print(', '); }
}
```
## Ex2
```java
int[] numbers = new int[100];
for (int k = 0; k < numbers.length; k++)
{
numbers[k] = k + 1;
}
```

View File

@ -1,9 +0,0 @@
# Tabela Exercício 1 de Strings
| Question | Answer |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------|
| What is the length of the string below?<br>String str = "Java Program" | 12 |
| With str as defined above, give a call to the substring method that returns the substring "gram". | str.substring(8) |
| Use the string concatenation operator to change the string variable str to contain the string "Java Programming". | str += "ming" |
| What does the following statement sequence print?<br><br>String str = "Harry";<br>int n = str.length();<br>String mystery = str.substring(0, 1) + str.substring(n - 1, n);<br>System.out.println(mystery); | Hy |
| Consider the following statement sequence. If the user provides the input John Q. Public, what is printed? If an error occurs, type error.<br><br>Scanner in = new Scanner(System.in);<br>String first = in.next();<br>String last = in.next();<br>System.out.println(last + ", " + first); | Q., John |

Binary file not shown.

View File

@ -2,5 +2,12 @@
## Código fonte para as diversas aulas de POO
### Métodos extra no diretório [*utils*](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src/utils)
## Índice
| Aula nº | Tópicos |
|-----------------------------------------------------------------------------------------|----------------------|
| [01](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src/aula01) | Introduction, Basics |
| [02](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src/aula02) | Flux Control |
| [03](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src/aula03) | Classes |
---
*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new)

View File

@ -3,7 +3,8 @@
### Tópico principal da aula: Flux Control
* [Guião](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/guides/POO-2021-aula02.pdf)
* [Slides](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/slides/POO_02_ControloFluxo.pdf)
* [Slides 1](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/slides/POO_02_ControloFluxo.pdf)
* [Slides 2](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/slides/POO_02_Modularidade_MetodosEstaticos.pdf)
### Exercise List
| Exercise Number | File Name | Exercise Number | File Name |

View File

@ -16,17 +16,16 @@ public class RealNumbers {
double min = first;
double sum = first;
while (true) {
double n = sin.nextDouble();
if (n == first)
break;
double n;
do {
n = sin.nextDouble();
if (n > max)
max = n;
if (n < min)
min = n;
sum += n;
++readNumbers;
}
} while (n != first);
System.out.printf("Valor máximo: %f\nValor mínimo: %f\nMédia: %f\nTotal: %f\n", max, min, (float) sum/readNumbers, sum);

View File

@ -0,0 +1,81 @@
package aula03;
import utils.UserInput;
import java.util.Scanner;
// Solução do exercício 5
public class Calendar {
public static void main(String[] args) {
// Data contains: {month, year, firstDay}
int[] data = getValues();
int monthDays = monthDays(data[0], data[1]);
printCalendar(data, monthDays);
System.out.println();
}
private static int[] getValues() {
Scanner sin = new Scanner(System.in);
System.out.print("Introduza o mês/ano no formato mm/yyyy: ");
String[] monthYear = sin.next().split("/");
System.out.print("1 = Segunda\n2 = Terça\n3 = Quarta\n4 = Quinta\n5 = Sexta\n6 = Sábado\n7 = Domingo\nIntroduza o dia da semana em que começa o mês (1 a 7): ");
int firstDay = (int) UserInput.getNumberBetween(sin, 1, 7);
sin.close();
return new int[]{Integer.parseInt(monthYear[0]), Integer.parseInt(monthYear[1]), firstDay};
}
private static int monthDays(int month, int year) {
switch (month) {
case 2:
if (year % 100 == 0 ? year % 400 == 0 : year % 4 == 0)
return 29;
else
return 28;
case 4:
case 6:
case 9:
case 11:
return 30;
default:
return 31;
}
}
private static void printCalendar(int[] data, int monthDays) {
System.out.printf("\n%13s %d\n", monthName(data[0]), data[1]);
System.out.println("Dom Seg Ter Qua Qui Sex Sab");
if (data[2] != 7)
for (int i = 0; i < data[2]; i++)
System.out.print(" ");
for (int monthDay = 1; monthDay <= monthDays; monthDay++) {
System.out.printf("%3d ", monthDay);
if ((monthDay + data[2]) % 7 == 0)
System.out.println();
}
}
private static String monthName(int month) {
/* Note that this does not work in codecheck.
In codecheck use the usual switch case.
*/
return switch (month) {
case 1 -> "Janeiro";
case 2 -> "Fevereiro";
case 3 -> "Março";
case 4 -> "Abril";
case 5 -> "Maio";
case 6 -> "Junho";
case 7 -> "Julho";
case 8 -> "Agosto";
case 9 -> "Setembro";
case 10 -> "Outubro";
case 11 -> "Novembro";
default -> "Dezembro";
};
}
}

View File

@ -0,0 +1,46 @@
package aula03;
import java.util.Scanner;
import utils.UserInput;
// Solução do exercício 4
public class Grades {
private static final Scanner sin = new Scanner(System.in);
public static void main(String[] args) {
System.out.print("Quantos alunos tem a turma? ");
int studentCount = sin.nextInt();
Student[] students = new Student[studentCount];
for (int i = 0; i < studentCount; i++) {
System.out.printf("Nota teórica do aluno %d: ", i+1);
double notaT = UserInput.getNumberBetween(sin, 0, 20);
System.out.printf("Nota prática do aluno %d: ", i+1);
double notaP = UserInput.getNumberBetween(sin, 0, 20);
students[i] = new Student(notaT, notaP);
}
printGrades(students);
System.out.println();
}
private static void printGrades(Student[] students) {
System.out.println("NotaT NotaP Pauta");
for (Student student : students) {
System.out.printf("%5.1f %5.1f %5d\n", student.notaT, student.notaP, student.notaFinal);
}
}
}
class Student {
public double notaT;
public double notaP;
public int notaFinal;
public Student(double notaT, double notaP) {
this.notaT = notaT;
this.notaP = notaP;
this.notaFinal = (notaT < 7 || notaP < 7) ? 66 : (int) Math.round(0.4 * notaT + 0.6 * notaP);
}
}

View File

@ -0,0 +1,39 @@
package aula03;
import utils.UserInput;
import java.util.Random;
import java.util.Scanner;
// Solução do exercício 3
public class HiLo {
private static final Scanner sin = new Scanner(System.in);
private static final Random rand = new Random();
public static void main(String[] args) {
String toContinue;
do {
game();
System.out.print("Pretende continuar? Prima (S)im ");
toContinue = sin.next();
} while (toContinue.equals("S") || toContinue.equals("Sim"));
}
private static void game() {
int secret = rand.nextInt(1, 100);
int i = 1;
int n;
while (true) {
System.out.printf("Tentativa %d: ", i);
n = (int) UserInput.getNumberBetween(sin, 1, 100);
if (n > secret)
System.out.println("Tentativa demasiado alta");
else if (n < secret)
System.out.println("Tentativa demasiado baixa");
else
break;
i++;
}
System.out.printf("Acertou, o número era %d, foram precisas %d tentativas.\n", secret, i);
}
}

View File

@ -0,0 +1,28 @@
package aula03;
import utils.UserInput;
import java.util.Scanner;
// Solução do exercício 2
public class Investment {
public static void main(String[] args) {
Scanner sin = new Scanner(System.in);
int investment;
do {
System.out.print("Introduza o investimento inicial (múltiplo de 1000): ");
investment = sin.nextInt();
} while (investment <= 0 || investment % 1000 != 0);
System.out.print("Introduza a taxa a aplicar (entre 0% e 5%): ");
double tax = UserInput.getNumberBetween(sin, 0, 5);
for (int i = 1; i <= 12; i++) {
investment *= 1+tax/100;
System.out.printf("Investimento em %d %s: %d\n", i, i==1?"mês":"meses", investment);
}
sin.close();
}
}

View File

@ -0,0 +1,33 @@
package aula03;
import utils.UserInput;
import java.util.Scanner;
// Solução do exercício 1
public class PrimesSum {
public static void main(String[] args) {
Scanner sin = new Scanner(System.in);
System.out.println("Introduza um número:");
int n = (int) UserInput.getPositiveNumber(sin);
int sum = 0;
for (int i = 0; i <= n; i++)
if (isNumPrime(i))
sum += i;
System.out.printf("A soma dos números primos até %d é %d\n", n, sum);
sin.close();
}
private static boolean isNumPrime(int n) {
if (n == 1)
return false;
for (int i = 2; i < n; i++)
if (n % i == 0)
return false;
return true;
}
}

View File

@ -0,0 +1,18 @@
# Programação Orientada a Objetos
## Aula 03
### Tópico principal da aula: Classes
* [Guião](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/guides/POO-2021-aula03.pdf)
* [Slides](https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/slides/POO_03_Classes.pdf)
### Exercise List
| Exercise Number | File Name |
|-----------------|----------------------------------------------------------------------------------------------------------------------|
| 1 | [PrimesSum.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula03/PrimesSum.java) |
| 2 | [Investment.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula03/Investment.java) |
| 3 | [HiLo.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula03/HiLo.java) |
| 4 | [Grades.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula03/Grades.java) |
| 5 | [Calendar.java](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/2semestre/poo/src/aula03/Calendar.java) |
---
*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new)