id
stringlengths
36
36
text
stringlengths
1
1.25M
fbf606ab-8da6-43a9-955e-94b796709f4c
public static void frequency(double frequency, double min, double max) throws IllegalArgumentException { if (frequency < min || frequency > max) { StringBuilder e = new StringBuilder(80); e.append("Invalid frequency value! "); e.append("It must be a positive double between "); e.append(String.format(Locale.ENGLISH, "%1.2f", min)); e.append(" and "); e.append(String.format(Locale.ENGLISH, "%1.2f", max)); e.append("."); throw new IllegalArgumentException(e.toString()); } }
c7a9da44-5932-4d38-923a-064bfddf2c2d
public static void midiNumber(int midiNumber) throws IllegalArgumentException { if (midiNumber < MIDI_MIN_NUMBER || midiNumber > MIDI_MAX_NUMBER) { StringBuilder e = new StringBuilder(80); e.append("Invalid MIDI note number value! "); e.append("It must be a positive integer between "); e.append(MIDI_MIN_NUMBER); e.append(" and "); e.append(MIDI_MAX_NUMBER); e.append("."); throw new IllegalArgumentException(e.toString()); } }
29459d35-94d4-4be2-9f0b-d17058eb7cb2
public static void pianoKey(int pianoKey) throws IllegalArgumentException { if (pianoKey < PIANO_MIN_KEY || pianoKey > PIANO_MAX_KEY) { StringBuilder e = new StringBuilder(80); e.append("Invalid piano key number value! "); e.append("It must be a positive integer between "); e.append(PIANO_MIN_KEY); e.append(" and "); e.append(PIANO_MAX_KEY); e.append("."); throw new IllegalArgumentException(e.toString()); } }
22813289-276d-4a00-8a4c-1e891a1dc78b
public static void transpose(int midiNumber, int semitones) throws IllegalArgumentException { int transposed = midiNumber + semitones; if (transposed < MIDI_MIN_NUMBER || transposed > MIDI_MAX_NUMBER) { StringBuilder e = new StringBuilder(80); e.append("Invalid semitones value! "); e.append("For this note it must be a value between -"); e.append(midiNumber); e.append(" and +"); e.append(127 - midiNumber); e.append("."); throw new IllegalArgumentException(e.toString()); } }
6ea22a2d-1140-43a9-ad41-926100caacd4
public static void volume(int volume) throws IllegalArgumentException { if (volume < VOLUME_MIN_VALUE || volume > VOLUME_MAX_VALUE) { StringBuilder e = new StringBuilder(80); e.append("Invalid volume value! "); e.append("It must be a positive integer between "); e.append(VOLUME_MIN_VALUE); e.append(" and "); e.append(VOLUME_MAX_VALUE); e.append("."); throw new IllegalArgumentException(e.toString()); } }
a7507afb-13ca-4b47-a92e-2ea0a160a2f4
public static void dots(int dots) throws IllegalArgumentException { if (dots < DOTS_MIN || dots > DOTS_MAX) { StringBuilder e = new StringBuilder(70); e.append("Invalid dots number! "); e.append("It must be a positive integer between "); e.append(DOTS_MIN); e.append(" and "); e.append(DOTS_MAX); e.append("."); throw new IllegalArgumentException(e.toString()); } }
adbd7e2e-0ab5-4521-b5e6-4c2295aafa86
public static void semitones(int semitones, int min, int max) throws IllegalArgumentException { if (semitones < min || semitones > max) { StringBuilder e = new StringBuilder(80); e.append("Invalid semitones value! "); e.append("It must be a positive integer between "); e.append(min); e.append(" and "); e.append(max); e.append("."); throw new IllegalArgumentException(e.toString()); } }
c97cc187-a128-4822-a3de-2330980fc220
public static double getFrequency(int semitonesDistance) { return getFrequency(semitonesDistance, A440); }
c1c7cbae-15e7-480d-a016-2b8629a9e398
public static double getFrequency(int semitonesDistance, double pitch) { return Math.pow(2, (double) semitonesDistance / 12.0) * pitch; }
907d1de9-f679-4edb-ad51-5af8e2647680
public static double getCents(double reference, double frequency) { return 1200.0 * lb(frequency / reference); }
3c11e168-e888-48e6-9cf6-ab8a0598ea7b
public static int getSemitones(double reference, double frequency) { return getSemitones(getCents(reference, frequency)); }
81189ad6-b844-4d88-920b-e3f53a6c650f
public static int getSemitones(double cents) { return (int) (Math.round(cents) / 100.0); }
3bfdb522-1367-4209-bb3e-cba8cb385d5b
public static int getMIDINumber(double frequency) throws IllegalArgumentException { Validator.frequency(frequency, MIDI_MIN_FREQUENCY, MIDI_MAX_FREQUENCY); return (int) Math.round(69.0 + 12.0 * lb(frequency / A440)); }
e6e90316-1ec7-4781-9541-d9ea307eab3a
public static double getMIDINumberFrequency(int midiNumber) throws IllegalArgumentException { Validator.midiNumber(midiNumber); return A440 * Math.pow(2, (midiNumber - 69.0) / 12.0); }
2464d37a-e661-4c53-a244-dcc3e7db79ea
public static int getPianoKeyNumber(double frequency) throws IllegalArgumentException { Validator.frequency(frequency, PIANO_MIN_FREQUENCY, PIANO_MAX_FREQUENCY); return (int) Math.round(12.0 * lb(frequency / A440) + 49.0); }
cfaf5519-cec9-4b5a-8edb-6055f7da40da
public static double getPianoKeyFrequency(int pianoKey) throws IllegalArgumentException { Validator.pianoKey(pianoKey); return Math.pow(2, ((double) pianoKey - 49.0) / 12.0) * A440; }
31668e83-8d14-41a1-b931-8d50d34c29ca
private static double lb(double value) { return Math.log(value) / Math.log(2.0); }
1e2655f4-a77c-4848-9327-3873db648e74
Accidental(final String name, final char symbol) { this.name = name; this.symbol = symbol; }
d66fd256-90ea-411d-811b-aab6363ce2fd
public String getName() { return name; }
fa58a008-da15-4518-b9c1-1537ccaaa450
public char getSymbol() { return symbol; }
c05de5fe-a0b3-42d1-8c4c-92cf73d916f9
@Override public String toString() { return String.valueOf(symbol); }
2175bc6b-145d-4078-bc03-46f3c1179fe7
private Tone(Name name, Accidental accidental, int pitchClass) { this.name = name; this.accidental = accidental; this.pitchClass = pitchClass; if (accidental == Flat) { this.accidentalID = 1; } else { this.accidentalID = 0; } }
72773402-1447-40de-ae26-b6b82e22a5cb
public Tone(double frequency) { this(Frequency.getMIDINumber(frequency)); }
d993ca35-b1dc-48ed-a37c-d3e705df9388
public Tone(int midiNumber) { Validator.midiNumber(midiNumber); this.pitchClass = midiNumber % 12; this.accidentalID = 0; this.name = tones[pitchClass][accidentalID].getName(); this.accidental = tones[pitchClass][accidentalID].getAccidental(); }
9d0153cb-855a-449f-b846-9983681f3531
public Tone(Tone tone) { this(tone.getName(), tone.getAccidental(), tone.getPitchClass()); }
e9b21ee7-9745-4cb6-a3f5-8e17dd6bdc58
public Name getName() { return name; }
d1c693b7-469a-4e5f-9b27-138fdac240b9
public Accidental getAccidental() { return accidental; }
00e0eac2-0107-428b-8b87-ce26964a841d
public int getPitchClass() { return pitchClass; }
f956ffcd-dff6-4daf-a8e3-e9a234d2c03e
public void switchAccidental() { this.accidentalID = (this.accidentalID == 0 ? 1 : 0); this.name = tones[pitchClass][accidentalID].getName(); this.accidental = tones[pitchClass][accidentalID].getAccidental(); }
7acaff53-b092-4711-9fc8-99f02d29ad6a
public static Tone getTone(Name name, Accidental accidental) { for (int pitchClass = 0; pitchClass < tones.length; pitchClass++) { if (tones[pitchClass][0].getName() == name && tones[pitchClass][0].getAccidental() == accidental) { return new Tone(tones[pitchClass][0]); } if (tones[pitchClass][1].getName() == name && tones[pitchClass][1].getAccidental() == accidental) { return new Tone(tones[pitchClass][1]); } } return null; // Unreachable }
9b97e9a3-92bd-4adc-874e-da74da4f5237
public static int getPitchClass(Name name, Accidental accidental) { for (int pitchClass = 0; pitchClass < tones.length; pitchClass++) { if (tones[pitchClass][0].getName() == name && tones[pitchClass][0].getAccidental() == accidental || tones[pitchClass][1].getName() == name && tones[pitchClass][1].getAccidental() == accidental) { return pitchClass; } } return -1; // Unreachable }
ab565325-250a-435b-a515-7c9fdf168857
public String toString() { StringBuilder sb = new StringBuilder(10); sb.append(name); if (accidental != Natural) { sb.append(accidental); } return sb.toString(); }
c9c57d18-470a-438e-af57-8f0f2dda6c44
public boolean equals(Object o) { if (!(o instanceof Tone)) { return false; } if (o == this) { return true; } Tone t = (Tone) o; if (t.getPitchClass() == this.pitchClass) { return true; } return false; }
30cd81d0-f24a-4f82-b9fc-32128bbdacf6
public int hashCode() { final int prime = 911; int hash = 1; hash = prime * hash + name.hashCode(); hash = prime * hash + accidental.hashCode(); hash = prime * hash + pitchClass; hash = prime * hash + accidentalID; return hash; }
0075892b-0283-4898-b3fe-3359b4ab8675
public static void main(String[] args) { int[] a = {1, 2, 3}; int[] b = {1, 442, 3}; boolean koll = Arrays.equals(a, b); if (koll == true) { System.out.println(""); } else { System.out.println(""); } }
3dfc47ff-5ee5-4c24-ad89-31bcb979fdc0
public static void main(String[] args) { int n = 100; int[] a = new int[n]; System.out.print("Dessa tal slumpas till arrayen: "); for(int i = 0 ; i < n ; i++){ if(i%10==0){ System.out.println(); } a[i] = (int) (1000 * Math.random()); System.out.print(a[i]+"\t"); } int s; for(int i = 0; i < n-1 ; i++) { for(int j = i+1; j < n ; j++){ if(a[i] > a[j]){ s = a[i]; a[i]= a[j]; a[j] = s; } } } System.out.println(); System.out.print("Efter sortering: "); for(int i = 0 ; i < n ; i++){ if(i%10==0) { System.out.println(); } System.out.print(a[i]+"\t"); } }
4f22bc11-2bb1-4e2a-ae4f-464851d9db63
public static void main( String[] arg ) { Scanner sc = new Scanner(System.in); int[] arr = {3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25}; int max, min, t, pos, mitten; min = 0; max = arr.length - 1; System.out.print("Vilket heltal söker du? "); t = sc.nextInt(); pos = -1; while(min <= max && pos == -1) { mitten = (max + min)/2; if ( t > arr[mitten]) min = mitten + 1; else if (t < arr[mitten]) max = mitten - 1; else pos = mitten; } if (pos == -1) System.out.println("Talet hittades inte"); else System.out.println("Talet finns i element nummer " + pos); }
0e52e3c1-336e-46fd-90c9-6152f4b267c4
public static void main( String[] arg ) { Scanner sc = new Scanner(System.in); int[] arr = { 13 , 15, 7 , 3 ,11 , 21 , 25 , 23 , 9 , 5 , 17} ; int pos = -1; System.out.print("Vilket heltal söker du? "); int t = sc.nextInt(); for(int i = 0 ; i < arr.length ; i++) { if( t== arr[i]){ pos = i; i = arr.length; // loopen slutar } } if (pos == -1) System.out.println("Talet hittades inte!"); else System.out.println("Talet finns i element nummer " + pos); }
0733af02-df01-4404-b4c9-feae9a93920a
public static void main(String[] args) { Scanner sc = new Scanner(System.in); HashMap<String, String> ht = new HashMap<>(); char svar; boolean fortsatt = true; int antalRatt = 1; while (fortsatt) { System.out.println(); System.out.println("Välj:"); System.out.println("1. Skapa Gloslistan"); System.out.println("2. Visa Gloslistan"); System.out.println("3. Skriv in en ny glosa"); System.out.println("4. Glosförhör"); System.out.println("0. Avsluta"); try { svar = sc.nextLine().charAt(0); switch (svar) { case '1': ht.put("Sol", "Sun"); ht.put("Hej", "Hello"); ht.put("Måne", "Moon"); ht.put("Regn", "Rain"); ht.put("Snow", "Snö"); System.out.println("Klart"); break; case '2': System.out.print("Glosa? "); String Glos = sc.nextLine(); System.out.println("Glosa: " + ht.get(Glos)); break; case '3': System.out.println("Ange det svenska ordet: "); String Glosa = sc.next(); System.out.println("Ange det engelska ordet: "); String uzd = sc.next(); ht.put(Glosa, uzd); break; case '4': for (String nyckel : ht.keySet()) { System.out.print("Vad heter: " + nyckel + " På engelska? "); String svaret = sc.next(); if (svaret.equals(ht.get(nyckel))) { System.out.println("Rätt!"); antalRatt++; } else { System.out.println("Fel! Rätt svar är " + ht.get(nyckel)); } } System.out.println("Antalet rätta: " + antalRatt ); break; case '0': System.out.println("SLUT"); break; default: break; } // vof switch } // end of try catch (Exception e) { } System.out.println(); } }//end main
0f2d59ef-1626-4d9e-8881-5d0a74de6f47
public static void main(String[] args) { int n = 100; int[] a = new int[n]; System.out.print("Arrayens element slumpas och skrivs ut: "); for (int i = 0; i < a.length; i++) { if (i%10==0){ System.out.println(""); } a[i] = (int)(1000 * Math.random()) ; System.out.print(a[i] + "\t"); }//end for }//end main
2fef34d3-631c-41e4-9da3-a444b1f68e6b
public static void main( String[] arg ) { int n = 100; int[] a = new int[n]; System.out.print("Dessa tal slumpas till arrayen:"); for(int i = 0 ; i < n ; i++) { if(i%10==0) System.out.println(); a[i] = (int)( 1000 * Math.random() ); System.out.print(a[i]+"\t"); } int summa, max, min; double medel; summa = 0; max = -1; min = 1000; for(int i = 0; i < n; i++) { summa = summa +a[i]; if (a[i]>max) max = a[i]; if (a[i]< min) min = a[i]; } medel = (double)summa/n; System.out.println(" "); System.out.println("Summa = " + summa + " Medel = " + medel); System.out.println("Max = " + max + " Min = " + min); }
94853afb-2648-41cf-883f-ac386385ae0b
public PeerNode() { name = null; ip = null; port = null; }
396d0ab6-9d00-418d-894c-eaa38c0b54c8
public PeerNode(String name, String ip, Long port) { this.name = name; this.ip = ip; this.port = port; }
fdd466d5-8d59-4e91-b59e-ad55b1a68107
public Message(){ dest = null; kind = null; data = null; src = null; seqNum = null; dupe = false; }
eda581f6-10d9-4173-9613-371e0c71aeae
public Message(String dest, String kind, Object data) { this.dest = dest; this.kind = kind; this.data = data; src = null; seqNum = null; dupe = false; }
4adc7c51-1238-4c5f-a25a-c7dd79143cee
public String get_Dest() { return dest; }
629cfeb0-fcc8-43f0-854e-46efd04c59fb
public String get_Kind() { return kind; }
c22f130f-ea1c-442c-b925-2a742843f518
public Object get_Data() { return data; }
2fd64b8b-32a2-422f-b283-8c4d9b24614f
public String get_Src() { return src; }
a3221c8a-2f59-4810-bd62-c58812170cba
public Integer get_SeqNum() { return seqNum; }
4e16b922-0933-4064-8527-c244f02dc3aa
public boolean get_Dupe() { return dupe; }
597e14e2-e465-4160-b31d-351e134c03fd
public void set_Dest(String dest) { this.dest = dest; }
46e80712-4307-4824-8e0d-4a2fe2853088
public void set_Kind(String kind) { this.kind = kind; }
88edb336-675c-4a7a-acc5-a1639213e2ae
public void set_Data(Object data) { this.data = data; }
d1ae2f14-69a4-4c19-89d9-799340676a50
public void set_Src(String source) { src = source; }
6d17551d-2749-413f-aae3-c92d574b0e40
public void set_SeqNum(int sequeceNumber) { seqNum = sequeceNumber; }
916c8e35-14eb-4e55-ae95-83c3268f48e2
public void set_Dupe(boolean dupe) { this.dupe = dupe; }
6e3a8f72-374a-4c06-85f9-b84abe770da1
public MessagePasser() { configuration_filename = null; local_name = null; }
b9162f85-2826-4f8f-86a0-058f95f64fff
public MessagePasser(String configuration_filename, String local_name) { this.configuration_filename = configuration_filename; this.local_name = local_name; }
d086ecbe-f2d4-4cb8-a796-f756a80b9818
public void send(Message message) { Rule r = check_rule(message); if (r != null) { r.getAction(); //add code here } System.out.println("Send message from SenderBuffer"); }
6bf04343-4728-4661-9b17-bc497c52522a
public void receive() { System.out.println("Read message from ReceiverBuffer"); }
682e77a1-fd6b-481c-8309-4c174ba68092
public static void SetUp() throws Exception { System.out.println("Local server is running."); try { while(true) { Socket socket = new Socket(); socket = listener.accept(); CreateListenThread(socket); } } catch (SocketException e) { // TODO Auto-generated catch block } finally { listener.close(); } }
eb06a299-66e4-4467-ba27-bde6f8f67a44
private static void CreateListenThread(final Socket socket) throws IOException { new Thread(new Runnable() { public void run() { try { String readline = new String(""); BufferedReader is=new BufferedReader(new InputStreamReader(socket.getInputStream())); readline = is.readLine(); while (readline != null) { System.out.println("Server is reveiving: "+ readline); readline = is.readLine(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { socket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }).start(); }
68640520-ccc7-4c8f-a7a6-2170a735e34f
public void run() { try { String readline = new String(""); BufferedReader is=new BufferedReader(new InputStreamReader(socket.getInputStream())); readline = is.readLine(); while (readline != null) { System.out.println("Server is reveiving: "+ readline); readline = is.readLine(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { socket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
f8c6a274-1d2c-459f-a1c4-2af155a4361c
private void CreateThread() throws IOException { new Thread(new Runnable() { public void run() { try { SetUp(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start(); }
3644de5b-57fb-4c62-be59-832231d09a1a
public void run() { try { SetUp(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
3ce9c286-f0c4-44b9-948a-de3a09c6494c
public Rule check_rule(Message message) { for (int i = 0; i < RuleSet.size(); i++) { if (RuleSet.get(i).IsMatch(message)) return RuleSet.get(i); } return null; }
f0318232-c64a-47e2-98b5-89165e177dcf
public static void main(String[] args) throws Exception{ String configuration_filename = new String(""); String local_name = new String(""); String send_info = new String(""); listener = new ServerSocket(12344); Message message = new Message(); //Scanner in =new Scanner(System.in); //configuration_filename = in.next(); //local_name = in.next(); MessagePasser MP = new MessagePasser(configuration_filename, local_name); MP.CreateThread(); Socket socket = new Socket("128.237.174.156",12344); PrintWriter ot = new PrintWriter(socket.getOutputStream()); InputStreamReader reader = new InputStreamReader(System.in); BufferedReader input = new BufferedReader(reader); send_info = input.readLine(); while (!send_info.equals("exit")) { String[] command = send_info.split(" "); if (command.length != 2 || !(command[0].equals("send") || command[0].equals("read"))) { System.out.println("Enter the right command!"); send_info = input.readLine(); continue; } if (command[0].equals("read")) { MP.receive(); send_info = input.readLine(); continue; } if (command[0].equals("send")) { ot.println(send_info); ot.flush(); send_info = input.readLine(); continue; } } //System.out.println(configuration_filename); //System.out.println(local_name); socket.close(); listener.close(); System.out.println("Program exit normally"); }
8501e6bb-cc92-4bd9-89db-4999ffba1723
public UserInterface() { super("MyJFrame"); setSize(480, 320); setLocation(500, 200); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //add(MyJPanel()); }
f70c2da9-518b-4388-bdd5-9458806518a0
public Rule() { action = null; src = null; dest = null; kind = null; seqNum = null; }
1d65fc56-8281-47cc-878f-ff2b14745257
public Rule(Rule r) { action = r.action; src = r.src; dest = r.dest; kind = r.kind; seqNum = r.seqNum; }
b86ab18c-b6a1-443e-94f2-c97c1996c621
public Rule(String action, String src, String dest, String kind, Integer seqNum) { this.action = action; this.dest = dest; this.src = src; this.kind = kind; this.seqNum = seqNum; }
c0b172fe-6830-493d-a5f8-61feab6bd021
public String getAction() { return action; }
ec0b6062-278f-4529-ae79-52906eb68860
public void setAction(String action) { this.action = action; }
4ac2b7fa-73a8-4e65-aa25-62d60f73ec1d
public String getSrc() { return src; }
4a1ee64f-9776-4c08-94ae-64d63e24a4d0
public void setSrc(String src) { this.src = src; }
d82c4556-8257-46db-87bc-a5f94b2a324a
public String getDest() { return dest; }
b20ee943-7bcc-4281-9232-358c01a0fd48
public void setDest(String dest) { this.dest = dest; }
30231748-ef30-4133-9e50-066243032c0e
public String getKind() { return kind; }
fad4947e-24e4-4963-a756-4123398b99c7
public void setKind(String kind) { this.kind = kind; }
d38e5a48-d72c-4196-81f8-e1b2517069a5
public Integer getSeqNum() { return seqNum; }
3d5093d1-c49c-4ec2-a0c0-3d8ac9b6b8b7
public void setSeqNum(Integer seqNum) { this.seqNum = seqNum; }
e39adf22-3315-4dac-9a69-dc2efe407d7d
public boolean IsMatch(Message message) { if (message.get_Src().equals(src) || src.equals(null)) { if (message.get_Dest().equals(dest) || dest.equals(null)) { if (message.get_Kind().equals(kind) || kind.equals(null)) { if (message.get_SeqNum().equals(seqNum) || seqNum.equals(null)) { if (message.get_Dupe() == false) return true; } } } } return false; }
fed7c072-e1e9-49ed-83d6-e63f476a26cf
GifPlayer(File file)throws IOException { super.file = file; super.images.add(ImageIO.read(file)); }
facf11a0-8002-4c38-a19d-46dba55fcaf1
public void play();
c509dee8-8d8c-4b81-97a6-c8d74cab3f92
SequencePlayer() { images = null; }
2df0f0f9-bd49-4cf5-9f8f-ac435449909d
SequencePlayer(ArrayList<BufferedImage> images) { this.images = images; }
fa3e9156-dcdd-494d-9458-42f5ae7f3411
public void play() { for (int i = 0; i < images.size(); i++) { new PicturePlayer((BufferedImage)(images.get(i))).play(); } }
2e891c7f-f453-4a54-ae35-c643691f9863
PicturePlayer(BufferedImage image) { this.img = image; }
cb8e8890-34b7-474d-9b31-c236655d43ab
PicturePlayer(File file) throws IOException { img = null; img = ImageIO.read(file); }
e6226cb8-03a0-4334-838f-9473ce284f32
private static void print(int pixel) { if (pixel > 240) { System.out.print(' '); } else if (pixel > 200) { System.out.print('.'); } else if (pixel > 160) { System.out.print('*'); } else if (pixel > 120) { System.out.print('~'); } else if (pixel > 80) { System.out.print('x'); } else if (pixel > 40) { System.out.print('#'); } else { System.out.print('$'); } }
c625eff9-5e18-49d2-9793-06f7b685ff40
private static int Grey(int rgb) { final Color colorful = new Color(rgb); return (colorful.getBlue() + colorful.getRed() + colorful.getGreen()) / 3; }
d7d71e31-c535-41dd-9c5f-2d2183fb0af0
public void play() { for (int y = 0; y < img.getHeight(); y++) { for (int x = 0; x < img.getWidth(); x++) { final int pixel = Grey(img.getRGB(x, y)); print(pixel); } System.out.println(); } }
f0b98137-5402-41b5-928e-930bc9e88893
VideoPlayer(File file) throws IOException { super.file = file; super.images.add(ImageIO.read(file)); }
50ab59df-626b-4326-88da-08492066e699
public static void main(String[] args) { final String arg = "E:\\Me\\Programming\\HackBulgaria\\Java\\GitOther Copy\\Core-Java-1\\8-WorkingWithLibraries\\a.jpg"; final File file = new File(arg); BufferedImage img = null; try { img = ImageIO.read(file); } catch (final Exception e) { e.fillInStackTrace(); } for (int y = 0; y < img.getHeight(); y++) { for (int x = 0; x < img.getWidth(); x++) { final int pixel = Grey(img.getRGB(x, y)); print(pixel); } System.out.println(); } }
26b621dd-2a94-4571-b1e8-8be6cae058ee
private static void print(int pixel) { if (pixel > 240) { System.out.print(' '); } else if (pixel > 200) { System.out.print('.'); } else if (pixel > 160) { System.out.print('*'); } else if (pixel > 120) { System.out.print('~'); } else if (pixel > 80) { System.out.print('x'); } else if (pixel > 40) { System.out.print('#'); } else { System.out.print('$'); } }
5da6a6b5-cfe5-41ac-a271-64c1c2b10660
private static int Grey(int rgb) { final Color colorful = new Color(rgb); return (colorful.getBlue() + colorful.getRed() + colorful.getGreen()) / 3; }
0e175fba-eff2-45e9-8c61-9d15aa7f4f31
public static void main(String[]args){ Product p = Factoria.getProduct("P1"); p.manipulate(); Product c = Factoria.getProduct("P1"); c.manipulate(); Product r = Factoria.getProduct("P2"); r.vender(); }
8f2c6955-7445-46d2-903c-b6ddd160ef37
public static Product getProduct(String name){ Product p = null; if(name.equals("P1")) p = new P1(); else p= new P2(); return p; }
f55e5756-e828-492a-b043-d214eb4a6a93
public static Product getProduct(String name) { Product p = null; if (name.equals("P1")) p = new P1(); else p = new P2(); return p; }