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 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?
-
public static void main(String[] args)
-
{
-
List<Integer> list = new LinkedList<Integer>();
-
int max = -999;
-
list.add(1);
-
list.add(12);
-
list.add(2);
-
list.add(11);
-
for (int i : list)
-
{
-
if (i > max)
-
{
-
max = i;
-
}
-
}
-
System.out.print("Max is : ");
-
System.out.println(max);
-
}
-
Thank u very much, appreciate that.
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?
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.
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?
- Map<String, Integer> bank = new Hashtable<String, Integer>();
-
String rich = null;
-
Integer richBalance = new Integer(0);
-
-
bank.put("aaa", new Integer(1020));
-
bank.put("bbb", new Integer(2333));
-
bank.put("ccc", new Integer(1356));
-
-
for (String account : bank.keySet())
-
{
-
if (bank.get(account) > richBalance)
-
{
-
rich = account;
-
richBalance = bank.get(rich);
-
}
-
}
-
System.out.println("Max is : " + rich + " (" + richBalance + ")");
-
It's my last for that day!
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???
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???
-
Map<String, Integer> bank = new Hashtable<String, Integer>();
-
String rich = null;
-
Integer richBalance = new Integer(0);
-
List<String> names = new LinkedList<String>();
-
-
bank.put("aaa", new Integer(1020));
-
bank.put("bbb", new Integer(2333));
-
bank.put("ccc", new Integer(-1356));
-
bank.put("ddd", new Integer(1356));
-
bank.put("eee", new Integer(-56));
-
-
for (String account : bank.keySet())
-
{
-
if (bank.get(account) > richBalance)
-
{
-
rich = account;
-
richBalance = bank.get(rich);
-
}
-
if (bank.get(account) < 0)
-
{
-
names.add(account);
-
}
-
}
-
System.out.println("Max is : " + rich + " (" + richBalance + ")");
-
System.out.println("Names are : " + names);
-
It is easy as you can see !!!
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
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 - max = map.entry(0).getInt(); // since list is not empty.
-
for(int i = 0; i < map.length(); i++)
-
{
-
if(max < map.entry(i).getInt())
-
{
-
max = map.entry(i).getInt());
-
rich = map.entry(i).getStr());
-
}
-
}
#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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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). ...
|
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...
|
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....
| |
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. ...
|
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...
|
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
}
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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
|
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...
| |