javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

thanx for ur responses,apreciate

<%@ page import="java.util.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="hi" %>
<HTML>
<BODY>
<jsp:useBean id="my" scope="request" class="hi">
<jsp:getProperty name="my" property="*"/>
</jsp:useBean>
<%my.print()%;>
</BODY>
</HTML>

i've changed my code as u specified but i've got the following error

org.apache.jasper.JasperException: /date.jsp(9,2) Unterminated &lt;% tag
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:132)
org.apache.jasper.compiler.Parser.parseScriptlet(Parser.java:771)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1437)
org.apache.jasper.compiler.Parser.parse(Parser.java:138)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:239)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:197)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:365)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:345)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:341)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:332)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
thanx

Apparently you ignored the answer that I gave you at your other double post and at this one. Other people cared to give you the answer. Did you bother reading it?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You posted the same exact question in a previous thread, which you got an answer. I don't know if it was the right one, but nevertheless, if you had problems you should have posted at the same thread.

And parry_kulk, I believe that you also missed that in his jsp page:

<%my.print()%;>
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Take a look at this:

<%my.print()%;>

The quote is in the wrong place. The idea is that you write java code inside the <% .. %>

Inside a JSP page:

<%
int a = 0;
a = my.print();
%>

<!-- This is not java. It is displayed at the page: -->
Result: <%= a %>

<!-- OR -->
Result: <%= my.print() %>
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you put the mysql-connector-java-5.0.8-bin.jar at the classpath ?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You want that other "Button 4" to have a different functionality or simply change its label.
For changing label use the set methods of the JButton class API.

For changing the button, you can try to look at the API of JButton, if it has a setVisible method.
You can have both buttons placed at that location but one would be hidden. When you click the "1" you can hide that and make the "4" visible.
Like I said in order for that to work you need to look at the API. I am not sure if it can be done

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You must always check if those values are null or not.
When you first go to that page, they are null, since you didn't submit anything.
After you check that they are not null, then do whatever validations you want.
I would suggest to use only one, the user for example. If it is not null, it means that the others were given as well.
Also for the radio button if don't select anything it submits null, so you can use that to check if the user hasn't entered anything. And add the value attribute to the radio button.


And lastly the best way to do those kinds of validations (if the user has entered empty values) use javascript:
http://www.w3schools.com/default.asp

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You can use this:
<jsp:forward page="successpage.jsp" />

<% 
if (pswrd1!=null && pswrd2!=null) {	 
  if (!pswrd1.equals(pswrd2)) { 
%>
     <%@ include file="errorpage.html" %>
<%
  } else {
%>
     <jsp:forward page="successpage.jsp" />
<%
  }
} 
%>
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The method str.charAt(i) that you are calling returns a char. Why don't you assign that call to a char variable and print that char.
You can also call the toCharArray method:

String s = "1234";
char [] ch = s.toCharArray();

// Now print the elements of the ch array.
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This is java:

if ( !("pass2").equals("pass2") ) {

}

Try to run that code and see what happens. The "pass2" string will always be equal to "pass2" string.
You write: "pass2".equals("pass2") . Those are fixed values and it is always true. And the ! will always make it false.

You need to get values from request. When you submit to a page use these methods to get the values from request.

<%
String password1 = request.getParameter("pass1"); // pass1 is the name of the input tag
String password2 = request.getParameter("pass2");

// check if the page has been submitted:
if (password1!=null && password2!=null) {
    
   // check if they are equal:
   if (!password1.equals(password2)) {
%>
     <%@ include file="errorpage.html" %>
<%
   }
}
%>

The first time you go to that page for the user to enter the values, the request is empty, so the password1, password2 would be null and the validation will not take place. But when you submit, you will send the pass1, pass2 values of the input fields and you will do the validation. I trust that exer02-b.jsp is the file that you posted. Remember the page that you enter at the action attribute of the form is where the values are sent.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

There aren't any default databases. You can use whatever you want with jsp, depending on the application.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can you be more specific in what way you will put them onto a website? Usually you something onto a website that has a GUI (Graphics user interface)
How will the console application run on the net?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

That would depend on the page. There is no way of doing, if you don't know the code of the page. If you want to login then the url mustn't be one of the main page but the page that it submits to with arguments the username and password. Although putting the password directly in the URL is a bad idea since it is visible.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can u tell me the formula or the key word that make me understand than this?

