Objetos en java
Publicado por Gaby (3 intervenciones) el 07/10/2019 00:28:06
Quiero llamar un objeto de una clase y me sale este error:
javac Racional.java
Racional.java:129: error: cannot find symbol
suma = sum.operacionRacional();
^
symbol: method operacionRacional()
location: variable sum of type operacionRacional
1 error
mi còdigo es este:
y al que quiero llamar es este:
javac Racional.java
Racional.java:129: error: cannot find symbol
suma = sum.operacionRacional();
^
symbol: method operacionRacional()
location: variable sum of type operacionRacional
1 error
mi còdigo es este:
1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import java.util.Scanner;
public class Racional{
private static double num;
private static double den;
private static double cociente;
private static double a1;
private static double a2;
private static double b1;
private static double b2;
private static double c1;
private static double c2;
double numMul;
double denMul;
double q;
double r;
public double inversoAditivo (){
double numAd;
numAd = -1 * num;
return numAd;
}
public double inversoMultiplicativo (){
double numMul;
double denMul;
numMul = den;
denMul = num;
return numMul;
}
public double simplifica() {
while (num % den != 0){
r = num % den;
num = den;
den = r;
}
return den;
}
public double muestraRacional(){
cociente = num / den;
return cociente;
}
public static void main(String[] args) {
Scanner teclado = new Scanner(System.in);
Racional inverso = new Racional();
Racional multi = new Racional();
Racional simple = new Racional();
Racional muestraRac = new Racional();
operacionRacional sum = new operacionRacional();
double nuevoNum;
double multiplicativo;
double numSimple;
double muestra;
double suma;
int opcion;
int seguir=1;
do {
System.out.println("\nELIGE LA OPERACIÓN A REALIZAR\n\n1.\tINVERSO ADITIVO\n2.\tINVERSO MULTIPLICATIVO\n3.\tSIMPLIFICA\n4.\tMOSTRAR RACIONAL\n5.\tSUMA\n6.\tRESTA\n7.\tMULTIPLICACIÓN\n8.\tDIVISIÓN\n9.\tIGUAL\n0.\tSALIR");
opcion = teclado.nextInt();
switch (opcion) {
case 1:
System.out.print("Ingresa el numerador: ");
num = teclado.nextDouble();
System.out.print("Ingresa el denominador: ");
den = teclado.nextDouble();
nuevoNum = inverso.inversoAditivo();
System.out.println("El inverso aditivo es: " + nuevoNum + " / " + den);
System.out.println("\nDESEAS REALIZAR OTRA OPERACIÓN?\n1. SI\n2. NO\n");
seguir = teclado.nextInt();
break;
case 2:
System.out.print("Ingresa el numerador: ");
num = teclado.nextDouble();
System.out.print("Ingresa el denominador: ");
den = teclado.nextDouble();
multiplicativo = multi.inversoMultiplicativo();
if (num > 0) {
System.out.println("El inverso multiplicativo es: " + multiplicativo*-1 + " / " + num);
}
else {
System.out.println("El inverso multiplicativo es: " + multiplicativo + " / " + (num*-1));
}
System.out.println("\nDESEAS REALIZAR OTRA OPERACIÓN?\n1. SI\n2. NO\n");
seguir = teclado.nextInt();
break;
case 3:
System.out.print("Ingresa el numerador: ");
num = teclado.nextDouble();
System.out.print("Ingresa el denominador: ");
den = teclado.nextDouble();
numSimple = simple.simplifica();
System.out.println("Número racional simplificado: " + num/numSimple + "/" + den/numSimple);
System.out.println("\nDESEAS REALIZAR OTRA OPERACIÓN?\n1. SI\n2. NO\n");
seguir = teclado.nextInt();
break;
case 4:
System.out.print("Ingresa el numerador: ");
num = teclado.nextDouble();
System.out.print("Ingresa el denominador: ");
den = teclado.nextDouble();
muestra = muestraRac.muestraRacional();
System.out.println("El cociente de " + num + " / " + den + " = " + muestra);
System.out.println("\nDESEAS REALIZAR OTRA OPERACIÓN?\n1. SI\n2. NO\n");
seguir = teclado.nextInt();
break;
case 5:
System.out.print("Ingresa el numerador: ");
num = teclado.nextDouble();
System.out.print("Ingresa el denominador: ");
den = teclado.nextDouble();
suma = sum.operacionRacional();
System.out.println("\nDESEAS REALIZAR OTRA OPERACIÓN?\n1. SI\n2. NO\n");
seguir = teclado.nextInt();
}
} while (opcion != 0 && seguir != 2);
System.out.println("\n********* H A S T A P R O N T O ! *********");
}
}
y al que quiero llamar es este:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.util.Scanner;
public class operacionRacional{
//ATRIBUTOS
private static double a1;
private static double a2;
private static double b1;
private static double b2;
private static double c1;
private static double c2;
//CONSTRUCTOR (inicializar variables)
operacionRacional(double a, double b){
//ATRIBUTOS
this.a1 = a1;
this.a2 = a2;
this.b1 = b1;
this.b2 = b2;
}
//MÉTODO
public double sumar () {
this.c1 = (this.a1 * this.b2)+(this.a2 * this.b1);
this.c2 = this.a1 * this.a2;
return this.c1;
// return this.c2;
}
// public double restar () {
// this.c = this.a - this.b;
// return this.c;
// }
// public double multiplicar () {
// this.c = this.a * this.b;
// return this.c;
// }
// public double dividir () {
// this.c = this.a / this.b;
// return this.c;
// }
}
Valora esta pregunta


0