OMGWTFBBQ
Bone for Tuna
- Член од
- 3 февруари 2007
- Мислења
- 8.802
- Поени од реакции
- 4.420
А да му направиш, clean/build и ако тоа не ти успее изгаси го eclipс-от и потоа пушти го од командна линија со eclipse.exe -cleanДруго е проблемот, еве screenshot ќе постирам
Не сака ниту со првото, ниту со второто.А да му направиш, clean/build и ако тоа не ти успее изгаси го eclipс-от и потоа пушти го од командна линија со eclipse.exe -clean
кликам од десно Eclipse 3.7 (Indigo) и ништо ...Можеш да го симнеш од тука
http://eclipsesource.com/en/downloads/eclipse-indigo-download/
Тоа од десно ти се само линкови до соодветната верзија.кликам од десно Eclipse 3.7 (Indigo) и ништо ...
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
class Glavna {
public void Vnesuvanje() {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Avtomobil vnes = new Avtomobil();
System.out.println("Tip na avtomobil :");
try {
vnes.marka = br.readLine();
} catch (IOException e) {
System.out.println("Obidi se povtorno.");
}
System.out.println("Serija na avtomobilot :");
try {
vnes.serija = br.readLine();
} catch (IOException e) {
System.out.println("Obidi se povtorno.");
}
System.out.println("Gorivo :");
try {
vnes.gorivo = br.readLine();
} catch (IOException e) {
System.out.println("Obidi se povtorno.");
}
System.out.println("Potrosuvacka (L/100km) :");
try {
vnes.potrosuvacka = br.read();
} catch (IOException e) {
System.out.println("Obidi se povtorno.");
}
System.out.println("Zafatnina na motorot (cc) :");
try {
vnes.zafatnina = br.read();
} catch (IOException e) {
System.out.println("Obidi se povtorno.");
}
System.out.println("Moknost (KW) :");
try {
vnes.moknost = br.read();
} catch (IOException e) {
System.out.println("Obidi se povtorno.");
}
}
public void Brishenje() {
}
public void Promena_Snimanje() {
}
public static void main(String[] args) throws TransformerConfigurationException, TransformerException {
XML xml = new XML();
Avtomobil avto = new Avtomobil();
System.out.println(xml.create("AVTOMOBIL.xml", avto));
System.out.println("Evidencija Na Avtomobili");
System.out.println("1 - Vnesuvanje na nov Avtomobil");
System.out.println("2 - Prebaruvanje");
System.out.println("3 - Promena na podatoci");
System.out.println("0 - Izlez");
int x = -1;
switch (x) {
case 1:
case 2:
case 3:
case 0:
break;
}
}
}
class Avtomobil {
public String marka;
public String serija;
public String gorivo;
public double potrosuvacka;
public int zafatnina;
public int moknost;
public String getMarka() {
return marka;
}
public void setMarka(String marka) {
this.marka = marka;
}
public String getSerija() {
return serija;
}
public void setSerija(String serija) {
this.serija = serija;
}
public String getGorivo() {
return gorivo;
}
public void setGorivo(String gorivo) {
this.gorivo = gorivo;
}
public double getPotrosuvacka() {
return potrosuvacka;
}
public void setPotrosuvacka(double potrosuvacka) {
this.potrosuvacka = potrosuvacka;
}
public int getZafatnina() {
return zafatnina;
}
public void setZafatnina(int zafatnina) {
this.zafatnina = zafatnina;
}
public int getMoknost() {
return moknost;
}
public void setMoknost(int moknost) {
this.moknost = moknost;
}
}
class XML {
public String create(String fileName, Avtomobil avtomobil) throws TransformerConfigurationException, TransformerException {
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = (Document) documentBuilder.newDocument();
Element root = (Element) document.createElement("Avtomobil");
Element marka = (Element) document.createElement("Marka");
Element serija = (Element) document.createElement("Serija");
Element gorivo = (Element) document.createElement("Gorivo");
Element zafatnina = (Element) document.createElement("Zafatnina");
Element moknost = (Element) document.createElement("Moknost");
marka.appendChild(document.createTextNode(avtomobil.getMarka()));
serija.appendChild(document.createTextNode(avtomobil.getSerija()));
gorivo.appendChild(document.createTextNode(avtomobil.getGorivo()));
zafatnina.appendChild(document.createTextNode(String.valueOf(avtomobil.getPotrosuvacka())));
moknost.appendChild(document.createTextNode(String.valueOf(avtomobil.getMoknost())));
root.appendChild(marka);
root.appendChild(serija);
root.appendChild(gorivo);
root.appendChild(zafatnina);
root.appendChild(moknost);
document.appendChild(root);
Source source = new DOMSource(document);
File file = new File(fileName);
Result result = new StreamResult(file);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(source, result);
return "DONE!";
} catch (ParserConfigurationException | TransformerFactoryConfigurationError | TransformerException e) {
return e.toString();
}
}
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Avtomobili>
<avtomobil id="">
<Marka>Opel</Marka>
<Gorivo/>
<Zafatnina/>
<potrosuvacka/>
<Moknost/>
</avtomobil>
</Avtomobili>
public String create(String fileName, Avtomobil avtomobil) throws TransformerConfigurationException, TransformerException {
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document dokument = docBuilder.newDocument();
Element filee = dokument.createElement("Avtomobili");
dokument.appendChild(filee);
Element glavenElement = dokument.createElement("avtomobil");
Attr attr = dokument.createAttribute("id");
glavenElement.setAttributeNode(attr);
filee.appendChild(glavenElement);
Element marka = dokument.createElement("Marka");
marka.appendChild(dokument.createTextNode("Opel"));
glavenElement.appendChild(marka);
Element Gorivo = dokument.createElement("Gorivo");
glavenElement.appendChild(Gorivo);
Element Zafatnina = dokument.createElement("Zafatnina");
glavenElement.appendChild(Zafatnina);
Element potrosuvacka = dokument.createElement("potrosuvacka");
glavenElement.appendChild(potrosuvacka);
Element Moknost = dokument.createElement("Moknost");
glavenElement.appendChild(Moknost);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(dokument);
StreamResult result = new StreamResult(new File("file.xml"));
transformer.transform(source, result);
} catch (ParserConfigurationException | TransformerFactoryConfigurationError | TransformerException e) {
return e.toString();
}
return null;
}
Некако вака изгледа структуата на xml:
Најгоре id не мора, но мене повеќе ми има смисла со id да се бараат автомобилите..Код:<?xml version="1.0" encoding="UTF-8" standalone="no"?> <Avtomobili> <avtomobil id=""> <Marka>Opel</Marka> <Gorivo/> <Zafatnina/> <potrosuvacka/> <Moknost/> </avtomobil> </Avtomobili>
Кодот за креирање на фајлот е :
Уствари еве тука имаш добар пример за се тоа што ти треба се надевам ќе се снајдеш..PHP:public String create(String fileName, Avtomobil avtomobil) throws TransformerConfigurationException, TransformerException { try { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document dokument = docBuilder.newDocument(); Element filee = dokument.createElement("Avtomobili"); dokument.appendChild(filee); Element glavenElement = dokument.createElement("avtomobil"); Attr attr = dokument.createAttribute("id"); glavenElement.setAttributeNode(attr); filee.appendChild(glavenElement); Element marka = dokument.createElement("Marka"); marka.appendChild(dokument.createTextNode("Opel")); glavenElement.appendChild(marka); Element Gorivo = dokument.createElement("Gorivo"); glavenElement.appendChild(Gorivo); Element Zafatnina = dokument.createElement("Zafatnina"); glavenElement.appendChild(Zafatnina); Element potrosuvacka = dokument.createElement("potrosuvacka"); glavenElement.appendChild(potrosuvacka); Element Moknost = dokument.createElement("Moknost"); glavenElement.appendChild(Moknost); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(dokument); StreamResult result = new StreamResult(new File("file.xml")); transformer.transform(source, result); } catch (ParserConfigurationException | TransformerFactoryConfigurationError | TransformerException e) { return e.toString(); } return null; }
package Seminarska;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Glavna {
public static void Vnesuvanje()
{
Scanner scan=new Scanner (System.in);
Avtomobil a = new Avtomobil();
System.out.println("Vnesi marka na avtomobilot :");
a.marka=scan.next();
System.out.println("Vnesi serija na avtomobilot :");
a.serija=scan.next();
System.out.println("Vnesi gorivo :");
a.gorivo=scan.next();
System.out.println("Vnesi potrosuvacka :");
a.potrosuvacka=scan.nextDouble();
System.out.println("Vnesi zafatnina (cc) :");
a.zafatnina=scan.nextInt();
System.out.println("Vnesi moknost (kW) :");
a.moknost=scan.nextInt();
List<Avtomobil> avtomobil = new ArrayList<Avtomobil>();
avtomobil.add(new Avtomobil());
XML xml = new XML();
System.out.println(xml.create("AVTOMOBILI.xml", avtomobil));
scan.close();
}
public void Brishenje()
{
}
public void Promena_Snimanje()
{
}
public static void main(String[] args) {
int x;
System.out.println("Evidencija Na Avtomobili");
System.out.println("1 - Vnesuvanje na nov Avtomobil");
System.out.println("2 - Prebaruvanje");
System.out.println("3 - Promena na podatoci");
System.out.println("0 - Izlez");
Scanner scan=new Scanner (System.in);
x=scan.nextInt();
switch(x){
case 1:
Vnesuvanje();
case 2:
case 3:
case 0:
break;
}
scan.close();
}
}
package Seminarska;
public class Avtomobil {
public String marka;
public String serija;
public String gorivo;
public double potrosuvacka;
public int zafatnina;
public int moknost;
public String getMarka() {
return marka;
}
public void setMarka(String marka) {
this.marka = marka;
}
public String getSerija() {
return serija;
}
public void setSerija(String serija) {
this.serija = serija;
}
public String getGorivo() {
return gorivo;
}
public void setGorivo(String gorivo) {
this.gorivo = gorivo;
}
public double getPotrosuvacka() {
return potrosuvacka;
}
public void setPotrosuvacka(double potrosuvacka) {
this.potrosuvacka = potrosuvacka;
}
public int getZafatnina() {
return zafatnina;
}
public void setZafatnina(int zafatnina) {
this.zafatnina = zafatnina;
}
public int getMoknost() {
return moknost;
}
public void setMoknost(int moknost) {
this.moknost = moknost;
}
public String toString()
{
return "Avtomobil [marka= " + marka + ", serija= " + serija + ", gorivo= " + gorivo + ", potrosuvacka= " + potrosuvacka + ", zafatnina= " + zafatnina + ", moknost= " + moknost + "]" ;
}
}
package Seminarska;
import java.io.File;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class XML {
public String create(String fileName, List<Avtomobil> avtomobil)
{
try
{
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.newDocument();
Element root = (Element) document.createElement("Avtomobili");
for(int i=0;i<avtomobil.size();i++)
{
Element avtomobilElement = (Element) document.createElement("Avtomobil");
avtomobilElement.setAttribute("id",String.valueOf(i));
Element marka = (Element) document.createElement("Marka");
Element serija = (Element) document.createElement("Serija");
Element gorivo = (Element) document.createElement("Gorivo");
Element potrosuvacka = (Element) document.createElement("Potrosuvacka");
Element zafatnina = (Element) document.createElement("Zafatnina");
Element moknost = (Element) document.createElement("Moknost");
marka.appendChild(document.createTextNode(avtomobil.get(i).getMarka()));
serija.appendChild(document.createTextNode(avtomobil.get(i).getSerija()));
gorivo.appendChild(document.createTextNode(avtomobil.get(i).getGorivo()));
potrosuvacka.appendChild(document.createTextNode(String.valueOf(avtomobil.get(i).getPotrosuvacka())));
zafatnina.appendChild(document.createTextNode(String.valueOf(avtomobil.get(i).getZafatnina())));
moknost.appendChild(document.createTextNode(String.valueOf(avtomobil.get(i).getMoknost())));
avtomobilElement.appendChild(marka);
avtomobilElement.appendChild(serija);
avtomobilElement.appendChild(gorivo);
avtomobilElement.appendChild(potrosuvacka);
avtomobilElement.appendChild(zafatnina);
avtomobilElement.appendChild(moknost);
root.appendChild(avtomobilElement);
}
document.appendChild(root);
Source source = new DOMSource(document);
File file = new File(fileName);
Result result = new StreamResult(file);
Transformer transformer= TransformerFactory.newInstance().newTransformer();
transformer.transform(source,result);
return "DONE!";
}
catch (Exception e) {
return e.toString();
}
}
}
Па почетник сум во Јава, и првиот пример со exceptions што го учев ми немаше логика. Отприлика сфатив зошто се користи, и приметив дека понатаму имаат важна улога, но конкретно во примерот што го ми беше прикажан некако многу код се создаде.Како мислиш преголем код се создава?
Многу се битни и корисни исклучоците посебно кога ќе правиш интерактивни апликации каде што податоците што ќе ги внесе корисникот не секогаш ќе бидат во точен формат..
public void Print(int ram)
{
if(ram<0)
System.out.println("Can't have less than 0 ram");
......
......
}
public static void main(String[] args)
{
......
kompjuter.Print(-1);
}
public void Print(int ram)
{
checkRam(ram);
......
......
}
private void checkRam(int ram)
{
if(ram<0)
throw new IllegalArgumentException("Can't have less than 0 ram");
}
public static void main(String[] args)
{
...
try
{
kompjuter.Print(-1);
}
catch(IllegalArgumentException exception)
{
System.out.println(exception.getMessage());
return;
}
int broj = konvert("1231231asdasd");
if(broj == greska1){
//kod
}else if( broj == greska 2){
// kod
}else if(broj == greska 3){
//kod
}else{
// da se PREDPOSTAVI deka tuka e tocen rezultato...
}
try{
int broj = konvert("1231231asdas")
}catch(Exception ex){
/// kod za sprauvanje so greska
}
}catch(TipGreska2 ex){
/// kod za sprauvanje so greska2
}
import java.util.Scanner;
public class Matrici {
class Matrica
{
Scanner in = new Scanner(System.in);
int mat[][];
Matrica(int ds)
{
mat = new int[ds][ds];
}
void vrednosti(int n)
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
System.out.println("[" + i + "]" + "[" + j + "] = ");
mat[i][j] = in.nextInt();
}
}
}
void zbir(Matrica M2, int ds)
{
int zbir[][] = new int[ds][ds];
for (int i = 0; i < mat[0].length; i++)
{
for (int j = 0; j < mat[1].length; j++)
{
zbir[i][j] += mat[i][j] + M2.mat[i][j];
}
}
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Vnesi ja dimenzijata za prvata matrica: ");
int n = in.nextInt();
Matrica M1 = new Matrica(n); - Овде дава грешка
}
}