You posted 4 questions. Where are you having problems? There is no keyword for all of them. About the 1st, don't you know how to initialize variables? Ask specific questions.

Study and then tell use what you don't understand

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Look at your Songs constructor. The error is there.
Also besides the error, why do you call the toString method in the constructor? It doesn't do anything.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Whether you are professional or student is irrelevant. The fact that you are new in Java means that this is too much for you. No one that is new in Java can deliver what you have been asked to do. What you have been asked is not for beginners.

I am not the best in java but not a beginner either. But I don't know how to do this and if I had to, I would do a lot of search and studying. There are many examples and tutorials and libraries that do what you want with little code and effort on your behalf.

Start searching and coding.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Do you use in your code one of those methods:
kb.nextInt() or kb.next() perhaps?

The solution is very simple, but first let us know if the above is true and what other methods of the scanner class do you use.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Read this post:
http://www.daniweb.com/forums/thread327418.html
And it is against the rules to post your mail and ask for people to send you the code there.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

One small advice. You do this in a lot of places in your program:

ArrayList<Double> studentScores = new ArrayList<Double>();
studentScores = gradeBook.get(indexOfStudent);

It is not necessary. What you actually do is create a new ArrayList<Double>. A new instance of ArrayList<Double> in memory. And then you never use it. You simply replace the reference studentScores with the one inside the gradeBook. The first ArrayList<Double> created goes unused.
It is simpler to do this:

ArrayList<Double> studentScores = gradeBook.get(indexOfStudent);

Of course if you want to add a new student you correctly create a new ArrayList<Double>, but when you have found the indexOfStudent then can take it from the gradeBook. The addScore method is ok.

But for the other methods it would be safer to add this:

public double individualSum(String name)
    {
        int indexOfStudent = 0;
        indexOfStudent = students.indexOf(name);

        if (indexOfStudent==-1) {
          System.out.println("Student: "+name+" not found");
          return -1;
        }
  
        double sum = 0.0;
        ArrayList<Double> studentScores = gradeBook.get(indexOfStudent);

        for(int i = 0; i < studentScores.size(); i++)
        {
            sum += studentScores.get(i);
        }

        return sum;
    }
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

develop a program to accept a sentence then display the word in reverse form. take note that a sentence should start w/ a capital letters and ends w/ a period. Further , count the total number of words and total number A's - Z's and a's - z's implement using JOptionPane


sample

input : you're cool.


output:


cool you're.

total: 2

A: 0 a=1
B:0 b=0
.... ...
........
.. ....
Z=0 z=0

Start a new thread, show some effort and use the split(" ") method of the String class. Print the array that it returns:

String input = "you're cool";
String [] arr = input.split(" ");
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The for loop should start at i=0. Print the all elements of the array. You call the dump twice with 2 different calls of the split method. Print the data of the array and then decide which split call suits you better and which element of the array holds the $1500.

Try this:

public void dump(String []s) { 
  System.out.println("Calling dump");
  for (int i = 0; i < s.length ; i++) { 
   System.out.println(i+":"+s[i]); 
  } 
  System.out.println("------------");
}

And see what gets printed.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi Koushik,

Below code is to set the session

//This code goes in server side (servlet).

HttpSession session = request.getSession(true); //create a session object
 session.setAttribute("key", "value");

//This code goes in client side (jsp).

// this will return the value in session
 String value=(String) session.getAttribute("key");

After getting the session value set it to first combo box in onLoad intself

we can also use the ajax to solve ur problem.

That is not the right way to use session. You shouldn't be putting things in the session for a simple submit or refresh page.

koushikroy1989, I assume that you submit the value of the first drop down list and then you load values to the second. If so, when you "send" the data of the second drop down list you can also send the value of the first drop down list and have that value selected.

Post some code so we can see how you send the data and how you load the second drop down list.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Actually the code that you wrote is logically wrong. If you don't want to redirect then the searchTerm must be null OR searchTerm.length==0. not AND
You will not get a NullPointerException if you write it correctly:

if (searchTerm == null || searchTerm.length() == 0) {
  // don't redirect.
}

That is the opposite of my if.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The error says: "non-static variable MainList" I assume that MainList is non static, so in order to access you need to have an instance of the class MainScreen

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Delete everything you have written.
Start by studying html, because your tags are wrong.

