473,789 Members | 2,707 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 7205
jamieexley
9 New Member
thanks 4 the help
Aug 24 '06 #11
PLA
44 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?
Expand|Select|Wrap|Line Numbers
  1.   public static void main(String[] args)
  2.   {
  3.     List<Integer> list = new LinkedList<Integer>();
  4.     int max = -999;
  5.     list.add(1);
  6.     list.add(12);
  7.     list.add(2);
  8.     list.add(11);
  9.     for (int i : list)
  10.     {
  11.       if (i > max)
  12.       {
  13.         max = i;
  14.       }
  15.     }
  16.     System.out.print("Max is : ");
  17.     System.out.println(max);
  18.   }
  19.  
Aug 24 '06 #12
jamieexley
9 New Member
Thank u very much, appreciate that.
Aug 24 '06 #13
jamieexley
9 New Member
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;
How is the loop which will store the name of the person with the most money in their account in rich written?
Aug 24 '06 #14
rivert1
1 New Member
I was given this, can anyone shed some light on it????

How do 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.
Aug 24 '06 #15
PLA
44 New Member
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;
How is the loop which will store the name of the person with the most money in their account in rich written?
Expand|Select|Wrap|Line Numbers
  1. Map<String, Integer> bank = new Hashtable<String, Integer>();
  2. String rich = null;
  3. Integer richBalance = new Integer(0);
  4.  
  5.     bank.put("aaa", new Integer(1020));
  6.     bank.put("bbb", new Integer(2333));
  7.     bank.put("ccc", new Integer(1356));
  8.  
  9.     for (String account : bank.keySet())
  10.     {
  11.       if (bank.get(account) > richBalance)
  12.       {
  13.         rich = account;
  14.         richBalance = bank.get(rich);
  15.       }
  16.     }
  17.     System.out.println("Max is : " + rich + " (" + richBalance + ")");
  18.  
It's my last for that day!
Aug 24 '06 #16
jamieexley
9 New Member
Just 1 more! Please
(3rd & Final)

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

I need to 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???
Aug 24 '06 #17
PLA
44 New Member
Just 1 more! Please
(3rd & Final)

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

I need to 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???
Expand|Select|Wrap|Line Numbers
  1.     Map<String, Integer> bank = new Hashtable<String, Integer>();
  2.     String rich = null;
  3.     Integer richBalance = new Integer(0);
  4.     List<String> names = new LinkedList<String>();
  5.  
  6.     bank.put("aaa", new Integer(1020));
  7.     bank.put("bbb", new Integer(2333));
  8.     bank.put("ccc", new Integer(-1356));
  9.     bank.put("ddd", new Integer(1356));
  10.     bank.put("eee", new Integer(-56));
  11.  
  12.     for (String account : bank.keySet())
  13.     {
  14.       if (bank.get(account) > richBalance)
  15.       {
  16.         rich = account;
  17.         richBalance = bank.get(rich);
  18.       }
  19.       if (bank.get(account) < 0)
  20.       {
  21.         names.add(account);
  22.       }
  23.     }
  24.     System.out.println("Max is : " + rich + " (" + richBalance + ")");
  25.     System.out.println("Names are : " + names);
  26.  
It is easy as you can see !!!
Aug 24 '06 #18
PLA
44 New Member
In fact it is the first time I use Generics in Java (I remembered ugly code and response time in C++ with templates) and it's quite good. Thanks for the lesson
Aug 24 '06 #19
D_C
293 Contributor
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.
Aug 24 '06 #20

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
10410
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10139
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
9984
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...
0
9020
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
5418
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...
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
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.