473,779 Members | 2,047 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Homework help

9 New Member
what are the parameters needed in the constructor call below to create a Date variable whose intitial value is the 15th of March 2004????
Aug 23 '06 #1
32 7202
jamieexley
9 New Member
3 JAVA QUESTIONS THAT I NEED ANSWERING??!?!

Enter the parameters needed in the constructor call below to create a Date variable whose intitial value is the 15th of March 2004.

Date d = new Date( ____________ );
--------------------------------------------------------------------------------

[2] There is a standard class called DateFormat which (among other things) lets you convert dates to various different output formats.

Use it to write a method called convert which converts a Date to a String in the form dd-mmm-yyyy:
public String convert (Date d) {
...
}

For example, when d is a Date variable representing the 25th of December 2006,
String s = convert(d);

should set s to the string "25-Dec-2006".

Enter your answer (just your convert method) below:






--------------------------------------------------------------------------------

[3] Write a condition for the if statement below which will be true when the Date d1 is not later than the Date d2:
if ( _______________ _____ ) {
...
}
Aug 23 '06 #2
D_C
293 Contributor
I don't have Java installed anymore, but it may be helpful to look at the Java API for DateFormat. I noticed a method called parse(string s) that may help you with the first question. For number 2, look at the format(Date d, StringBuffer sb, FieldPosition fp) method, and maybe getNumberFormat ().

I assume Date(0) is equivalent to midnight Jan 1, 1979, just as the new year began. The time is given in milliseconds, so then every (1000*60*60*24* 365.25...=31557 600000) is approximately equivalent to a year. There are algorithms to calculate how many days are in between two dates. Finally, if each date is represented as the number of milliseconds then you could simply compare these two numbers that represent the date. I am assuming the less than operator is already implemented for Date.
Aug 23 '06 #3
D_C
293 Contributor
The easiest thing would be to parse the date, using DateFormat.pars e(string source), and let Java do all those calculations so Java figures out a time in ms for you. However, here are the calculations that go on behind the scenes, in case you want to understand.

Leap years
Expand|Select|Wrap|Line Numbers
  1. //int year; bool leap;
  2. if((year % 400) == 0) // If year is divisible by 400
  3.   leap = true;
  4. if((year % 100) == 0) // If year is divisible by 100
  5.   leap = false;
  6. if((year % 4) == 0)   // If year is divisible by 4
  7.   leap  = true;
Calculations
So (26*365 + 6) = 9490+6 =9496 days. // 6 leap years, 1980, 84, 88, 92, 96, 2004, but not 2000.
9496 days * (24 hrs/day) = 227904 hrs.
227904 hrs * (60 min/hr) = 13674240 min.
13674240 min * (60 sec/min) = 820454400 sec.
820454400 sec * (1000ms/sec) = 820454400000 ms.
The 26 years = 820454400000 ms.

We still need to count Jan, Feb, and part of March.
Jan = 31 days, Feb = 28 days (we already counted the leap year since 2000 was not a leap year) and Mar = 15 days.
74 days * 24 hrs/day * 60 min/hr * 60 sec/min * 1000 ms/sec = 6393600000ms.

820454400000 ms + 6393600000 ms = 826848000000 ms.
So, Date(8268480000 00) should give you Mar, 15, 2004 right at midnight. If you want 4:30 PM, you would have to add
(16hrs(60 min/hr) + 30 min)*60sec/min*1000ms/sec = 59400000 ms.
Then the date would be 826848000000 ms + 59400000 ms = 826907400000 ms, or Date(8269074000 00).
Aug 23 '06 #4
PLA
44 New Member
Date d = new Date(104, 2, 15);
104 + 1900 = 2004
2 is for March(0 based)
15 for 15 ;-)
But the class Date is deprecated (One of the thing i will nerver understand in Java), you should use the GregorianCalend ar instead
Aug 24 '06 #5
PLA
44 New Member
3 JAVA QUESTIONS THAT I NEED ANSWERING??!?!

Enter the parameters needed in the constructor call below to create a Date variable whose intitial value is the 15th of March 2004.

Date d = new Date( ____________ );
--------------------------------------------------------------------------------

[2] There is a standard class called DateFormat which (among other things) lets you convert dates to various different output formats.

Use it to write a method called convert which converts a Date to a String in the form dd-mmm-yyyy:
public String convert (Date d) {
...
}

For example, when d is a Date variable representing the 25th of December 2006,
String s = convert(d);

should set s to the string "25-Dec-2006".

Enter your answer (just your convert method) below:

--------------------------------------------------------------------------------

[3] Write a condition for the if statement below which will be true when the Date d1 is not later than the Date d2:
if ( _______________ _____ ) {
...
}
[1] See the other post
[2]
GregorianCalend ar c = new GregorianCalend ar(2006, 11, 25);
Date date = c.getTime();
SimpleDateForma t sdf = new SimpleDateForma t("dd-MMM-yyyy", Locale.US);
result = sdf.format(date );
[3]d1.compareTo(d2 ) <= 0
Aug 24 '06 #6
jamieexley
9 New Member
[1] Given a list of integers and an integer variable declared like this:
List<Integer> list;
int max;