Then put the "database" code in a separate method that returns a list with the values from the DB. Better create a class with attributes ID and NAME and return a list of that object. In that method you MUST close the connection, the statement, and the ResultSet.

Never write html code in a servlet. Create a JSP file and call that method in that jsp and take the list with the data from the DB. Don't mix database with presentation. One method returns the data, then you get to call that method from wherever you want. In this case you call it from the JSP and dislay that data.

You will need to learn about scriplets. Assuming that you have a class called Product with attributes ID and NAME and you have created get/set methods and you have a List with data from the DB, then in the jsp:

<%
ArrayList list = getDataFromDB();
%>

<select name="product">
<option value="">Select a product</option>

<%
for (int i=0;i<list.size();i++) {
   Product prd = (Product)list.get(i);
%>
   <option value="<%=prd.getId()%>" ><%=prd.getName()%></option>
<%
}
%>

</select>

You have the query and you know how to run it, just create a method and call it from there instead from inside the servlet. You should know how to create classes on your own. If you don't then stop learning about web and go back to basics.
You have the …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you tried searching the net? Yahoo perhaps?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And ... ?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

i want to create a menu.
if i press the menuitem,then a certain action will occure.. and so on...
give the details please...

What you ask has been done so many times in this forum. Do some little searching. Also you should give it a try. It is not that difficult to print the menu with System.out.println and use if statements. All you need is the code for reading input which can be found again by searching this forum

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Put the code that calculatea the width and changes the stylesheet in a function. In that way you can call it whenever you want. For starters you will call it at the onload:

<html>
<head>

<link rel="stylesheet" type="text/css" href="big_screen.css" id="styleId" />

<SCRIPT type="text/javascript" LANGUAGE="JavaScript" >
  function changeStyle() {
    var scwidth=screen.width;

    switch (scwidth) {
		case 1024: 
                    // do something
			break;
		case 1280: 
                    // do something else
			break;
    }  
  }
</SCRIPT>
</head>

<body onload="changeStyle();">
....
</body>
</html>

The stylesheet declaration needs to be in the <head> tag.

Now, you should have paid a closer look at the link I provided. I don't believe that you gave it too much time, nor you studied it thoroughly like you should have.

If you did, you would have come up with this:
http://www.w3schools.com/jsref/dom_obj_link.asp

The tag that you specify the style sheet is a link tag: <link rel="stylesheet" type="text/css" href="big_screen.css" id="styleId" /> Therefor a link object. At that page it shows how you can change its attributes like the href attribute where you specify the css file. So you can do this in the switch statement: document.getElementById("styleId").href="some_css_file.css"; Where "styleId" is the id of the link tag where you specify the css and href is the file.

If you click at the link "href" at that page I showed you: http://www.w3schools.com/jsref/dom_obj_link.asp It has as an example, exactly what you want

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

So from what I understand, you have a form and you submit to a page. But if the form is empty you want to go back to the form? Wouldn't be better if you didn't submit the form in the first place?

<HTML>
<HEAD>
<script>
  // javascript method. Executes at the client. No submit takes place
  function validate() {
    var sT = document.myForm.searchTerm.value;
    if (sT=="") {
      alert("PubMed is empty");
    } else {
       document.myForm.submit();
    }
  }
</script>

</HEAD>
<BODY>
  <FORM METH0D="GET" action="index.jsp" name="myForm">
  <INPUT TYPE="TEXT" NAME="searchTerm" /><BR/><BR/>
  <INPUT TYPE="BUTTON" VALUE="Search PubMedX" onclick="validate();" /><BR/>
  </FORM> 
</BODY>
</HTML>

An alternative to that would be not to have javascript at all and submit to the same page. When action="" then you submit to the same page. Then use java to check the input field and then redirect:

<HTML>
<HEAD>
</HEAD>

<%
String searchTerm = request.getParameter("searchTerm");
if (searchTerm!=null && searchTerm.length!=0) {
  // redirect to the next page
%>
   <jsp:forward page="index.jsp" />
<%
}
%>

<BODY>
  <FORM METH0D="GET" action="" name="myForm">
  <INPUT TYPE="TEXT" NAME="searchTerm" /><BR/><BR/>
  <INPUT TYPE="SUBMIT" VALUE="Search PubMedX" /><BR/>
  </FORM> 
</BODY>
</HTML>

The first time the page loads, the searchTerm is null, so from the if nothing happens. If you submit, then the same page loads but this time the searchTerm is not null. In any case the if will always run and if the searchTerm exists and it is not empty, you redirect.

