Question programmation JAVA
Résolu
tom818
-
tom818 Messages postés 19 Date d'inscription Statut Membre Dernière intervention -
tom818 Messages postés 19 Date d'inscription Statut Membre Dernière intervention -
A voir également:
- Question programmation JAVA
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel - Télécharger - Jeux vidéo
- Eclipse java - Télécharger - Langages
- Java apk - Télécharger - Langages
- Waptrick java voiture - Télécharger - Jeux vidéo
5 réponses
Salut !
Voila un exemple pour ta première question:
public class Main
{
private static boolean correct = false;
public static void main(String[] args)
{
String password = "blabl";
correct = verifierPassword(password);
if(correct)
System.out.println("Le mot de passe est correct.");
else
{
System.out.println("Le mot de passe est incorrect.\n");
if(password.length() < 7)
System.out.println("Il vous manque " + (7 - password.length() + " caractères"));
else
System.out.println("Vous avez " + (password.length() - 15) + " caractères en trop");
}
}
public static boolean verifierPassword(String password)
{
boolean vrai = false;
if(password.length() < 7 || password.length() > 15)
vrai = false;
else
{
vrai = true;
return vrai;
}
return vrai;
}
}
Tu n'a qu'à changer la valeur de la String password pour tester le programme.
Pour ton deuxième exercice, je ne savais pas trop ce à quoi tu voulais en venir, mais bon, j'ai fait quelque chose selon ce que j'ai compris, en esperant que j'étais sur la bonne piste...
Deuxième question :
import javax.swing.JOptionPane;
public class Main
{
public static void main(String[] args)
{
execution();
}
public static void execution()
{
String prenom = "";
String nom = "";
String finale = "";
String lettre1, lettre2;
prenom = JOptionPane.showInputDialog(null, "Quel est votre prénom?", "Prénom", JOptionPane.QUESTION_MESSAGE);
nom = JOptionPane.showInputDialog(null, "Quel est votre nom?", "Nom", JOptionPane.QUESTION_MESSAGE);
lettre1 = prenom.substring(0, 1);
lettre2 = nom.substring(0, 1);
finale = lettre1 + lettre2 + "-";
System.out.println(finale);
}
}
Voial, au plaisir d'avoir peut-etre aidé...
Au plaisir,
maxmethot
Voila un exemple pour ta première question:
public class Main
{
private static boolean correct = false;
public static void main(String[] args)
{
String password = "blabl";
correct = verifierPassword(password);
if(correct)
System.out.println("Le mot de passe est correct.");
else
{
System.out.println("Le mot de passe est incorrect.\n");
if(password.length() < 7)
System.out.println("Il vous manque " + (7 - password.length() + " caractères"));
else
System.out.println("Vous avez " + (password.length() - 15) + " caractères en trop");
}
}
public static boolean verifierPassword(String password)
{
boolean vrai = false;
if(password.length() < 7 || password.length() > 15)
vrai = false;
else
{
vrai = true;
return vrai;
}
return vrai;
}
}
Tu n'a qu'à changer la valeur de la String password pour tester le programme.
Pour ton deuxième exercice, je ne savais pas trop ce à quoi tu voulais en venir, mais bon, j'ai fait quelque chose selon ce que j'ai compris, en esperant que j'étais sur la bonne piste...
Deuxième question :
import javax.swing.JOptionPane;
public class Main
{
public static void main(String[] args)
{
execution();
}
public static void execution()
{
String prenom = "";
String nom = "";
String finale = "";
String lettre1, lettre2;
prenom = JOptionPane.showInputDialog(null, "Quel est votre prénom?", "Prénom", JOptionPane.QUESTION_MESSAGE);
nom = JOptionPane.showInputDialog(null, "Quel est votre nom?", "Nom", JOptionPane.QUESTION_MESSAGE);
lettre1 = prenom.substring(0, 1);
lettre2 = nom.substring(0, 1);
finale = lettre1 + lettre2 + "-";
System.out.println(finale);
}
}
Voial, au plaisir d'avoir peut-etre aidé...
Au plaisir,
maxmethot
Ahhh c'est du JavaScript que tu voulais et non du Java tout court, ca fallais le préciser ! ^^
Dans ton code, y'a d'la répétition...essaye plutot ca:
<SCRIPT
language="JavaScript"
type="text/javascript">
var customer;
customer = window.prompt('Please enter 1 to register as a new customer or 2 for estabisched customer','');
while(customer != 1 || customer != 2)
{
if (customer == 1)
{
document.write('<BR>' + 'WELCOME – WE WILL SET UP YOUR ACCOUNT DETAILS NOW')
}
else if (customer == 2)
{
document.write('<BR>' + 'SHOP UNTIL YOU DROP')
}
else
{
document.write('<BR>' + 'Try again')
window.prompt('Please enter 1 to register as a new customer or 2 for estabisched customer','');
}
maxmethot
Dans ton code, y'a d'la répétition...essaye plutot ca:
<SCRIPT
language="JavaScript"
type="text/javascript">
var customer;
customer = window.prompt('Please enter 1 to register as a new customer or 2 for estabisched customer','');
while(customer != 1 || customer != 2)
{
if (customer == 1)
{
document.write('<BR>' + 'WELCOME – WE WILL SET UP YOUR ACCOUNT DETAILS NOW')
}
else if (customer == 2)
{
document.write('<BR>' + 'SHOP UNTIL YOU DROP')
}
else
{
document.write('<BR>' + 'Try again')
window.prompt('Please enter 1 to register as a new customer or 2 for estabisched customer','');
}
maxmethot
Merci,
mais voici l'énnoncé de la question et comme tu as fait c'est une boucle et je n'en sortirais jamais.
write a JavaScript program that prompts the user to enter 1 if they want to register as a new customer; and 2 if they are an established customer. If the user inputs anything other than 1 or 2, the system prompts them to try again. Do not use a loop: if the input is still not valid after two tries, the program does not produce any output.
Once a user has successfully entered 1 or 2, your system should print a welcome message. New customers should get the message “WELCOME – WE WILL SET UP YOUR ACCOUNT DETAILS NOW”; established customers will just get the message “SHOP UNTIL YOU DROP”.
mais voici l'énnoncé de la question et comme tu as fait c'est une boucle et je n'en sortirais jamais.
write a JavaScript program that prompts the user to enter 1 if they want to register as a new customer; and 2 if they are an established customer. If the user inputs anything other than 1 or 2, the system prompts them to try again. Do not use a loop: if the input is still not valid after two tries, the program does not produce any output.
Once a user has successfully entered 1 or 2, your system should print a welcome message. New customers should get the message “WELCOME – WE WILL SET UP YOUR ACCOUNT DETAILS NOW”; established customers will just get the message “SHOP UNTIL YOU DROP”.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
bonjour, voici la solution,
j'oubliais de réatribuer la valeur à customer en seconde partie.
Voici le code:
<HTML>
<HEAD> M150 TMAO3 Question 1
<TITLE>SOFASPEND - IN THE BEST POSSIBLE TASTE!</TITLE>
<SCRIPT
language="JavaScript"
type="text/javascript">
var customer;
customer = window.prompt('Please enter 1 to register as a new customer or 2 for estabisched customer','');
if (customer == 1)
{
document.write('<BR>' + 'WELCOME – WE WILL SET UP YOUR ACCOUNT DETAILS NOW')
}
else
{
if (customer == 2)
{
document.write('<BR>' + 'SHOP UNTIL YOU DROP')
}
else
{
document.write('<BR>' + 'Try again')
customer = window.prompt('Please enter 1 to register as a new customer or 2 for estabisched customer','');
if (customer == 1)
{
document.write('<BR>' + 'WELCOME – WE WILL SET UP YOUR ACCOUNT DETAILS NOW')
}
else
{
if (customer == 2)
{
document.write('<BR>' + 'SHOP UNTIL YOU DROP')
}
}
}
}
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
j'oubliais de réatribuer la valeur à customer en seconde partie.
Voici le code:
<HTML>
<HEAD> M150 TMAO3 Question 1
<TITLE>SOFASPEND - IN THE BEST POSSIBLE TASTE!</TITLE>
<SCRIPT
language="JavaScript"
type="text/javascript">
var customer;
customer = window.prompt('Please enter 1 to register as a new customer or 2 for estabisched customer','');
if (customer == 1)
{
document.write('<BR>' + 'WELCOME – WE WILL SET UP YOUR ACCOUNT DETAILS NOW')
}
else
{
if (customer == 2)
{
document.write('<BR>' + 'SHOP UNTIL YOU DROP')
}
else
{
document.write('<BR>' + 'Try again')
customer = window.prompt('Please enter 1 to register as a new customer or 2 for estabisched customer','');
if (customer == 1)
{
document.write('<BR>' + 'WELCOME – WE WILL SET UP YOUR ACCOUNT DETAILS NOW')
}
else
{
if (customer == 2)
{
document.write('<BR>' + 'SHOP UNTIL YOU DROP')
}
}
}
}
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
1.
Make a copy of the file prog1.html and rename it prog2.html
Amend this file to include code for the entry of customer details. Individuals starting a new account must enter the following data: first name, second name and a password of their own choice.
Passwords must be at least 7, and no more than 15, characters long (there is no restriction on the type of characters allowed). If users enter a password that is invalid according to this rule then the program displays an explanatory message, telling the user how many characters the password entered actually had, and prompts them repeatedly until a valid password is entered.
2.
Make a copy of the file prog2.html and rename it prog3.html.
Amend this file so that your program allocates the new customer a customer code. The customer code is a string made up of the first letter of the first name, plus the first letter of the second name, and a dash. Thus, a customer with the following details:
First name: Orson
Second name: Welles
Password: CitizenKane
will have the customer code:
OW-
Your program should write the first name, the second name and the customer code to the screen.
et voici le code de prog1.html
Mais j'ai un problème dedans et je ne le trouve pas, si j'entre autre chose que 1 ou 2 lors de la première fenêtre il me met bien try again et m'ouvre une seconde fenêtre et la si j'entre 1 ou 2 il ne me met rien. pouriez vous m'aidez.
<SCRIPT
language="JavaScript"
type="text/javascript">
var customer;
customer = window.prompt('Please enter 1 to register as a new customer or 2 for estabisched customer','');
if (customer == 1)
{
document.write('<BR>' + 'WELCOME – WE WILL SET UP YOUR ACCOUNT DETAILS NOW')
}
else
{
if (customer == 2)
{
document.write('<BR>' + 'SHOP UNTIL YOU DROP')
}
else
{
document.write('<BR>' + 'Try again')
window.prompt('Please enter 1 to register as a new customer or 2 for estabisched customer','');
if (customer == 1)
{
document.write('<BR>' + 'WELCOME – WE WILL SET UP YOUR ACCOUNT DETAILS NOW')
}
else
{
if (customer == 2)
{
document.write('<BR>' + 'SHOP UNTIL YOU DROP')
}
}
}
}
</SCRIPT>