io fin ad ora ho prodotto il seguente codice.
- Codice: Seleziona tutto
Double A = new Double (txtA.getText());
Double B = new Double (txtB.getText());
Double C = new Double (txtC.getText());
JOptionPane.showMessageDialog(null,"Creato da Cracker1992");
DecimalFormat df = new DecimalFormat("###,###,###,###.###");
if(txtA.getText().equals("")&& txtB.getText().equals("") && txtC.getText().equals("")){
JOptionPane.showMessageDialog(null,"inserisci i valori richiesti in a,b e c");
}else if(txtA.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"inserisci il valore richiesto in a");
}
else if(txtB.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"inserisci il valore richiesto in b");
}
else if(txtC.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"inserisci il valore richiesto in b");
}else if( txtA.getText().equals("") || txtC.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"inserisci il valori mancanti soprattutto in a");
}
else if( txtA.getText().equals("") || txtB.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"inserisci il valori mancanti soprattutto in a");
}else if( txtB.getText().equals("") || txtC.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"inserisci il valori mancanti ....");
}
else if( txtA.getText().equals("") && txtC.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"inserisci il valori mancanti in a e c");
}
else if( txtA.getText().equals("") && txtB.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"inserisci il valori mancanti in a e b");
}else if( txtB.getText().equals("") && txtC.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"inserisci il valori mancanti in b e c");
}
else{
JOptionPane.showMessageDialog(null,"bene hai inserito i valori richiesti attento pero a scrivere solo numeri in a,b,c e valori diversi a 0 in a ");
if(A != 0.0){
if(A >= 0.0)
{
Double Delta = new Double (Math.pow(B, 2.0))-(4.0*(A)*(C));
if(Delta < 0.0)
{
JOptionPane.showMessageDialog(null,"il delta è minore quindi nessuna soluzione reale");
Double X1 = null;
Double X2 = null;
Double YV = new Double(-(Delta)) / (4.0 * A);
Double XF = new Double(-B) / (2.0 * A);
Double XV = XF;
Double YF = new Double (-(Delta) / (4.0 * A)) + (1.0 / (4.0 * A));
Double D = new Double (-(Delta) / (4.0 * A)) - (1.0 / (4.0 * A));
txtF.setText(df.format(XF.toString()) + "" + ";" + df.format(XF.toString()));
txtV.setText(df.format(XV.toString()) + "" + ";" + df.format(YV.toString()));
txtD.setText("Y" + "" + "=" + df.format(XF.toString())+ "" + "-" + df.format(D.toString()));
txtASimm.setText("X" + "" + "=" + df.format(XF.toString()));
txtConcavita.setText("Parabola con Concavita verso l'alto");
txtintX1.setText("");
txtintX2.setText("");
if(B>=0 && C>=0){
txtP.setText("Y" + "" + "=" + df.format(A.toString()) + "" + "+" + df.format(B.toString()) + "" + "-" + df.format(C.toString()));
}else if (B>=0 && C<0){
txtP.setText("Y" + "" + "=" + df.format(A.toString()) + "" + "+" + df.format(B.toString()) + "" + "-" + df.format(C.toString()));
}else if(B<0 && C>=0){
txtP.setText("Y" + "" + "=" + df.format(A.toString()) + "" + "-" + df.format(B.toString()) + "" + "+" + df.format(C.toString()));
}
txtintY.setText("0.0" + "" + ";" + "" + df.format(C.toString()));
txtintD.setText("Parabola Esterna");
}
else if (Delta == 0.0)
{
JOptionPane.showMessageDialog(null,"il delta è uguale a zero quindi due soluzioni reali e coicidenti");
Double X1 = new Double((-B)+(Math.pow(Delta, 0.5)))/(2.0*A);
Double X2 = X1;
Double YV = new Double(-(Delta)) / (4.0 * A);
Double XF = new Double(-B) / (2.0 * A);
Double XV = XF;
Double YF = new Double (-(Delta) / (4.0 * A)) + (1.0 / (4.0 * A));
Double D = new Double (-(Delta) / (4.0 * A)) - (1.0 / (4.0 * A));
txtF.setText(df.format(XF.toString()) + "" + ";" + df.format(XF.toString()));
txtV.setText(df.format(XV.toString()) + "" + ";" + df.format(YV.toString()));
txtD.setText("Y" + "" + "=" + df.format(XF.toString())+ "" + "-" + df.format(D.toString()));
txtASimm.setText("X" + "" + "=" + df.format(XF.toString()));
txtConcavita.setText("Parabola con Concavita verso l'alto");
Double AX1 = new Double (A*(Math.pow(X1, 2.0)));
Double BX2 = new Double (B*(Math.pow(X2, 1.0)));
if(B>=0 && C>=0){
txtP.setText("Y"+""+"="+df.format(AX1.toString())+""+"+"+df.format(BX2.toString())+""+"+"+df.format(C.toString()));
}else if (B>=0 && C<0){
txtP.setText("Y"+""+"="+df.format(AX1.toString())+""+"+"+df.format(BX2.toString())+""+"-"+df.format(C.toString()));
}else if(B<0 && C>=0){
txtP.setText("Y"+""+"="+df.format(AX1.toString())+""+"-"+df.format(BX2.toString())+""+"+"+df.format(C.toString()));
}
txtintX1.setText(df.format(X1.toString())+""+";"+"0.0");
txtintX2.setText(df.format(X1.toString())+""+";"+"0.0");
txtintY.setText("0.0"+""+";"+""+df.format(C.toString()));
txtintD.setText("Parabola Tagente");
}
else if(Delta > 0.0)
{
JOptionPane.showMessageDialog(null,"il delta è maggiore di zero quindi due soluzioni reali non coicidenti");
Double X1 = new Double((-B)+(Math.pow(Delta, 0.5)))/(2.0*A);
Double X2 = new Double((-B)-(Math.pow(Delta, 0.5)))/(2.0*A);
Double YV = new Double(-(Delta)) / (4.0 * A);
Double XF = new Double(-B) / (2.0 * A);
Double XV = XF;
Double YF = new Double (-(Delta) / (4.0 * A)) + (1.0 / (4.0 * A));
Double D = new Double (-(Delta) / (4.0 * A)) - (1.0 / (4.0 * A));
txtF.setText(df.format(XF.toString()) + "" + ";" + df.format(XF.toString()));
txtV.setText(df.format(XV.toString()) + "" + ";" + df.format(YV.toString()));
txtD.setText("Y" + "" + "=" + df.format(XF.toString())+ "" + "-" + df.format(D.toString()));
txtASimm.setText("X" + "" + "=" + df.format(XF.toString()));
txtConcavita.setText("Parabola con Concavita verso l'alto");
Double AX1 = new Double (A*(Math.pow(X1, 2.0)));
Double BX2 = new Double (B*(Math.pow(X2, 1.0)));
if(B>=0 && C>=0){
txtP.setText("Y"+""+"="+df.format(AX1.toString())+""+"+"+df.format(BX2.toString())+""+"+"+df.format(C.toString()));
}else if (B>=0 && C<0){
txtP.setText("Y"+""+"="+df.format(AX1.toString())+""+"+"+df.format(BX2.toString())+""+"-"+df.format(C.toString()));
}else if(B<0 && C>=0){
txtP.setText("Y"+""+"="+df.format(AX1.toString())+""+"-"+df.format(BX2.toString())+""+"+"+df.format(C.toString()));
}
txtintX1.setText(df.format(X1.toString())+""+";"+"0.0");
txtintX2.setText(df.format(X1.toString())+""+";"+"0.0");
txtintY.setText("0.0"+""+";"+""+df.format(C.toString()));
txtintD.setText("Parabola Seccante");
}
}
else
{
Double Delta = new Double (Math.pow(B, 2.0))-(4.0*(A)*(C));
if(Delta < 0.0)
{
JOptionPane.showMessageDialog(null,"il delta è minore quindi nessuna soluzione reale");
Double X1 = null;
Double X2 = null;
Double YV = new Double(-(Delta)) / (4.0 * A);
Double XF = new Double(-B) / (2.0 * A);
Double XV = XF;
Double YF = new Double (-(Delta) / (4.0 * A)) + (1.0 / (4.0 * A));
Double D = new Double (-(Delta) / (4.0 * A)) - (1.0 / (4.0 * A));
txtF.setText(df.format(XF.toString()) + "" + ";" + df.format(XF.toString()));
txtV.setText(df.format(XV.toString()) + "" + ";" + df.format(YV.toString()));
txtD.setText("Y" + "" + "=" + df.format(XF.toString())+ "" + "-" + df.format(D.toString()));
txtASimm.setText("X" + "" + "=" + df.format(XF.toString()));
txtConcavita.setText("Parabola con Concavita verso il basso");
txtintX1.setText("");
txtintX2.setText("");
if(B>=0 && C>=0){
txtP.setText("Y" + "" + "=" + df.format(A.toString()) + "" + "+" + df.format(B.toString()) + "" + "-" + df.format(C.toString()));
}else if (B>=0 && C<0){
txtP.setText("Y" + "" + "=" + df.format(A.toString()) + "" + "+" + df.format(B.toString()) + "" + "-" + df.format(C.toString()));
}else if(B<0 && C>=0){
txtP.setText("Y" + "" + "=" + df.format(A.toString()) + "" + "-" + df.format(B.toString()) + "" + "+" + df.format(C.toString()));
}
txtintY.setText("0.0" + "" + ";" + "" + df.format(C.toString()));
txtintD.setText("Parabola Esterna");
}
else if (Delta == 0.0)
{
JOptionPane.showMessageDialog(null,"il delta è uguale a zero quindi due soluzioni reali e coicidenti");
Double X1 = new Double((-B)+(Math.pow(Delta, 0.5)))/(2.0*A);
Double X2 = X1;
Double YV = new Double(-(Delta)) / (4.0 * A);
Double XF = new Double(-B) / (2.0 * A);
Double XV = XF;
Double YF = new Double (-(Delta) / (4.0 * A)) + (1.0 / (4.0 * A));
Double D = new Double (-(Delta) / (4.0 * A)) - (1.0 / (4.0 * A));
txtF.setText(df.format(XF.toString()) + "" + ";" + df.format(XF.toString()));
txtV.setText(df.format(XV.toString()) + "" + ";" + df.format(YV.toString()));
txtD.setText("Y" + "" + "=" + df.format(XF.toString())+ "" + "-" + df.format(D.toString()));
txtASimm.setText("X" + "" + "=" + df.format(XF.toString()));
txtConcavita.setText("Parabola con Concavita verso il basso");
Double AX1 = new Double (A*(Math.pow(X1, 2.0)));
Double BX2 = new Double (B*(Math.pow(X2, 1.0)));
if(B>=0 && C>=0){
txtP.setText("Y"+""+"="+df.format(AX1.toString())+""+"+"+df.format(BX2.toString())+""+"+"+df.format(C.toString()));
}else if (B>=0 && C<0){
txtP.setText("Y"+""+"="+df.format(AX1.toString())+""+"+"+df.format(BX2.toString())+""+"-"+df.format(C.toString()));
}else if(B<0 && C>=0){
txtP.setText("Y"+""+"="+df.format(AX1.toString())+""+"-"+df.format(BX2.toString())+""+"+"+df.format(C.toString()));
}
txtintX1.setText(df.format(X1.toString())+""+";"+"0.0");
txtintX2.setText(df.format(X1.toString())+""+";"+"0.0");
txtintY.setText("0.0"+""+";"+""+df.format(C.toString()));
txtintD.setText("Parabola Tagente");
}
else if(Delta > 0.0)
{
JOptionPane.showMessageDialog(null,"il delta è maggiore di zero quindi due soluzioni reali non coicidenti");
Double X1 = new Double((-B)+(Math.pow(Delta, 0.5)))/(2.0*A);
Double X2 = new Double((-B)-(Math.pow(Delta, 0.5)))/(2.0*A);
Double YV = new Double(-(Delta)) / (4.0 * A);
Double XF = new Double(-B) / (2.0 * A);
Double XV = XF;
Double YF = new Double (-(Delta) / (4.0 * A)) + (1.0 / (4.0 * A));
Double D = new Double (-(Delta) / (4.0 * A)) - (1.0 / (4.0 * A));
txtF.setText(df.format(XF.toString()) + "" + ";" + df.format(XF.toString()));
txtV.setText(df.format(XV.toString()) + "" + ";" + df.format(YV.toString()));
txtD.setText("Y" + "" + "=" + df.format(XF.toString())+ "" + "-" + df.format(D.toString()));
txtASimm.setText("X" + "" + "=" + df.format(XF.toString()));
txtConcavita.setText("Parabola con Concavita verso il basso");
Double AX1 = new Double (A*(Math.pow(X1, 2.0)));
Double BX2 = new Double (B*(Math.pow(X2, 1.0)));
if(B>=0 && C>=0){
txtP.setText("Y"+""+"="+df.format(AX1.toString())+""+"+"+df.format(BX2.toString())+""+"+"+df.format(C.toString()));
}else if (B>=0 && C<0){
txtP.setText("Y"+""+"="+df.format(AX1.toString())+""+"+"+df.format(BX2.toString())+""+"-"+df.format(C.toString()));
}else if(B<0 && C>=0){
txtP.setText("Y"+""+"="+df.format(AX1.toString())+""+"-"+df.format(BX2.toString())+""+"+"+df.format(C.toString()));
}
txtintX1.setText(df.format(X1.toString())+""+";"+"0.0");
txtintX2.setText(df.format(X1.toString())+""+";"+"0.0");
txtintY.setText("0.0"+""+";"+""+df.format(C.toString()));
txtintD.setText("Parabola Seccante");
}
}
}else
{
JOptionPane.showMessageDialog(null,"inserisci valori diversi da zero in a ");
txtA.grabFocus();
txtA.setText("");
}
}
}
sto usando il Java come linguaggio di programmazione e netbeans come abiente di lavoro. ho bisogno di finire questo programma e per farlo ho deciso di chiedere una mano in questo forum in quanto i codici che richiedo non li conosco e vorrei imparare nuove cose che mi sono neccesarie per fare un buon lavoro. oltre che mi serve una sistematina al mio codice prodotto in quanto risultano alcuni problemi che ora adro ad elencare.
1) controllare che in a,b,c l'utente inserisca qualcosa non lasci i textfield vuoti.
- Codice: Seleziona tutto
if(txtA.getText().equals("")&& txtB.getText().equals("") && txtC.getText().equals("")){
JOptionPane.showMessageDialog(null,"inserisci i valori richiesti in a,b e c");
}else if(txtA.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"inserisci il valore richiesto in a");
}
else if(txtB.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"inserisci il valore richiesto in b");
}
else if(txtC.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"inserisci il valore richiesto in b");
}else if( txtA.getText().equals("") || txtC.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"inserisci il valori mancanti soprattutto in a");
}
else if( txtA.getText().equals("") || txtB.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"inserisci il valori mancanti soprattutto in a");
}else if( txtB.getText().equals("") || txtC.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"inserisci il valori mancanti ....");
}
else if( txtA.getText().equals("") && txtC.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"inserisci il valori mancanti in a e c");
}
else if( txtA.getText().equals("") && txtB.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"inserisci il valori mancanti in a e b");
}else if( txtB.getText().equals("") && txtC.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"inserisci il valori mancanti in b e c");
}
non mi funzionano i messaggi che ho inserito in quanto se faccio un test non mi esce il joptionpane ma in output dei messaggi d'errore invece di eseguire la mia mascherina grafica. perchè? come risolvo?
2)
- Codice: Seleziona tutto
DecimalFormat df = new DecimalFormat("###,###,###,###.###");
come potete vedere in tutto il listato ho usato il decimal format. perchè cerco un modo per far in modo che invece di avere risultati con decimali lunghi avvolte indecrifrabili in quanto escono le annotazioni scietifiche o risultati tipo 0.999999994439923929 e comunque vorrei che uscisse fuori una separazione anche per migliaia come questa 1.000 anche se esce un numerone che tocca i migliardi e infine al massimo due decimali. ma facendo un test mi esce fuori dei errori in output al posto della maschera grafica che mi dice impossibile formatare i numeri. perchè? come risolvo? e possibile scrivere un risultato numerico come questo: 1.000.000.000,00
dopo aver risolto questi problemi vorrei il codice che faccia visualizzare in modo grafico una parabola data da tutti i risultati prodotti dai codici precendenti in automatico. mi piacerebbe visualizare tramite non so cosa forse una label un disegno con dei cerchi a sfondo rosso gli eventuali punti di insercazione con gli assi cartesiani, in blu gli eventuali/l'eventuale punti/punto d'insersecazione con la direttrice, in verde il fuoco, in giallo il vertice, la parabola di colore arancione, gli assi marroni, la diretrice in viola e in nero l'asse di simmetria della parabola. come si fa? i colori indicati sono indicati messi a caso l'importante è il codice perchè poi a mo gusto cambio io i colori.
ditemi anche se manca qualche controllo se ci sono errori di logica e sintassi e c'è da aggiungere qualcosa altro per rendere tale programma completo e perfetto.