Hello guys,
Please, follow the new thread in the post with my new question. I modified the post, following the rules of the forum
I will appreciate any help
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hello guys,
Please, follow the new thread in the post with my new question. I modified the post, following the rules of the forum
I will appreciate any help
Last edited by chucho11028; May 9th, 2020 at 12:18 PM.
Please copy the full text of the error message and paste it here. It has important info about the error.I get an error,
The code must handle all values returned by the showInputDialog method, including null.
What should the program do if the user cancels the dialog?
If you don't understand my answer, don't ignore it, ask a question.
Hello everyone
I have edit my post because I have tried something else
I have a main class where I have asking to introduce some values
In teh second class I use this values to provide an answer
So, in the main class maincoche.java I use JOptionPane to introduce an String value
it should be si or SI or Si, etc (yes). This value is sent to a SETTER in a second class named coche.java, the setter name is config_seats(String asientos_cuero) which receive teh string value
Here I add the value
mifurgoneta.config_seats(JOptionPane.showInputDialog("Tiene asientos de cuero")); System.out.println(mifurgoneta.get_asientos());
here is my setter
public void config_seats(String asientos_cuero) { //do{ if (asientos_cuero.equalsIgnoreCase("si") || asientos_cuero.equalsIgnoreCase("s")) { this.asientos_cuero = true; } else { this.asientos_cuero = false; } //}while(!asientos_cuero.equalsIgnoreCase("si") || !asientos_cuero.equalsIgnoreCase("s")); }
So my question is:
How can I use a do-while in order to repeat the code if I introduce a wrong value differnet to (si or SI or Si)?
the condition IF only handle the case sensitive for si but I think I need do - while in case I introduce any other character like sdjdjsdh or 17261 or cancel.
when I use the do-while the program doesn't print the value and keep runing without any action. It is like I can not validate something coming from anotehr class
Here you have the complete code
main class
package poo; import javax.swing.*; public class maincoche { public static void main(String[] args) { // TODO Auto-generated method stub //sintaxis clase + name_oF_object + new constructor coche micoche1 = new coche(); micoche1.establece_color("Rojo"); //sintaxis clase + name_oF_object + new constructor furgoneta mifurgoneta = new furgoneta(7,1000); mifurgoneta.establece_color(JOptionPane.showInputDialog("Cual es el color :")); System.out.println(mifurgoneta.dime_color()); mifurgoneta.config_seats(JOptionPane.showInputDialog("Tiene asientos de cuero")); System.out.println(mifurgoneta.get_asientos()); /* coche micoche = new coche(); micoche.establece_color(JOptionPane.showInputDialog("Introduce color")); System.out.println(micoche.provide_generaldata()); System.out.println(micoche.dime_color()); micoche.config_seats(JOptionPane.showInputDialog("Tiene asientos de cuero?")); System.out.println(micoche.get_asientos()); micoche.conf_climatizador(JOptionPane.showInputDialog("Tiene climatizador?")); System.out.println(micoche.get_climatizador()); */ } }
second class
package poo; public class coche { //the key private encapsula las propiedades para que no sean modificadas desde otra calse private int ruedas; private int largo; private int ancho; private int motor; private int peso_plataforma; private String color1; private String color; private int peso_total; boolean asientos_cuero, climatizador; //constructor public coche() { ruedas=4; largo=2000; ancho=300; motor=1600; peso_plataforma=500; } //metodo getter obtain value propertie //sintaxis es Public + tipodedato + nameofmethod() + usa return public String provide_generaldata() { return "El coche tiene: " + ruedas + " ruedas" + " Con un largo de " + largo/1000 + " metros " + " y peso de " + peso_plataforma + " kg"; } //************************************** //method setter public void set_color() { color1= "rojo"; } //method getter public String provide_color() { return "El color is: " + color1; } //******************************8 //setters modifica valor propiedades //sintaxis public+void+nombre_method no usa return public void establece_color(String color_coche) { color=color_coche; } //method getter public String dime_color() { return "El color del coche es : " + color; } //setter public void config_seats(String asientos_cuero) { //do{ if (asientos_cuero.equalsIgnoreCase("si") || asientos_cuero.equalsIgnoreCase("s")) { this.asientos_cuero = true; } else { this.asientos_cuero = false; } //}while(!asientos_cuero.equalsIgnoreCase("si") || !asientos_cuero.equalsIgnoreCase("s")); } //getter public String get_asientos() { if(asientos_cuero==true) { return "el coche tiene asientos de cuero"; } else { return "no tiene cuero"; } } public void conf_climatizador(String climatizador) { if(climatizador.equalsIgnoreCase("si") || climatizador.equalsIgnoreCase("s")) { this.climatizador = true; } else { this.climatizador = false; } } public String get_climatizador() { if(climatizador==true) { return "el coche tiene climatizador"; } else { return "no tiene climatizador"; } } }
Last edited by chucho11028; May 9th, 2020 at 12:16 PM. Reason: I got a new approach to find my solution
Did you try adding code to handle what is returned by the showInputDialog method?
Please edit your post and wrap your code with code tags:
[code]
**YOUR CODE GOES HERE**
[/code]
to get highlighting and preserve formatting.
If you don't understand my answer, don't ignore it, ask a question.