and assuming that some values have been added to the list, write a loop which finds the largest value in list and stores it in max.
--------------------------------------------------------------------------------

[2] A bank account is stored as a Map which maps the names of the account holders to a value representing the current balance of their account:
Map<String,Inte ger> bank;

Given a String variable declared like this:
String rich = null;

write a loop which will store the name of the person with the most money in their account in rich.

--------------------------------------------------------------------------------

[3] Using the same bank account as in the previous question, and a list of strings:
Map<String,Inte ger> bank;
List<String> names;

write a loop which fills the list names with the names of all account holders whose accounts are overdrawn, i.e. the balance of their account is less than zero.
------------------------------------------------------------------------------------

[4] Write a method called convertDouble as follows:
public double convertDouble (String value) {
...
}

This method should convert its parameter (a string like "3.1415") to the corresponding value of type double. If the string supplied is not a valid number, it should return 0.0 as its result. Note that you can use the method Double.parseDou ble() to do the hard work for you.

Insert your convertDouble method in the space below:

--------------------------------------------------------------------------------

[5] Modify your convertDouble method to ignore any extra characters at the end of the string, so that convertDouble(" 3.1415xxx") will produce the value 3.1415 as its result.

Insert your convertDouble method in the space below:

--------------------------------------------------------------------------------
[6]
Write a method called countChars which takes an InputStream as a parameter, reads the stream and returns the number of characters it contains as an int. Any IOExceptions which might occur in the method should be passed back to the method's caller.

Insert the code for your method in the space below:


------------------------------------------------------------------------------
[7]
Using the countChars() method from the previous answer, write a method called fileSize() declared as follows:
public int fileSize (String name) {
...
}

which counts the number of characters in the file whose name is supplied as the "name" parameter. This method should return the number of characters in the file, or -1 if an IOException occurs.

Insert the code for your method in the space below:
Aug 24 '06 #7
PLA
44 New Member
I think you don't need a forum but a Java training ;-)

If you are developping a system with money and account, I think you should use BigDecimal (Fix capacity) instead of double (rouding error...)
Aug 24 '06 #8
jamieexley
9 New Member
I know i need training, but I need to resolve these questions? can you help please
Aug 24 '06 #9
jamieexley
9 New Member
Given a list of integers and an integer variable declared like this:
List<Integer> list;
int max;

and assuming that some values have been added to the list,
What is the loop which finds the largest value in list and stores it in max?
Aug 24 '06 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

7
1771
by: tjshadyluver | last post by:
ok i have gotten this damn project almost done but i am frustrated on this one step. getting 18-35 together and 36-50 and so on. here is my code how can i get them combined in one line instead of writing it out a million times. please help me. i have to write a program that you type in the age and it stores it in a text file then i have to catagorize them and when i hit the read button it shows how many times 18-35 was typed in, then how...
2
2281
by: N3TB1N | last post by:
Let me try again. I could use some help with this assignment, even though my teacher does not grade assignments.but because I need to know this stuff for a test very soon, but haven't been in class for awhile and don't know what I'm doing. I have included my (probably wrong) answers for the first few questions. It would be great if someone could tell me what is missing or what I need to work on at least just for the first few. I...
11
1712
by: spawn | last post by:
but I've been struggling with this for far too long and I'm about to start beating my head against the wall. My assignment seemed simple: create a program that will cacluate the running total of user inputs until it hits 100. At 100 it should stop. That's not the problem, in fact, that part works. It's the adding that isn't working. How can my program add 2 + 7 and come up with 14? I'm posting my code (so that you may all laugh). ...
1
1581
by: mastern200 | last post by:
I need some homework help with an assignment due wed. I need to make a program where in this program calculates the average of a set of test scores. The program will ask the user how many scores there will be. The user will be prompted to enter score 1, score 2, etc. After the scores are entered the computer will print the total number of points, the average score, and the number of scores. The program will ask the user if he/she wants...
5
2998
by: karafire2003 | last post by:
I was wondering if someone can help me with my homework. here's the assignment: a. Write a C program that has a declaration in main() to store the string "What's for lunch?" into an array named message. There should be a function call to restaurant() that accepts the message as an argument named menu and then displays the message using the pointer notation *(menu + i). b. Modify this restaurant() function to alter the address in message....
1
1564
by: itgetsharder | last post by:
Hey, i was wondering if anyone could help me. i have two questions that i cannot complete for a homework assignment: This method should convert its parameter (a string like "3.1415") to the corresponding value of type double. If the string supplied is not a valid number, it should return 0.0 as its result. Note that you can use the method Double.parseDouble() to do the hard work for you. ...
8
29168
by: garyrowell | last post by:
I have been at this programme for hours trying to work out what is wrong. Any help would be very much appricated. Here is the breif I received. The program This week you are going to write three classes: Card.java, Deck.java and DeckTester.java. The specification for each class is given below. Card.Java This is a simple class that represents a playing card. Card has two attributes: • rank which is a String that represents the value...
3
4237
by: alireza6485 | last post by:
I need to write a C# program that asks for a pattern and for each pattern beeps one and goes silence for 1 second. This is my code: for (int i=0;i< pattern; i++) { Console.Beep(); ***************** //I have no idea what to put for 1 sec of silence }
0
9632
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9925
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7478
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.