You are on page 1of 5

Data Structures and Algorithms (WS 13/14) Exercise00

Submitted By

Name Chuyu Wang Fei Li Mohammad Faysal Ebna HOSSAIN

student IDs 2869346 2869278 2918323

E-mails chuyuwang310@gmail.com leepercent0512@gmail.com faysal.csebd@gmail.com

Question 1:
(1) Product.java
package de.unistuttgart.dsaws2013.ex0.p1; public class Product { private static String name; private static String description; private static int price; private static Manufacturer manufacturer; ! public Product(String name, int price, Manufacturer manufacturer){ this.name = name; this.price = price; this.manufacturer = manufacturer;} public void setName (String name){ this.name = name; } public void setDescription (String description){ this.description = description; } public void setPrice (int price) { this.price = price; } public void setManufacturer (Manufacturer manufacturer) { this.manufacturer = manufacturer; } public String getName (){ return name; } public String getDescription (){ return description; } public int getPrice () { return price; } public Manufacturer getManufacturer () { return manufacturer; } ====================================================================

(2) Manufacturer.java
package de.unistuttgart.dsaws2013.ex0.p1; public class Manufacturer { public static String name; public static String street; public static String city; public static String country; public String getName (){ return name; } public void setName (String name){ this.name = name; } public String getStreet (){ return street; } public void setStreet (String street){ this.street = street; } public String getCity (){ return city; } public void setCity (String city) { this.city = city; } public String getCountry (){ return country; } public void setCountry (String country){ this.country = country; }

Question2:
(1)ProductFact.java
package de.unistuttgart.dsaws2013.ex0.p1; public enum ProductFact { NAME("Nano"), DESCRIPTION("improved voice control"), MANUFACTURER_NAME ("Apple"), MANUFACTURER_STREET("Allmandring"), MANUFACTURER_CITY("Stuttgart"), MANUFACTURER_COUNTRY("Germany"); private String productInfo; private ProductFact(String productInfo) { this.productInfo = productInfo; } } ====================================================================

(2) TextFinder.java
package de.unistuttgart.dsaws2013.ex0.p1; public class TextFinder { ! static String info; public String ndText (Class Product, String Info) { try{ Object obj = Product.newInstance(); // obj is a newly created object of the passed in type } catch (Exception ex) {} return info; } public static void main (String[] args){ if(args.length != 1){ System.err.println("invalid input!"); // check for invalid input parameters System.exit (-1); } String name = "Nano"; Exception IllegalArgumentException; ! ! if (name == info){

for (ProductFact productInfo: ProductFact.values()){ ! ! system.out.printly("product" + productInfo);} else throws IllegalArgumentException != null; }

} }

Quesiton3:
pseudocode of the method ndText in the previous problem:

accept a given string while the string length is not zero do read the whole strings one by one if the given string matches one of the strings in the string set then return the corresponding ProductFact value; ; od; Throws the IllegalArgumentException.

You might also like