Answer the question
In order to leave comments, you need to log in
Is it worth continuing to learn java?
The girl is fond of programming in java.
Here is an example of her code:
package Tetrahedron;
import java.io.IOException;
import java.lang.Math;
import java.io.BufferedReader;
import java.io.InputStreamReader;
class YslovieA4 {
double u1, u2, u3;
YslovieA4(double uk1, double uk2, double uk3){
u1=uk1; u2=uk2; u3=uk3;
}
double maxABBC(){
return u1+u2;
}
double minBCAB(){
return Math.abs(u2-u1);
}
boolean provNorm () {
if((minBCAB()<u3)&(u3<maxABBC())) return true;
else return false;
}
}
public class Tetra_6 {
public static void main (String args []) throws IOException {
BufferedReader n = new BufferedReader(new InputStreamReader(System.in)) ;
System.out.print("Вводим длины сторон треугольника в основании тетраэдра ABCD, больше 0.\n" +
"AB = ");
String ABs=n.readLine();
double AB=Double.parseDouble(ABs);
System.out.print("\nBC = ");
String BCs=n.readLine();
double BC=Double.parseDouble(BCs);
boolean norm, norm2; double AC;
do {System.out.print("\nAC = ");
String ACs=n.readLine();
AC=Double.parseDouble(ACs);
YslovieA4 Y1=new YslovieA4(AB, BC, AC);
norm=Y1.provNorm();
if(norm);
else System.out.println("Увы, так не получится: с вырожденным" +
" треугольником тетраэдр не сделать.\nСторона AC должна быть больше "+Y1.minBCAB()+
" и меньше "+Y1.maxABBC());
}while (!norm);
System.out.println("Proshlo");
System.out.println("AC = "+AC);
System.out.print("Отлично, теперь займемся другими гранями:\n" +
"AD = ");
String ADs=n.readLine();
double AD=Double.parseDouble(ADs),
BD;
do{System.out.print("\nBD = ");
String BDs=n.readLine();
BD=Double.parseDouble(BDs);
YslovieA4 Y2=new YslovieA4(AD, AB, BD);
norm=Y2.provNorm();
if(norm);
else System.out.println("Увы, так не получится: с вырожденным" +
" треугольником тетраэдр не сделать.\nСторона BD должна быть больше "+Y2.minBCAB()+
" и меньше "+Y2.maxABBC());
}while (!norm);
System.out.println("Proshlo");
System.out.println("BD = "+BD);
System.out.print("И, наконец, последнее ребро");
double CD;
do { System.out.print("\nCD = ");
String CDs=n.readLine();
CD=Double.parseDouble(CDs);
YslovieA4 Y3 = new YslovieA4(AC, AD, CD);
YslovieA4 Y4 = new YslovieA4(BC, BD, CD);
Double provCDmax3=Y3.maxABBC(),
provCDmax4=Y4.maxABBC(),
CDmaxRes=Math.min(provCDmax3, provCDmax4),
provCDmin3=Y3.minBCAB(),
provCDmin4=Y4.minBCAB(),
CDminRes=Math.max(provCDmin3, provCDmin4);
if(CDminRes<CD & CD<CDmaxRes) norm2=true;
else { System.out.println("Увы, так не получится: с вырожденным" +
" треугольником тетраэдр не сделать.\nСторона CD должна быть больше "+CDminRes+
" и меньше "+CDmaxRes);
norm2=false;}
} while(!norm2);
System.out.println("Proshlo");
System.out.println("CD = "+CD);
double a=BD, b=AD, c=AB,
q=((a*a+c*c-b*b)/(2*a*c)),
radABD=Math.acos(q),
gradABD=Math.toDegrees(radABD);
b=CD; c=BC;
q=((a*a+c*c-b*b)/(2*a*c));
double radDBC=Math.acos(q),
gradDBC=Math.toDegrees(radDBC);
System.out.println ("Угол AВD = "+gradABD);
System.out.println ("Угол DBC = "+gradDBC);
double p=((AB+BC+AC)/2),
s=p*(p-AB)*(p-BC)*(p-AC),
S=Math.sqrt(s);
System.out.println("Площадь треугольника ABC = "+S+"см2");
if(gradABD==90 & gradDBC==90) { double VT=S*BD/3;
System.out.println("Объем тетраэдра = "+VT+"см3");}
else if(gradABD>90) gradABD=180-gradABD;
else; //будет убран после проверки!!!
if (gradDBC>90) gradDBC=180-gradDBC;
radDBC=Math.toRadians(gradDBC);
double sinDBC=Math.sin(radDBC),
f=BD*sinDBC,
sinABD=Math.sin(radABD),
h=f*sinABD;
System.out.println("Высота Т. = "+h);
/*double gradK=90-gradABD,
radK=Math.toRadians(gradK),
sinK=Math.sin(radK),
g=f*sinK,
S2=(h*g)/2;
System.out.println("Катет на основании = "+g);
System.out.println("Площадь второго для проверки = "+S2);*/
double VT=S*h/3;
System.out.println("Объем тетраэдра = "+VT);
}
}
Answer the question
In order to leave comments, you need to log in
Let him try the IDEA(community) environment. It will help you form the habit of good code formatting.
It is better for a girl to give birth to a child and take care of a family.
It seems to me that the problem is not in the language as such. You can read McConnell's "Perfect Code" - it will give an understanding of how to correctly divide the program into layers / blocks (principles of KISS, DRY), good naming of methods / variables, etc.
I would give a couple of problems in functional / logical languages. Some kind of List/Prolog/Haskel/Erlang. But not a small one that describes the language, but something from real life.
This should clean up the structure of the code, and force more time to decompose.
Here's a slightly edited version. The code is formatted. A huge main method that did everything and immediately broke it into pieces. The code has become a little more, but it is easier to understand. It still has a lot of copy-paste (duplication of code sections with minimal differences).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question