You <jsp:forward /> you don't have to worry if the searchTerm is in the request, because it is. Even if you …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I will try your code later. What I would suggest would be to put the above code in a function and call it at the onload event of the <body> tag.
Also I would prefer if you had it like this: document.getElementById("resolution").innerText = '<link rel="stylesheet" type="text/css" href="normal_screen.css" />' Although I am not sure that this is the right approach. I will look into it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then save it as a String and then have a method that checks if that String represents a number. Remember the value would be saved as a String.

For validation, you can take each character of that String using for loop.
Check the method charAt(int i) of the String class. Then take each character and check if it is a number using a method from the Character class.

If you find that a character from that String is not a number then display a message and don't continue with the rest of the program.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

With your latest post, it seems that you need to give use some more information about what is your problem and what you want your program to do.

This: "343548357848573" is a String. If the use enters it from a GUI for example you can retrieve it only as a String.

If you use Integer.parseInt or even Long.parseLong and it is too big you will get an exception.

If you must have that value as a numeric then use the classes BigInteger or similar.

Sorry I didn't know about BigInteger. Better tell us what your program needs to do. Why must you have that value: "343548357848573" saved as numeric and not as String ?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

With your latest post, it seems that you need to give use some more information about what is your problem and what you want your program to do.

This: "343548357848573" is a String. If the user enters it from a GUI for example you can retrieve it only as a String.

If you use Integer.parseInt or even Long.parseLong and it is too big you will get an exception.

If you must have that value as a numeric then use the classes BigInteger or similar.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you tried if(saw == "") ?

martin5211 please, If you don't know what you are saying don't post wrong advices. Be sure about what you post and test it before you post it.
Don't use ==. Never use ==.

The problem is that if you don't enter anything at the text field, it will return an empty String, not null.
It will return null if the searchTerm doesn't exist in the request, meaning if you didn't have such field.

Try and write this:

String abc = request.getParameter("some_crazy_string_12312312");

abc will be null.
But if you have searchTerm as a field and you don't enter anything then you will get what you passed which is an empty String "".

Also this is totally wrong:

String see ="null";

see is NOT null, it is "null". null means it doesn't exist. "null" means it has the value of the String "null". When null you cannot use it to call methods.

You cannot do this: You will get an exception:

String s = null;
s.length();

But this will return 4:

String s = "null";
s.length();

Study a bit more about jsp. Your methodology is wrong. Don't use out.print() . Use scriplets.
Don't use servlets to write html code. Change this:

out.print("<br/> <br /><B>Please enter a term to search on NCBI<br /> PubMed:</B><BR><BR>" );
out.print("<FORM METH0D=GET action =\"index.jsp\">");
out.print("<INPUT TYPE=TEXT NAME=searchTerm><BR><BR>");
out.print("<INPUT TYPE=SUBMIT VALUE=Search PubMedX\"><BR>" );
out.print("</FORM> " );
out.print("</BODY>" );
out.print("</HTML>");

To this:

<br/> <br /><B>Please …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

That is because 23837472 is not a long it is an int. This is a long: 23837472L
Try this:

long l = testApp(23837472L);

When you use the 45638, that int number is turned into a long. The reason why you need to add the 'L' is because if you don't, it sees the 23837472 as an int and it is too big for an int.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Of course you get null because the query doesn't return anything! Try to print the argument of the query or better yet the query itself:

System.out.println("SELECT * FROM student where sno='"+stname+"'");

You will also need to close the connection, the statement and the resultset before proceeding.
I also don't agree with your logic not do I know what the welcome class has inside. Does the regdno.getSelectedText() has any value when you call the (new welcome()) ? Because I believe that when you do the regdno is empty. And even if you do enter value to that text, you need to "send" that value to your query by clicking a button or something.

For starters, fix your DB connection.
Create a separate class like this:

public class Student {
  private String sid = null;
  private String sname = null;

  public Student() {

  }

  // add get, set methods or make the above public (Better go with the get/set methods):
  // example:
  public String getSid() {
    return sid;
  }
}

Then

