Home Tutorialhelp Comment Need help with JAVA

 
 

Comment

Vrushal
Need help with JAVA,
October 21, 2009 at 8:40 PM

Hi Guys...

My question cud be very daft but i am new to programming so please help.. need to complete assignment for my uni

i am trying to find average age of a Squad (n no.of players) but the code gives me wring answer
there are two classes 1. Players and 2. Club

In Player Class I have written this bit of code for gettingage of individual player:


public String getAge()
{

Calendar now = Calendar.getInstance();
int year=now.get(Calendar.YEAR);
int mon = now.get(Calendar.MONTH);
int day = now.get(Calendar.DAY_OF_MONTH);

now.set(year,mon,day);

long nowinday = now.getTimeInMillis()/86400000;

Calendar DOB = Calendar.getInstance();

DOB.set(yob,dob,mob);
long dobinday = DOB.getTimeInMillis()/86400000;


long spanofday = nowinday - dobinday;

int years = (int)(spanofday / 365);
int rem = (int)(spanofday % 365);

int month = (rem / 30);
rem = (rem % 30);



String age = "The age is " + years + " years " + month + " months and " + rem + " days";
return age;
}

And in Club Class I have written this bit of code for calculating averageage. but it does not work...please help

//** method for calculating average Age of Squad

public String getAverageAge()
{
Calendar cal1 = Calendar.getInstance();
long days = 0;
long months = 0;
String ret;
int year = cal1.get(cal1.YEAR);
int month = cal1.get(cal1.MONTH) + 1;
int day = cal1.get(cal1.DATE);
cal1.set(year, month, day);
for (Players p:Squad)
{
Calendar cal2 = p.getDateOfBirth();
cal2.set(cal2.get(cal2.YEAR), cal2.get(cal2.MONTH), cal2.get(cal2.DATE));
long mills = 86400000;
days = day + ((cal1.getTimeInMillis() - cal2.getTimeInMillis())/mills);
}
days = days/Squad.size();
long years = (days / 365);
long rem = (days % 365);
if (rem > 30)
{
months = (rem / 30);
rem = (rem % 30);
}
ret = year + " years " + months + " months " + days + " days";
return ret;
}


PLease please please help
View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
Java Beginners

help
help  i need help with this code. write a java code for a method named addSevenToKthElement that takes an integer array, and an integer k as its arguments and returns the kth element plus 7. any help would be greatly 

Development process Questions

help
help   how i can send a pitcture on url in java 

Applet Questions

help
help  pls help me to get the code of a java program a program to perform different shapes in a menu using javaapplet 

WebSevices Questions

help
help  Hii.. I have to design one registration page in java that looks like REGISTER USERNAME (here i have to check whether username already exists... to the user) please tell me how could i design that. Please help me asap Thanks a lot 

General

Java Help Center
Java Help Center       Welcome to Java help Center service...; In this section, we provide you round the clock Java Help 

Java Interview Questions

help
(); } } SFDV2103 ‚?? Java Programming Fall, 2012 Term Project... on the percentage of cheating. SFDV2103 ‚?? Java Programming Fall, 2012 Term... based on the percentage of cheating. please help me 

Java Beginners

Help
Help  Design and implement a Java class to represent a 3-D geomtetric shape of your choice. The class should contain a constructor, appropriate data fields and methods to return the volume of the shape, and the surface area 

Java Beginners

help
help  how can i query for a minimum value of of one of the column in my database through java   Use min to retrieve the minimum value from one column of database table. Suppose you have a table named emp where 

Java Beginners

Need Help in Java programming
Need Help in Java programming  Hello. Can someone please help me with writing the following program Java program that gives assignment details such as:assignment number,assignment name,due date,submission date,percentage marks 

JavaScript Questions

