javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I am finishing up writing an extensive C/C++ program and am in dire need of completing these 4 short JAVA programs. Any help would be appreciated GREATLY! (I missed a few days of lecture and am extremely behind in this class.. :sad:
EDIT:
actually just helping me with one or two of these would be GREAT.. :o


1) Write a program that displays the recommended weight, given the user's age and height. The formula for calculating the recommended weight is:

recommendedWeight = (height - 100 + age % 10) * 0.90

Define a service class named Height and include an appropriate method for getting a recommended weight of a designated height.
-------------------------------------------------------------------

First start a new thread.
Then write some code and post it. Surely you know how to define a class and declare a method.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Sorry for the double posting but a better way would be:

public class feetInches
{
public static final int FEET_TO_INCHES = 12;
public static final double INCHES_TO_FEET = 1.0/12.0;

public static void main(String [] args)
{
int feet = 5;
int inches = feet * FEET_TO_INCHES ;

System.out.println(feet + " feet is " + inches);
}
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
public class feetInches
{
public static void main(String [] args)
{
int feet = 5;
int feetToInches = 12;
int inches = feet * feetToInches ;

System.out.println(feet + " feet is " + inches);
}
}

If you want the user to enter input then search this forum for the Scanner class

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You don't help because you don't know.

You are right, all the trained professionals here don't know how to recompile and you, a student, do.


Hehe, I've recompiled the program ;) . And...I won the bet.

Good for you. I hope you did it on your own without any help and you won the bet fair and square.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Why you people don't understand? IS JUST A SIMPLE BET WITH MY TEACHER. If I can modify his java text editor somehow, anything, a simple char, I can get a 10 for that lab. Does it mean I cheat if I prove him I can do something he can't?

You made the bet with your teacher not we. If you want to win the bet then do what you promised:

And I told him I can do this until tomorrow

What should we help you for a bet?
If you had a problem with an assignment we would have helped since this is the purpose of this forum

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all don't do an: ps.executeUpdate() .
You don't update anything to the database, you do a select. So use the method that returns a ResultSet:

ResultSet rs = ps.executeQuery();
if (rs.next) {
  // user found
} else {
  // invalid credentials
}

Don't forget to close the 'rs' at the finally as well.

Also I don't see you creating your Connection:

public int Login(Friend fr) throws EventException
	{
		[B]Connection con = null;[/B]
		System.out.println("Database connection succeeded");

Also at the servlet the method "Login" returns an int. So you need to store that in a variable and with an if statement check if the user has given the correct username nad password

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Don't use these methods:
ye.getYear()
They are deprecated.
Instead use the java.util.Calendar
And use the get method

Calendar rightNow = Calendar.getInstance();
rightNow.get(Calendar.MONTH);

This will return the month. Read the static fields of the API

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

A year is a leap year if it is divisible by 4, unless it is also divisible by 100 but not by 400.

There is your if statement.
Use this '%' operator to determine if a number is divisible by another number.
It returns what is left by the division. If it returns 0 then it is divisible
Experiment with this code:

System.out.println( (10%5)  ); // will return 0
System.out.println( (10%4)  ); // will return 2

10 = 4 * 2 + 2
The green 2 is what the '%' returns. So if it is 0 it means that it is divisible

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well I cannot do the whole thing for you, nor offer help without knowing your level.
And to see your level I will need to see some code.

For the Part 1 you will need the Math class. (search it at the net)
and the
JOptionPane class. Use the static methods (showInputDialog).
For component use null.

Don't bother with the input. First use variables with initial values to do correctly the calculations and then search this forum for the Scanner class and how to read input using that.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I'm having Java course and I have to submit the following programs by the coming Wednesday

Was the assignment given to you today? If no, then what were you doing all this time? If yes, then you have a very demanding teacher.

Please may you code those for me for this time?

Does this mean that next time you will do it on your own?
But if you can't do this now, how will you be able to do the more advanced? Not to mention that you would not have learned how to think on your own, so even if you do understand the code that we would have given you, you would not be able to think the solution for the next assignment.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well the assignment is pretty self explanatory. After you read the triangles apply the Pythagorean theorem.

int a = // read the angle
int b = // read the angle
int c = // read the angle

// if a*a + b*b is equal to c*c then it is a right angle triangle

Then use System.out.println() statements to print the result according to the assignment.
Search this forum for examples on how to read input using the Scanner class.
API:
java.util.Scanner

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

So can anybody please suggest me another method(leaving jsp) to display my data from database on html page

If you want to display data to html page then you use jsp.
Jsp is actually constructed using html tags. So if you don't know html how can you create a web page? If you don't know java how can you display the data?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

it means a number whose digits and consecutive sums add up to the same number. such as 197

you have 1+9+7=17, then 9+7+17=33, then 7+17+37.....and so on till you get 197 and so its a Keith number...

Ok.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

We know that it doesn't run. The code I told you to add was so that we can see what are the values of the variables so we can figure out what is the problem.
You changed the code and instead of posting the results we keep repeating that it doesn't work.

You complained about printing null.
After you added the code, what does it print?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Im not sure I understand what you mean.

I can print the the String s1 with the set from inside the loop but what I want to do is produce all the possible combinations of the result of s1. Then print them to the screen.

I dont understand what you mean by this

import java.io.*;
import java.util.*;
import java.lang.*;

public class gaelan3

{
  static int size;
  static int count;
  static char[] charArray;

  public static void main(String[] args) throws IOException
  {



	String s1= null;

	/*System.out.println("Please enter letters for anagram problem to be solved. Thankyou");

	BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
	String s = read.readLine();
	String input = s;
	*/

	String validChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	Random r = new Random();


	for(int i=1; i<10; i++)
			  {  char randomChar = validChars.charAt(r.nextInt(validChars.length()));
			      s1 = Character.toString(randomChar);

			     System.out.println("s1: "+s1);

			  }



	String input = s1;
			     System.out.println("input: "+input);
    size = input.length();
    count = 0;
    charArray = new char[size];
    for (int j = 0; j < size; j++)
   	  charArray[j] = input.charAt(j);
    doAnagram(size);
  }
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try to print the value s1 from inside the loop.
Then print the value of s1 and input after the assignment.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Why don't you post the code that compiles

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The compiler error should be enough to help you fix this. Read it carefully.
Focus on the part: "Cannot resolve symbol s1"

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
if(empID.equals(acc[i].getjobTitle())) {

}

empId is the employee id, so Why do you compare it with the job title: empID.equals(acc[i].get[B]jobTitle[/B]()) Compare it with the empId of the employee in the array. Then set the job title

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Follow the instructions at the link.
Also at the options where the user enters employee number, loop through the array until you find the employee and call that employee's methods. You don't loop the array and call everybody's method, only the employee that has the employee number that you entered

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Like I mentioned in this link:
http://www.daniweb.com/forums/thread232042.html

The JobTitle method shouldn't be in the Employee class but in the main method

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Nice to meet you too. Although this is not the right thread for introductions

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can you explain what is a Keith number?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you tried this:
../logoutpage.jsp ?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I'm not crazy about this anonymous up/down stuff. I'm a big believer that if you criticize or praise someone in a public way, you should attach your name to it so everyone knows who did it.

Well as VernonDozier said, shouldn't you at least be able to mention the reasons why you Up or Down voted a post, or be able to see who did it to your post?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Para que se usa el string.value, ayudenme a crear una clase cuenta. Manda a pedir si quieres crear una cuenta de ahorro o una de credito...

Αυτό το thread είναι από το 2005. Αν έχεις να κάτι να πεις πόσταρε στα Αγγλικά.

Do you see how frustrating it is that I used my mother language?
> This thread is from 2005. If you have something to post, do it in English.
By the way the above is Greek. Ζήτω η Ελλάς. :)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

So from what I understood:
The reputation system affects both the rep points as well as the voting points of the specific post,
but
The voting system affects only the voting points?

Also is it possible when the user clicks the Up,Down button to display a pop up confirmation dialog? Once I wanted to down vote a post and I accidentally clicked the Up button. The opposite thing might happen. Can you make the Up, Down buttons not to look exactly the same?

By the way I found one of my posts that I did back at 2008! to be down voted even though the post contained a clear solution to the problem of the OP. I know that like the rep points, anyone can give you whatever points they want, negative or positive, but I find it strange that someone decided to down vote a post that is 1 year old without a single explanation.
At least with the reputation system you get to describe the reasons for your selection.

Thank you for your time.

majestic0110 commented: I totally agree with you there +0
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I haven't look at your code but from your explanation, I assume that you create the second frame, when the button is clicked?
If yes declare the second frame as global variable and create it once. In the previous way you keep creating a new one.
With this way whatever you do to the frame will be applied to the same instance:

class Frame1 extends JFrame {
  private Frame2 frame2 = new Frame2();

  // now you can set to visible false or true the frame2 whenever you want
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
public static float average(short [] grades) {
  // calculate the average using a for loop
}

And to call it after you have your array created and entered values in it:

short [] grades = .... ;
..
..

float avrg = average(grades);
BestJewSinceJC commented: Congrats on 200th solved.. :) (Well marked solved anyway) +4
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have 3 methods that accept a:
short [] as argument and return the min, the max, and the average.

And next time use code tags. Press the button that says (CODE) when you create a new post

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Your question has been answered:

http://www.daniweb.com/forums/thread232053.html

If this answers your question give a positive rep to BestJewSinceJC

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you have any questions about the Scanner, check this post. That person had the same problem and got his answer:

http://www.daniweb.com/forums/thread232053.html

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Won't the statement:

c.SetBefore(before);

keep moving the cursor back one from where it is when rs.next() was called?

Of course not. Calling methods with the results you get from rs don't affect it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

int i=123;
System.out.println(i[1]);
Any ideias?

'i' is an int, not an array:

int [] i = new int[2];
i[0] = 1;
i[1] = 2;
i[2] = 3;
System.out.println(i[1]);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What is wrong with your withdraw?
You have the balance in your class. It should take only one argument, the amount to deduct:

withdraw(float amount) {
  if (balance >= amount) {
      balance = balance - amount;
  } else {
     System.out.println("Not enough money");
  } 
}

Then at the main, once you have the number of accounts:

// After creating an array of desired number of accounts
int num = ....
Account [] accounts = new Account[num];

There, you are done. This is the array that you need. Not the one you had in the Account class.

2) Withdraw an Amount (required input: account number, amount to withdraw)
After you get these info, loop the array that you have in the main for the account.

String accountNum = "value entered";
float mon = 10; // value entered
for (int i=0;i<Account.count;i++) {
      if (accountNum.equals(accounts[i].getAccountNumber())) {
             accounts[i].withdraw(mon);
   }
}

Also at your main, don't do that:

for(int i=0;i<acc.length;i++)
{
....
}

Do this:

// create the array here!

int choice = 0;
[B]while (choice!=7) {[/B]

System.out.println("What do you want to do ? ");
System.out.println("Open an Account (1)");
System.out.println("WithDraw Amount (2)");
System.out.println("Deposit Amount (3)");
System.out.println("Account Statement (4)");
System.out.println("Credit Profit (5)");
System.out.println("Total Number of Accounts (6)");
System.out.println("Exit (7)");

choice=Integer.parseInt(JOptionPane.showInputDialog("Enter your choice :"));

switch (choice) {
   case 1:
     ....

   case 7:
        System.out.println("Good bye"); 
        break;
   default:
     System.out.println("Invalid choice"); 
     break;
      
}

}

So whenever the user wants to withdraw or add money, you will loop the array until you find the …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

hi ..thnx alot for help ..i tried the convertor class on 1 row ....and it works perfectly without any errors .....i don't know what's happening when i run it inside the while loop ?:S

You have one instance, and you keep calling the Converte() which executes this code:

for (int i=0; i<unwanted.length(); i++) {
toDelete.add(unwanted.charAt(i));
}

Meaning that for each different row you add to the same Vector the unwanted characters. Since it is one instance you add to the Vector the characters and at the next loop you add more characters and with every loop you add more and more.

Try put the code the way you had it and do this:

public String Converte ()
    {
        char [] BeforeTable = before.toCharArray();
        Vector<Character> BeforeVector = new Vector<Character>();
        for (int i=0; i<unwanted.length(); i++) {
            toDelete.add(unwanted.charAt(i));
        }
        
       [B] System.out.println("-------------------------");
        System.out.println(toDelete);[/B]

        for (int i=0; i<BeforeTable.length; i++) {
            BeforeVector.add(BeforeTable[i]);
        }

            //BeforeVector.re
            BeforeVector.removeAll(toDelete);
        

        for (Character ca : BeforeVector) {
            after+=ca;
        }
        return after;
    }

You will see the elements of the Vector keep increasing.
It would be better to put that part of the code at the constructor if you want to have one instance, or have the method to be static that takes as argument the 'before' and define the Vector inside the method.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

thanks alot but i want the method for accept the space

Try nextLine

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Put everything in a separate method. Have result, input and exchange as arguments and return the output123.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In your Converte method you keep adding elements into the vector todelete.
But in the main method you have only one instance of the Conversion class.
Meaning with each loop instead of calculating the new data from scratch you add every time you call the method more elements.
Since the unwanted is declared in the class and it is unchanged, why don't you add the elements to the todelete vector in the constructor.
From what I see you don't do anything else with the vector. You don't add any more items than the ones of the unwanted.

Have you tried to create a new Conversion object inside the while loop for each row read?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

how to mearge two file where one is exel file and another is java file

Start a new thread for your question and
do you want to know it can be done using code?
Because I don't know how to do this without code.
One is a java file, the other an xls file!

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I will tell you in the morning what I think error is.
In the mean time why don't you try to create every time a new Converter in the loop

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Post the code

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

hi ...thnx again for your reply ....i tried the code that you told me ..and i got this Exception :

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
        at java.util.Arrays.copyOf(Arrays.java:2882)
        at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
        at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:390)
        at java.lang.StringBuilder.append(StringBuilder.java:119)
        at java.lang.StringBuilder.append(StringBuilder.java:115)
        [B]at Conversion.Convertor.Converte(Convertor.java:55)
        at Conversion.DataBaseConvertor.main(DataBaseConvertor.java:43)[/B]