public Student getStudent(String stname) throws Exception {
Student S = null;
Statement stmt = null;
ResultSet rs = null;
Connection con = null;
  try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:exam");
stmt=con.createStatement();
rs=stmt.executeQuery("SELECT * FROM student where sno='"+stname+"'");
                    
if(rs.next()) {
 S = new Student();

 S.setSid(rs.getString(1));
 S.setSname(rs.getString(2));
}

  } catch (Exception e) {
    throw e;
  } finally {
    if (rs!=null) rs.close();
    if (stmt!=null) stmt.close();
    if (con!=null) con.close();
  }
return S;
}

I would suggest that you call that method whenever …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Sorry, my mistake

Forgive my previous post. I clicked the Post button accidentally.

I took your code and made a few changes in order to help you understand it a little bit better

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
        int PERIODS = 4;
        int GRADES = 5; // That is also the number of subjects
    
        float[][] arr = new float[PERIODS][GRADES];

        // This is necessary in order to remember the previous average
        float [] averages = new float[PERIODS];
        
        String studentName, gradeLevel;
    
        System.out.print("Enter name: ");
        studentName = in.readLine();
        System.out.print("Grade level: ");
        gradeLevel = in.readLine();
    
        for(int period=0; period<PERIODS; period++) {
            
            System.out.println();
            System.out.println("============================");
            System.out.println("Enter Grading Grades for period: " + (period+1));
            System.out.println("============================");
        
            float sum = 0;
            for(int grade=0; grade<GRADES; grade++) {
                System.out.print("Enter Grading Grade: " + (grade+1));
            
                arr[period][grade] = Float.parseFloat(in.readLine());
                sum += arr[period][grade];
            }
            float currentAvg = sum/GRADES;
            System.out.println("Current Average for period: "+(period+1) + " is: " + currentAvg);
            
            // TODO ADD YOUR CODE HERE
            //averages[period] = ?;
            
            System.out.println("Final Average for period: "+(period+1) + " is: " + averages[period]);
        }

Try to run that code and see what happens. Now about your formula. It says for the first period do some stuff, for the rest periods do something else. That sounds like if statements:

if (period==0) {
 // Average = Sum of grades / Number of subjects
 averages[period] = Average; // period here is 0
} else {
  // get Average of the previous grading period: IT IS SAVED IN THE averages I DECLARED FOR YOU. YOU JUST NEED TO TAKE …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Sorry, my mistake

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It seems that your problem is with reading from the database. That has nothing to do with gui. All you need is to read the data that you want and then use them in any way you want (pass it as parameter at the setText method).

Search for tutorials and examples in this forum on how to read data from database. How is your sql. You might want to study sql queries as well.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't know then. Sorry

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't know if that is the problem or you simply forgot to post it, but you haven't closed the <a> tag. You didn't put the </a>

<td align=center>
  <a href="successLogs.jsp?strHour=<%=strDate+strHour%>&strcli=<%=strcli%>">
   <%=totSuccCount%>
  </a>
</td>

And you don't need the <u> tags in order to have it underlined.

Also I am not sure that this will solve your problem, but you try this correction and see

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

can u help me with my website please because i do not have any idea how to do or how to start it.
if someone knows how to do it please explain for me from the first step until the end please.
thanks lot
Alex

If you want someone to explain it to you from start to end, then buy a book and do some studying!
We can not explain it to you because we don't have the time nor daniweb has the space for us to post everything there is especially when those can be found in many books. Do some studying, show some effort and we will answer specific questions after you start a NEW thread.

Start by reading about html, then move to jsp and servlets and if you want database look about database connectivity and java.

But you need to be very good with core java first before you proceed otherwise you would be wasting your time.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to put the value attribute at the second option list of options like the first:

<select id="type" name="type">

<option>Please Choose</option>
<option value="50">Single - 50£</option>
<option value="60">Double - 60£</option>
<option value="70">Luxury double - 70£</option>
</select>

Then submit the form to another page and take from the request the values and multiply them. That will require java

Or if you want it to happen at the client you can use javascript to take their values.

But my guess is that you want the first choice

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you have a large application you shouldn't wait until its finished in order to run it.
You should be testing it many times during the development. With every change you make, run it. So if for some reason the application stops running it means that your previous change was the problem and you can undo it.

Before you reinstall try to comment all your code and then start adding bit by bit and run it in order to find the error.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Add some System.out.println calls in your methods and print some debug messages. Add some in your main method. You may also want to print any exceptions that you get.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When you call replaceAll why do you use args[0]? That is the argument of your program. You need to remove the number from inside the file.

Once you get the line from the file call the split method. Assuming that you have the line:

String [] tok = line.split(",");
// for line="1,aaaa" then the tok array will have: {"1","aaaa"} elements
// so do this:

writer.write(tok[1]);

You also need to check if the tok array has length 2 before calling tok[1]. And you need to fix the code that you use for reading and writing.

Use the BufferedReader, FileReader classes and check their APIs:

FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);