help
this in java then try this: import java.util.*; class SquareNumber { public 

JSP Servlet Questions

Help
Help  <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.sql.*" %>...; " id="radio4" name="radio"/> <%@ page language="java 

Java Beginners

help
Java application  public int remainder(int a, int b) { int answer = a % b; System.out.printf("%d % %d = ", a , b); return (answer); } and in my main, int answerRemain 

JavaScript Questions

help
. Based on the above scenario, write a complete Java program. Your program should 

JSP Servlet Questions

Need help on JAVA JSP
Need help on JAVA JSP  Hi, I have never worked on java and I have... using JAVA JSP). e.g. Tool does not adjust with the resolution of the screen(need to know how I can adjust it based on the cureen system's screen resolution 

Java Beginners

Need Help - Java Beginners
Need Help  Hello Sir, Am a beginner of Java. Also i did course... projects in Java as well as J2EE... Can u help me and guide to do a project.../reference/tutorials/ http://netbeans.org/kb/trails/java-ee.html http 

Java Beginners

need help - Java Beginners
need help  Need help in programming in Java  Simple java program that will show the output within quotes using system.out.println();DISPLAYING OUPUT " * " ," *** " ........I used System.out.print 

Java Beginners

Need help - Java Beginners
Need help   To Write a Java program that asks the users to enter a m * n matrix of integers, m and n being the number of rows and columns...; Hi Friend, Please try the following code. We hope that this code will help 

Java Beginners

Regular Expression Help Help HELP!!!!
Regular Expression Help Help HELP!!!!  HI all I am very new to java... = "International Students 1"; So i need to extract only the "international Students", i...","hotmail.com"); so i need to extract"07001", "MR Harish Ram " and extract "M.RHarish 

Java Beginners

Need help in java programming
Need help in java programming  Hello. Can someone please help me with writig the following programm. Assignment 20% Presentation 10% Mini Test 10% Exam 60% Java program that accepts the following details: student 

Java Beginners

need help. - Java Beginners
 

Java Beginners

need help with a program - Java Beginners
Java algorithm - need help with a program  Java algorithm - need help with a program 

Java Beginners

PLZ Need some help JAVA...HELP !!
PLZ Need some help JAVA...HELP !!  Create a class names Purchase Each purchase contains an invoice number, amount of sale and amount of sales tax. Include set methods for the invoice number and sale amount. Within the set 

Java Beginners

java help!
java help!   I need help starting off a program I am trying to write for class. The class should contain a private instance variable to represent temperature in Degrees Celsius and it should have the following methods 

Java Beginners

hello there i need help
i am a beginner, and aside from that i am really eager to learn java please help me with the codes and please explain to me how it works. i only need to use...hello there i need help  : i need to do a program like 

Java Beginners

java help
java help   Write a Java program that does the following: 1.Creates a grading program based on the Baker College grading standard. You will need to look up the current grade standard. You may use only the letter grades without 

Java Beginners

need help with a program - Java Beginners
need help with a program   Part I An algorithm describes how... by the user. The output of the program should be the length and width (entered.... First you would need to make up the "test data". For this algorithm, the test data 

Java Beginners

seriously need help....
seriously need help....  Write a program that will prompt the user to select an appliance, lookup the energy the appliance uses and for each time... program. Use each of the following Java statements at least once in your program 

Java3D Questions

help in java
help in java  Define a class named Money whose objects represent amounts of U.S. money. The class will have two instance variables of type int... class. Notes: You will need to implement the following methods: ‚?? int getCents 

Swing AWT

Need Help with Java-SWING progrmming - Swing AWT
Need Help with Java-SWING progrmming  Hi sir, I am a beginner in java-swing programming. I want to know how we can use the print option with a program in swing. Could you help me with an example? Regards Sreejith  

Java Beginners

Java Programming Need Help ASAP
Java Programming Need Help ASAP  You are required to develop..., maths mark, communications mark. You will then need accessor and mutator methods... class that creates an array of Students and handles it. You will need 

Java Beginners

Need *Help fixing this - Java Beginners
Need *Help fixing this  I need to make this program prompt user... and maybe add retrieve function //need help with this one badly. Thanks guys for all the help. import java.text.*; import javax.swing.*; import java.awt.event. 

HTML Questions

HELP
HELP  I need this code to open in a new web browser. but no matter what i do it wont please help?? Directive 055 Storage Requirements for the Upstream Petroleum Industry 

Java Beginners

help
help  i need ajava code for compressing files using huffman algorithm (run on netbeans correctly 

Java Beginners

Need help in constructing bubble sort
Need help in constructing bubble sort  using a bubble sort, for each entry in the array, display the original index of the first dimension...://www.roseindia.net/java/beginners/arrayexamples/bubblesort.shtml http://www.roseindia.net/java 

Java Beginners

help me
help me  Dear sir/medam i would like to know how to use the java... the order, Fourth button is Find length of text. and there are panels. Please help me...(); f.add(p1,BorderLayout.NORTH); f.add(p2,BorderLayout.CENTER 

Java Beginners

guys,, need help,, in java programing,, arrays
guys,, need help,, in java programing,, arrays  create a program where you will input 10 numbers and arrange it in ascending way using arrays 

Java Beginners

Need help writing a console program
Need help writing a console program  I need help cant seems to figure it out! Write a program that consists of three classes. The first class...): This is a test, this is only a test! This test is a test of your Java programming 

Java Server Faces Questions

plese help
plese help  i need a program to convert a decimal num into binary num in java language by using array and loop   Java Convert decimal to binary import java.util.*; public class DecimalToBinary{ public static void 

RMI Questions

help - RMI
RemoteException; }   You will need three console windows..., in this order: rmiregistry java EchoServer java EchoClient 

Java Beginners

need help on writing a program. - Java Beginners
Writing first Java Program  Hi, I need help to write my first Java... roseIndia to get your query solved. check given link to see the solution of your Java problem.http://www.roseindia.net/java/simple-java-program.shtmlThanks 

Java Beginners

Sales System.. Need Help!! - Java Beginners
Sales System.. Need Help!!  were going to make a sales system in our... help us.. Thank you very much for your reply in my past questions you are a big help.. Thank you so much. Hope you will help me again thanks!! God Bless and more 

Java Beginners

Help With Java...
Help With Java...  Write a java program that can take a positive integer greater than 2 as input and write out the number of times one must repeatedly divide this number by 2 before getting a value less than 2 

Programming Tutorials

open source help desk
solutions?.    Center Help desk component Globodigital.net has updated it Support Center Help desk component for Joomla based...Open Source Help Desk Open Source Help Desk Software As my help desk 

JSP Servlet Questions

help on project - JSP-Servlet
help on project  Need help on Java Project 

Java Beginners

New to Java Please help
New to Java Please help  Hi I need help, can some one help me.... Thanks!   If you are new in java, then you need to learn core java concepts.So go through the following link: Core Java Tutorials Here, you will find 

Java Beginners

java help - Java Beginners
java help  Code a try statement that catches an IOException and an EOFException. If an IOException occurs, print the message ?An I/O error occurred....? to the console. You don?t need to code anything within the try block 

JavaMail Questions

help in java
help in java   Rational Numbers Rational numbers are numbers that can be represented as a fraction p / q where p is an integer number and q is a positive integer (q != 0). Design and implement a Java class RationalNumber 

Java Beginners

Java help - Java Beginners
Java help  I need to write an application that uses the circle class. It must read a radius of a circle from the user creates a circle object, and return the object. The program creates a circle object by using the above method 

Java Interview Questions

Need help
Need help  Dear sir, I have a problem. How to write JSP coding, if a user select a value from drop down list for example department, the another drop.... This name list should get from the database. Please help me. By the way, I'm 

Java Beginners

Need help
Need help  Hello... I need some help I have a method which contains 1 string value and i wnat when this method get called den that string value should b assigned as array name.. for example.. i have a method name() which 

Java Beginners

Need help
Need help  Hello... I need some help I have a method which contains 1 string value and i wnat when this method get called den that string value should b assigned as array name.. for example.. i have a method name() which 

JSP Interview Questions

need help...................please
need help...................please  I have a problem in my JSP Coding... on this area. Please help me. By the way, I'm using access Database and JSP coding...; <table border="0" width="400px" align="center" bgcolor="#CDFFFF"> < 

Java Beginners

java loan calculator applet help
java loan calculator applet help  Hi, I could use some help correcting a code here. I need to write a Java applet program (together with its html... FlowLayout(2)); p2.add(this.jbtCompute); add(p1, "Center"); add(p2, "South 

Java Beginners

java help
java help  How to Open CSV Files in a Microsoft Excel Application Using Java Code with example pgm 

Java Beginners

Need help in completing a complex program; Thanks a lot for your help
Need help in completing a complex program; Thanks a lot for your help ... content is user inputted and static content is prewritten. 3) We need to search... stuck: I need to write a batch file (Windows) which will pass that string 

Java3D Questions

help in java
help in java  Write an application that prompt the user to enter a number to use as an array size, and then attempt to declare an array using the entered size. Java generates a NegativeArraySizeException if wou attempt to create 

Java Beginners

( Inheritance,need help in Polymorphism, Overriding) - Java Beginners
( Inheritance,need help in Polymorphism, Overriding)  can any one please help me create this application,thank you Advanced Concepts with Classes( Inheritance, Polymorphism, Overriding) Employees in a company are divided 

JavaMail Questions

help in java
help in java  3.Flights Design and implement a class called Flight that represents an airline flight. It should contain instance data that represents the airline name, flight number, and the flight's origin and destination cities 

Java3D Questions

help in java
help in java  Write a program that will evaluate simple expressions such as 17 + 3 and 3.14159 * 4.7. The expressions are to be typed in by the user. The input always consist of a number, followed by an operator, followed 

Java Beginners

Java Question Anyone need some HELP !!
Java Question Anyone need some HELP !!  Create a file that contains... of the two files. Note: For the above code, you need POI api. import... and poi-scratchpad-3.2-FINAL-20081019.jar files into the following path: \Java 

Java Beginners

Java Programming Help
Java Programming Help  Hello ! I m the student of last year and i need your help to complete my java project. I going to make a site like youtube... with controls .. I Just want to use jsp and applet in my project . Please help me 

Java Beginners

need help creating a lift program - Java Beginners
need help creating a lift program  Classes, Methods, Constructors please i need help to create an elevator program Simulating an Elevator write... for any help rendered 

Java3D Questions

help in java
help in java  The factorial of a nonnegative integer n is written n! (pronounced √Ę‚?¨Ň? n factorial√Ę‚?¨¬?) and is defined as follows: n!=n . (n-1) . (n-2) . .... . 1 (for values of n greater than or equal to 1) and n!=1 (for n 

JavaScript Questions

help in java
help in java  Design and implement a class called Sphere that contains instance data that represents the sphere's diameter. Define the Sphere constructor to accept and initialize the diameter, and include getter and setter 

Java Beginners

java help?
java help?  Write a program, where you first ask values to an array with 6 integer values and then count the sum and average of the values in methods (send in the array & return the counted value to the main program). Print 

Java Beginners

I need your help - Java Beginners
I need your help  What is the purpose of garbage collection in Java, and when is it used?  Hi check out this url : http://www.artima.com/insidejvm/ed2/gc.html http://java.sun.com/javase/technologies/hotspot 

Java3D Questions

help in java
help in java  Gross And Dozens Design and implement a class called GrossAndDozens to convert a given number of eggs into the number of gross, the number of dozens, and to the number of left over eggs. If you have N eggs, then you 

Java3D Questions

help in java
help in java  Shopping cart Create 3 shopping carts from a Cart class. Each class should have four items in it, a title, a price for the 4 items and the number of each. Your shopping cart should use private variables, so use 

Java Beginners

need help pleaseee....i weak in java
need help pleaseee....i weak in java  QUESTION 1 You are required to write an application called Customer Billing System. This system... meter reading, current meter reading and charges. Write a structured Java program 

Java Beginners

need help with java program as soon as possible
need help with java program as soon as possible  So my assignment is to write a program that used while loops to perform 6 different things. 1. prompt the users to input two integers: firstNum and secondNum (firstNum must be less 

Java Beginners

Need help with this!
Need help with this!  Can anyone please help me... to a file at all at this time. Any help would be greatly appreciated, thank you... to effectivly end the loop with out the need to break it. for(i=(0); i < 

Java3D Questions

help in java
help in java   Team Roster Create a program called TeamRoster that uses a class called Roster. Roster should contain a team name and the names of all... or help me on this pleas.. 7. Gross And Dozens Design and implement a class 

Java Beginners

help for java
help for java  1.convert the following Pseudo code to java if/else structure if student?s grade is greater than or equal to 90 Print ?A? else if student?s grade is greater than or equal to 80 Print ?B? else 

Swing AWT

Need Help To Connect XML as backend in Java-Swing
Need Help To Connect XML as backend in Java-Swing  Seat arrangment swing screenshot I made XML program to connect to swing like this. <?xml... problem is if i click the B1 label it need to change as(occupied-grey colour 

Java3D Questions

help in java
help in java  Create 3 shopping carts from a Cart class. Each class should have four items in it, a title, a price for the 4 items and the number of each. Your shopping cart should use private variables, so use getter and setter 

Java3D Questions

help in java
help in java  Create a class named Order that performs order processing of a single item. The class has five instance variables (fields) : customer name, customer number, quantity ordered, unit price, and total price. Define 

Java3D Questions

help in java
help in java  Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have a number 

Java3D Questions

help in java
help in java  Temperature Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have 

Java Beginners

help - Java Beginners
help  hi,i am new to java & i do not have progamming background, i... shows the c:\javatutorial> in the command prompt, is there any setting i need to do or what could be the issue? plz help   hello, First complie ur 

Java Interview Questions

i need your help - Java Interview Questions
i need your help  Write a java program that: i. Allows user to enter 2 numbers from the keyboard ii. Uses a method to compare the two numbers to determine which is larger iii. Print to the screen stating which number is larger 

Java Beginners

java help
java help  1) build class(es) for the dresses, choose (dress ID, color, price, designer)( link lists) 2) construct the driver class by establishing two separate objects for each sister 3) let them both to enter the dresses 

Java3D Questions

java help
java help  Rational numbers are numbers that can be represented as a fraction p / q where p is an integer number and q is a positive integer (q != 0). Design and implement a Java class RationalNumber for representing such numbers 

Java Beginners

Graphic interface java help
Graphic interface java help  A modified checkers program with class.... Somehow need to enhance the Checkers program above to respond to mouse clicks..., please help 

Java Beginners

I need help in doing this. - Java Beginners
I need help in doing this.  Student DataBase i will need creating a program that will be used to manipulate a student database. This portion..., and the student's GPA.using arrays and objects, need to structure the information 

Java Beginners

Java Help
Java Help  Write a Temperature class that represents temperatures in degrees in both Celsius and Fahrenheit. Use a Floating-point number for the temperature and a character for the scale: either 'C' for Celsius or 'F 

Java Beginners

Java help
Java help  Write a Temperature class that represents temperatures in degrees in both Celsius and Fahrenheit. Use a Floating-point number for the temperature and a character for the scale: either 'C' for Celsius or 'F 

Java3D Questions

java help
java help  Design and implement a class called DateWriter that has three instance variables: a string for month, an integer for day, and an integer for year. The class should has a constructor to accept and initialize the values 

Java Beginners

HELP Java as a starter!
HELP Java as a starter!  I feel like my mind is going to blow! I... programming with Java and I cant find a guide that?s neat. In till someone told me to read (Thinking in java) I was about to buy it in till I saw the pages 1600! pages 

Java Beginners

I need your help - Java Beginners
I need your help  For this one I need to create delivery class for a delivery service .however, this class should contain (delivery number which... the file name is ApplicationDelivery.java Your program must follow proper Java 

Java3D Questions

help in java please
help in java please  Define a class named Money whose objects represent amounts of U.S. money. The class will have two instance variables of type... a test program for your class. Notes: You will need to implement the following 

Java Beginners

Java Variables Help Please!
Java Variables Help Please!  Hi, I just started with java and i need help with my school project, this is it so far: import java.util.*; public class ProjectCS { public static void main(String[] args) { welcome 

Java Beginners

SubString help - Java Beginners
SubString help  Hi , I would appreciate if somebody could help me... a substring of 35 zeros '00000000000000000000000000000000000' and they could... substring . If it find 35 zeros i need 10 digits in front of it along with those 

Java Beginners

Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java... to display whatever is inside. All this is done through the following java code 

Java Beginners

Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java... to display whatever is inside. All this is done through the following java code 

Java Beginners

Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java... to display whatever is inside. All this is done through the following java code 

Java Beginners

Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java... to display whatever is inside. All this is done through the following java code 

Java Beginners

Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java... to display whatever is inside. All this is done through the following java code 

Java Beginners

Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java... to display whatever is inside. All this is done through the following java code 

Java Beginners

Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java... to display whatever is inside. All this is done through the following java code 

Java Beginners

Java and JSP help
Java and JSP help  I have a website, on my website i have made a form...="myPackage.FileReaderWriter"%> <%@page import="java.util.Vector"%> <%@ page language="java... to display whatever is inside. All this is done through the following java code 

Advertisements Advertisements
 

 

 

DMCA.com