473,789 Members | 2,726 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
32 7206
D_C
293 Contributor
Java API for BufferedInputSt ream. Become friends with the Java API. I don't have Java to test this, but it should work. Also, by not catching the exception, it is returned as requested.
Expand|Select|Wrap|Line Numbers
  1. public int countChars(InputStream is) throws IOException
  2. {
  3.    int count = 0;
  4.    BufferedInputStream bis = new BufferedInputStream(is);
  5.    while(bis.read() != -1) // -1 is returned when end of input is reached.
  6.    {
  7.       count++;
  8.    }
  9.    return count;
  10. }
Aug 24 '06 #21
PLA
44 New Member
I don't know how list is defined, but this may give you an idea of how to do it. I am assuming there are list.length() elements in the list, and list.entry(i) returns the ith element. Similarly for map. I will give you an idea for #2, and some suggestions for the others.

Number 2
Expand|Select|Wrap|Line Numbers
  1. max = map.entry(0).getInt(); // since list is not empty.
  2. for(int i = 0; i < map.length(); i++)
  3. {
  4.    if(max < map.entry(i).getInt())
  5.    {
  6.       max = map.entry(i).getInt());
  7.       rich = map.entry(i).getStr());
  8.    }
  9. }
#1. Just like #2, only you don't worry about the string rich. Also it's a list instead of a map.
#3. Change the if statement. It's condition is given to you. The code to execute should simply put the person's name into a list.

The others seem just as trivial. Give it a go yourself, and if you have any trouble, post your code, what's wrong with it, and what you can't figure out. Then we'll look at it and see.
An other way is to use Java 5.0 Generics and loop
Other thread
Aug 25 '06 #22
Niheel
2,456 Recognized Expert Moderator Top Contributor
All of jaime's questions got merged into one homework help thread.
Aug 26 '06 #23
ruth1976
1 New Member
I need some help on this. I did this code but now need to be updated. I really dont understand what are the benefit. How do I do? Thank you so much for any help.
Ruth


I have the code below how do I do to update the new method:

int count = ((Integer)(orde rMap.get(key))) .intValue();
currentOrder.pu t(unknownItem, new Integer(count)) ;


That is the code to be updated.


public class ToysInventory {
private String[] toysOrdered = {"bear", "train", "car", "ball", "doll",
"ball", "train", "doll", "game", "train",
"bear", "doll", "train","ca r", "ball",
"bat", "glove", "bat", "b", "doll", "bear",
"ball", "doll", "bat", "car", "glove",
"train", "doll", "bear" };

private String[] toysInventoryLi st = {"ball", "bat", "bear", "car", "doll",
"game", "glove", "playstatio n", "train" };

private int InventoryCounte r[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };

public static void main(String[] args) {//BEGIN main()

ToysInventory toys = new ToysInventory() ;
toys.countToys( );
System.exit(0);
}//END main()

private void countToys() {
int temp = 0;
int orderedIndex = 0;
int inventoryIndex = 0;

for (inventoryIndex = 0; inventoryIndex < toysInventoryLi st.length; inventoryIndex+ +){
for (orderedIndex = 0; orderedIndex < toysOrdered.len gth; orderedIndex++) {
if (toysOrdered[orderedIndex] == toysInventoryLi st[inventoryIndex]) {
temp = temp + 1;
}//END if
InventoryCounte r[inventoryIndex] = temp;
}
temp = 0; //reset counter value
}

System.out.prin tln("[order status]");
for (temp = 0; temp < InventoryCounte r.length; temp++){
// (*) before any item for which the customer has requested
// a quantity of 5 or more.
if (InventoryCount er[temp] >= 5){
System.out.prin t("*");
}
else {
System.out.prin t(" ");
}
System.out.prin tln(toysOrdered[temp] + " = " + InventoryCounte r[temp]);
}
}//END countToys()

}//END ToysInventory
Sep 4 '06 #24
joej231
2 New Member
for question
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.

i used this answer
for (int i : list)
{
if (i > max)
{
max = i;
}
}
System.out.prin tln(max);
}
and i get these errors
Main.java:36: illegal start of type
for (Integer n : list) {
^
Main.java:48: <identifier> expected
}
^
Main.java:49: 'class' or 'interface' expected
}
^
Main.java:49: 'class' or 'interface' expected
}
^
4 errors

any ideas in what im doing wrong?
Mar 6 '08 #25
satch
23 New Member
for question
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.

i used this answer
for (int i : list)
{
if (i > max)
{
max = i;
}
}
System.out.prin tln(max);
}
and i get these errors
Main.java:36: illegal start of type
for (Integer n : list) {
^
Main.java:48: <identifier> expected
}
^
Main.java:49: 'class' or 'interface' expected
}
^
Main.java:49: 'class' or 'interface' expected
}
^
4 errors

any ideas in what im doing wrong?
Hey joej231,
I think it would have been helpful if you had posted the complete code because without the code the errors are of no help.
Anyways the following code finds the max given a list of numbers(that is what you are trying to do..right?). Hope it solves your problem.
[ no code spoonfeeding alllowed -- mod ]

First of all, joej should've started his/her own thread for the problem and not hijack
a years old thread. Second, we don't spoonfeed source code.

kind regards,

Jos
Mar 6 '08 #26
MonaLisaO
13 New Member
[ no code spoonfeeding alllowed -- mod ]

First of all, joej should've started his/her own thread for the problem and not hijack
a years old thread. Second, we don't spoonfeed source code.

kind regards,

Jos
I'm confused, is this the real JosAH or someone who is saying some thing that JosAH would say? Because I think also he would have said be sure to use CODE tags.

~mona
Mar 6 '08 #27
JosAH
11,448 Recognized Expert MVP
I'm confused, is this the real JosAH or someone who is saying some thing that JosAH would say? Because I think also he would have said be sure to use CODE tags.

~mona
I almost never say that, I simply insert those tags myself and add an 'edit' line ;-)

kind regards,

Jos ( and don't forget the CODE tags folks! ;-)
Mar 6 '08 #28
MonaLisaO
13 New Member
I almost never say that, I simply insert those tags myself and add an 'edit' line ;-)

kind regards,

Jos ( and don't forget the CODE tags folks! ;-)
But apparently not in this case? lol

~mona
Mar 6 '08 #29
satch
23 New Member
[ no code spoonfeeding alllowed -- mod ]

First of all, joej should've started his/her own thread for the problem and not hijack
a years old thread. Second, we don't spoonfeed source code.

kind regards,

Jos
Point noted :)
I had read about not spoonfeeding source code on the forum but I felt he had written most of the logic correctly and was probably making a mistake in initialization/syntax, so I posted the code.
Anyways from now on I'll avoid posting code.
Mar 7 '08 #30

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
1713
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
29171
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
9666
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
10200
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
10142
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
9021
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
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
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3703
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
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.