String line = br.readLine();
while (line!=null) {
  // do stuf

  // write to file

  // read the next line:
  line = br.readLine();
}

And writing:

FileWriter wr = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fr);

....
bw.write("write something");
bw.newLine(); // change line
....

Also you need to close at the end the bw and br. Check their APIs

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You don't need the switch. And you cover only String with letters 'a' to 'z'. For a better approach:

String string2 = "";
char char1;
for (int x = 0; x < input.length; x++){
 char1 = input.charAt(x);
 int i = char1;
 string2 += i;
}
return string2;

Also the above might not work because you do Integer.parseInt at the end and the final String generated might be too big to be turned into an int.

I just wanted to mention an easier way to turn char variables to ints. The above approach can also be used to determine if a char is within a range of characters.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You can call the checkFP methods in your constructor.
Ask the user the values of the tires and then just call the constructor.
You can add some more boolean attributes that indicate the condition of the tyres.

public class TirePressure
{
	private int fright = 0;
	private int bright = 0;
	private int fleft = 0;
	private int bleft = 0;
	
        private boolean _checkFP = false;
        private boolean _checkBP = false;
	
	public TirePressure(int w, int x, int y, int z)
	{
		fright = w;
		fleft = x;
		bright = y; 
		bleft = z;
		
		System.out.println(checkFP());
		System.out.println(checkBP());
	}
	
	public String checkFP()
	{
		String message;
		if(bleft <= bright && fleft == fright && fright >= 35 && fright <= 45 && bright >= 35 && bright <= 45)
		//if(bleft == bright ||bright == bleft + 3 || bright == bleft - 3 || bright == bleft + 2 || bright == bleft - 2 || bright == bleft + 1 || bright == bleft - 1 )
		{
			message = "Back inflation is OK.";
                        _checkFP = true;
		}
		
		else {
			message = "Back inflation is Not ok.";
                        _checkFP = false;
               }
		
		
			return message;
		
	}
	public String checkBP()
	{
		String message;
		if( fright == fleft ||fright == fleft -3 || fright == fleft +3 || fright == fleft - 2 || fright == fleft + 1 || fright == fleft - 1 )
			
		{
		message = " inflation is OK.";
                _checkBP = true;
		}
		
		else {
			message = " inflation is …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The count variable will hold the place in which the new coin needs to be inserted. When you add a new coin you will put it in the count place and then you will increase its value by one so the next coin will be inserted at the next element of the array.

Before inserting you need to check using if statements if the count value is greater than the length of the array. If the count is greater than the size of the array you cannot add any more coins and the methods needs to return false. Also inside the method add, you need to call the legal method to check if the argument is truly a coin. If the legal method returns false then you shouldn't insert.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

thank you very much for your help ans sorry about my errors....i did not check my code when i sent it here and i had many simple errors.
Can i ask you some more general questions.
1)i would like in a drop down list to have all the dates of the month.(1-31)
the easiest way to do this is

<br>
 <h1></h1>
         Start Date
    <select id="StartDate" name="StartDate" onchange ="DayChanged()">
    <option>1</option>
    <option>2</option>
             .
             .
             .
    <option>31</option>
  </select>
  </br>

this code has many lines and is not very useful.Is there any other way?

2)if i have 2 drop down lists again with dates(e.g departure-arrival) and i want a validation that if the period between these 2 is bigger than 14 days then 'error',is there any way to do this?

Thank you!!!

For the dates you should use peter_budo suggestion. But if you want to make select drop down list with little code you can try this:

<select name="month">
<%
for (int i=1;i<=12;i++) {
%>
  <option value="<%=i%>"><%=i%></option>
<%
}
%>
</select>

The same works if you want multiple <tr> lines at a table. In case you want to print a java array, you for loop it and in the for loop you put: <tr><td><%=array[i]%></td></tr> for example

For validation check out the javascript tutorials I sent. In a javascript function try to get the selected values of the the drop down lists, then compare them. If the validation is ok, submit the form. You can have a type="button" instead of a type="submit" and …