Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

preciso de ajuda com um trabalho.

Vou dar alguns scripts e depois um enunciado e


preciso que completes o codigo e enuncies os padroes de desenho utilizados.

//products.txt
Car 990001 Toyota Avalon 100
Car 990002 MAZDA MX-5 Miata 100
Car 990000 Ford Maverick 120
Van 980001 GMC Safari 130
Van 980002 Lancia Voyager 120
Van 970006 Alfa Romeo AR6 130
Van 970005 Jeep Grand Cherokee 150
Motorcycle 900009 BMW R1150R Boxer Naked Roadster Cinza ABS 195
Motorcycle 900010 Harley-Davidson Pan America 1250 205
Motorcycle 990001 Ducati DesertX 185

//OldJeep class

package lab13.ex1;

public class OldJeep {


private String data;

public OldJeep(String data) {


this.data = data;
}

public String getData() {


return data;
}

@Override
public String toString() {
return "OldJeep [data=" + data + "]";
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((data == null) ? 0 : data.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
OldJeep other = (OldJeep) obj;
if (data == null) {
if (other.data != null)
return false;
} else if (!data.equals(other.data))
return false;
return true;
}

//Product interface

package lab13.ex1;

public interface Product {


String code();
String description();
double points();
}

//client class

package lab13.ex1;

public class Client {


private String code;
private String name;

public Client(String code, String name){


this.code = code;
this.name = name;
}

public String getCode() {


return code;
}

public String getName() {


return name;
}

//main, nao posso alterar o question1

package lab13.ex1;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;

// Notas:
// Não altere o código apresentado na alinea 1
// Deve completar o código das alineas 2 e 3
// Pode comentar código para garantir que vai executando parcialmente

public class XIII1{

public static void main(String[] args) throws FileNotFoundException {


PrintStream fl = new PrintStream(new File("pds2022.txt"));
test(System.out); // executa e escreve na consola
fl.println(System.getProperty("user.dir"));
fl.println(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new
Date()));
test(fl); // executa e escreve no ficheiro
fl.close();
}

private static void test(PrintStream out) {


question1(out);
question2(out);
// question3(out);
}

private static void question1(PrintStream out) {


out.println("\nQuestion 1) ----------------------------------\n");
ToShare market = new ToShare();
Product[] cars = {
new Car("ZA11ZB", "Tesla, Grey, 2021", 100),
new Van("AA22BB", "Chevrolet Chevy, 2020", 180),
new Motorcycle("ZA33ZB", "Touring, 750, 2022", 85),
new Car("BB44ZB", "Ford Mustang, Red, 2021", 150),
};
for (Product item : cars)
market.add(item);

out.println("--- All Products :");


for (Product item : market.getProducts())
out.println(item);

Client u1 = new Client("187", "Peter Pereira");


Client u2 = new Client("957", "Anne Marques");
Client u3 = new Client("826", "Mary Monteiro");
market.share("ZA11ZB", u1);
market.share(cars[2], u2);
market.share("BB44ZB", u3);

out.println("--- Shared Products :\n" + market.sharedProducts());


market.giveBack(cars[0]);
market.giveBack("BB44ZB");
out.println("--- Shared Products :\n" + market.sharedProducts());

market.remove("ZA11ZB");
OldJeep oj = new OldJeep("JJ0011;Some old SUV;88.5"); // assume
"code;description;points"
market.add(new Jeep(oj));
out.println("--- All Products :");
for (Product item : market)
out.println(item);
}

private static void question2(PrintStream out) {


out.println("\nQuestion 2 (output example)
----------------------------------\n");
// Completar
}

private static void question3(PrintStream out) {


out.println("\nQuestion 3) ----------------------------------\n");
// Completar
}

You might also like