what to di now?

At line 43 DataBaseConvertor.java you call a method of Convertor.java
At line 55 Convertor.java that method gives you the error.
It usually happens when you repeatedly call something.
Example: an endless loop: while (true) {...} or keep running a recursive method without returning from it:

pubic int method() {
  return method();
}

In either way we would like to see the code of the method called,
and YOU need to better test that method in a different main method on its own.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

(day1.after(day2) day1 and day2 are Strings. They don't have an after method:

The method after(String) is undefined for the type String

You should be able to figure that out.

I would suggest your methods to return the date object since it has these methods:

public static Date Later()
   {
       GregorianCalendar thisday = new GregorianCalendar();
       thisday.add(GregorianCalendar.DATE,7);
       Date d = thisday.getTime();
       return d;
   }
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Oh thanks.But what if we dont know the length before.As long as we input name,the program with compare and sort them.

If you don't know the length use the Vector class.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

From the error:

cannot find symbol
symbol : constructor NsccLine()

That means the class NsccLine doesn't have a constructor with no arguments

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

i designed normal calculator application........if u want just tell me to send it for u and tell me the modifications u need......
SNIP

Please don't do that again, as masijade has mentioned. It makes the rest of us look stupid.
As if we couldn't write similar code or we are bad people that have the code and won't to give it to others

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Write a method that reads the user input (I am assuming your getting input at various stages) and checks whether it is "quit" or not and otherwise returns the input as a String. Then, every place where you are currently reading input call this method instead.

Clever suggestion. Although I was under the impression that he wanted something done automatically - like in the background.
But even with my solution, you would still need to call a set method, unless the variable was static, but anyway, I think it would be a lot of fuss about nothing.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

oh Thanks.But any way,i have Some problems with my code.Here, how to modify to input array of string and compare the name(compare first name,if the same first name then compare last name).Tell the smallest one.

Actually you cannot input an array of Strings.
Ask the user to enter the length of the array and then do this:

System.out.println("Enter length: ");
int length = Integer.parseInt(in.nextLine());

String [] array = new String[length];

for (int i=0;i<length;i++) {
  System.out.println("Enter name:");
   array[i] = in.nextLine();
}

Now you have the array and do whatever comparisons you want. Use the compareTo method to compare which String is greater than the other for your sorting. Have a separate method that does that.

If you want to "split" the input try this method:

String input = "Name MN Last";
String [] tokens = input.split(" ");
for (int i=0;i<tokens.length;i++) {
   System.out.println(tokens[i]);
}

/////////////////////////////////////////////////////////////

For better solution try:

class Names {
  public String first = "";
  public String last = "";
  public String middle = "";

  public Names() {
  }

  public String toString() {
     return first+" "+middle+" "+last;
   }
}
String input = "Name MN Last";
String [] tokens = input.split(" ");
for (int i=0;i<tokens.length;i++) {
   System.out.println(tokens[i]);
}

Names nm = new Names();
nm.first = tokens[0];
nm.middle = tokens[1];
nm.last = tokens[2];

System.out.println(nm); // the toString method of the object is called automatically
Names [] arrayWithNames = new Names[2];

arrayWithNames[0].first = ....;
arrayWithNames[0].middle = ....;
arrayWithNames[0].last = ....;

for (int i=0;i<arrayWithNames.length;i++) …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

javax.swing.JComboBox

When you add an Object to the Combo Box, the toString() method is called and it displays that at the GUI: void addItem(Object anObject) The method Object getSelectedItem() gets you the item you have selected.

So create an object with all the info from the DB including the primary key:

class Data {
  private long id = 0L; // assuming this is the PK
  private Sting name = null;
  private int age = 0;
  .....

  public String toString() {
      return name;
  }
}

Get the data from the DB, put each row in a Data object and put that object into a List (java.util.Vector).

Then add each of the objects from the List to Combo Box