Skip to main content

Random advice thread

OK. Your problem is three parts. Inputting user input and parsing it, performing the calculation and then outputting the value.

For user input you can use Integer.parseInt() on the String arguments provided to main( String [] args ) all inside a test for the correct number of arguments and an exception handler for bad input. Are you confident of that part?
 
The calculation needs a decision by you. The programmer's solution would be to use the Java Date class and underlying millisecond count to have all the work done for you. You would just use Calendar to create the 2 dates and subtract the two millisecond values. All the leap year calculation should be done for you.

If this is a really simple program they might want you to do all the work yourself. You said the varying month lengths, but a true solution would also include the leap year every 4 years, but not every 100 but every 400.
 
OK. Your problem is three parts. Inputting user input and parsing it, performing the calculation and then outputting the value.

For user input you can use Integer.parseInt() on the String arguments provided to main( String [] args ) all inside a test for the correct number of arguments and an exception handler for bad input. Are you confident of that part?
I think so. So far I have done this:

//Date Created: 28 April 2015
//Date Last Changed: 28 April 2015
//This program calculates the number of days the user has been alive
//Input: .txt, Output: None


import java.util.Scanner;


public class DaysAlive {

/**
* Launch the application
*/

/*Global Values*/
public static int iDayBirth, iMonthBirth, iYearBirth;
public static int iDayCurrent, iMonthCurrent, iYearCurrent;
static int iDaysAlive;

public static void main(String[] args) {

/*Calender Array:*/
int Calender[]= new int[13];
Calender[0]= 0;
Calender[1]= 31;
Calender[2]= 28;
Calender[3]= 31;
Calender[4]= 30;
Calender[5]= 31;
Calender[6]= 30;
Calender[7]= 31;
Calender[8]= 31;
Calender[9]= 30;
Calender[10]= 31;
Calender[11]= 30;
Calender[12]= 31;


/*Birth Dates:*/

Scanner inConsole = new Scanner (System.in);

/*Day of Birth*/
System.out.print("Enter the Day of the Date of Birth: ");
iDayBirth = inConsole.nextInt();

/*Month of Birth*/
System.out.print("Enter the Month of the Date of Birth: ");
iMonthBirth = inConsole.nextInt();

/*Year of Birth*/
System.out.print("Enter the Year of the Date of Birth: ");
iYearBirth = inConsole.nextInt();


/*Current Dates:*/


/*Current Day*/
System.out.print("Enter the Current Day: ");
iDayCurrent = inConsole.nextInt();

/*Current Month*/
System.out.print("Enter the Current Month: ");
iMonthCurrent = inConsole.nextInt();

/*Current Year*/
System.out.print("Enter the Current Year: ");
iYearCurrent = inConsole.nextInt();


/*Code to calculate the number of days alive*/



/*Print the results*/
System.out.println(iDaysAlive);

}

}
 
The calculation needs a decision by you. The programmer's solution would be to use the Java Date class and underlying millisecond count to have all the work done for you. You would just use Calendar to create the 2 dates and subtract the two millisecond values. All the leap year calculation should be done for you.

If this is a really simple program they might want you to do all the work yourself. You said the varying month lengths, but a true solution would also include the leap year every 4 years, but not every 100 but every 400.
Yes, they want the leap years too but I am more worried about getting the calculation working atm.
 
OK, let's presume that the current date is always after the birthdate and you want to count from the start, birth, date. Assuming the above code style, you will need to iterate using one or probably more for loops and keep a total of the days you encounter.
 
Just to put it out there, if you are allowed to use the class GregorianCalendar it is very easy...

public GregorianCalendar(int year,int month,int dayOfMonth)

is a constructor. You can construct one each for your two dates, get the millisecond value with:

public long getTimeInMillis()

and subtract one from the other. Then just convert milliseconds into days.
 
I posted elsewhere, but I thought maybe this might be a better place .......

What Would You DO?

So ............. My KFC Coleslaw had something foreign in it - looked like a piece of black thread - about 2.5cms long - maybe it was a fake eyelash - I don't know :( It made me feel real sick. I had eaten a bit of the Coleslaw before I found it. I have put it all back in the fridge, including the 'foreign' bit, wrapped up separate.

So ............ I have lodged a complaint online with them but I am wondering if I should take it further?
 
I posted elsewhere, but I thought maybe this might be a better place .......

What Would You DO?

So ............. My KFC Coleslaw had something foreign in it - looked like a piece of black thread - about 2.5cms long - maybe it was a fake eyelash - I don't know :( It made me feel real sick. I had eaten a bit of the Coleslaw before I found it. I have put it all back in the fridge, including the 'foreign' bit, wrapped up separate.

So ............ I have lodged a complaint online with them but I am wondering if I should take it further?

Take a photo. Post it on one of their SM sites if you can. Call the store and make a complaint during opening hours. it's not ok
 
I'm having a police check done. I've never been arrested or questioned by police, but when I was either 15 or 16 I skipped school, went to the city on the train and got a fine... never paid it either, I think like a week after I got the fine I moved house and have not heard anything about any fines since then. My question is will this fine show up?
 
I'm having a police check done. I've never been arrested or questioned by police, but when I was either 15 or 16 I skipped school, went to the city on the train and got a fine... never paid it either, I think like a week after I got the fine I moved house and have not heard anything about any fines since then. My question is will this fine show up?

In my profession, you get a police check done whenever you start a job, and need to report any legal proceedings to the Registration Board - minor traffic fines have never been an issue, I'm assuming this along similiar lines. If they wanted the outstanding fine paid, they would have found you by now.
 
In my profession, you get a police check done whenever you start a job, and need to report any legal proceedings to the Registration Board - minor traffic fines have never been an issue, I'm assuming this along similiar lines. If they wanted the outstanding fine paid, they would have found you by now.
Ok that makes sense, I just was unsure about the fine, but yeah if no one has tracked me down by now, I don't think they ever will.
 
Ok that makes sense, I just was unsure about the fine, but yeah if no one has tracked me down by now, I don't think they ever will.
Wow, you must be quite the model citizen to still remember such a minor offence after such along time. I admire that! :)

I'm quite the same myself. I've never been in any kind of trouble with the police, but I always worry about breaking the law. :shy:
 
Wow, you must be quite the model citizen to still remember such a minor offence after such along time. I admire that! :)

I'm quite the same myself. I've never been in any kind of trouble with the police, but I always worry about breaking the law. :shy:
Well it wasn't that long ago... I'm not that old lol.... And don't be afraid to break the law, some laws are meant to be broken...:p
 
Well it wasn't that long ago... I'm not that old lol.
lol I mean no offence. You see, worrying about something for more than six months is a long time to worry in my books. :)

I find myself worrying about things that happened at least 10 years ago. And in my mind, that is far too long!!! :(

I meant no implication towards your age. Sorry :sorry:
 
lol I mean no offence. You see, worrying about something for more than six months is a long time to worry in my books. :)

I find myself worrying about things that happened at least 10 years ago. And in my mind, that is far too long!!! :(

I meant no implication towards your age. Sorry :sorry:
Dude it's all good, I wasn't offended. Well maybe a tiny little bit lol.
 
Back
Top