When I run choice == 2 I'm suppose to a an out.println back finding a product.
but I get Null for all the values.
Can someone help me with this. - class Computer_listing {
-
-
private String id;
-
-
private String name;
-
-
private int harddrive;
-
-
private int memory;
-
-
private float speed;
-
-
public Computer_listing(String idx) {
-
-
this.id = idx;
-
-
}
-
-
-
public Computer_listing(String cd, String cn, int hd, int me,
-
float sp) {
-
this.id = cd;
-
this.name = cn;
-
this.harddrive = hd;
-
this.memory = me;
-
this.speed = sp;
-
-
}
-
-
public String getId() {
-
-
return this.id;
-
-
}
-
-
public String getName() {
-
-
return this.name;
-
-
}
-
-
public int getHardrive() {
-
-
return this.harddrive;
-
-
}
-
-
public int getMemory() {
-
-
return this.memory;
-
-
}
-
-
public float getSpeed() {
-
-
return this.speed;
-
-
}
-
-
public void setId(String cd) {
-
-
this.id = cd;
-
}
-
-
public void setName(String cn) {
-
-
this.name = cn;
-
-
}
-
-
public void setHarddrive(Integer hd) {
-
-
this.harddrive = hd;
-
-
}
-
-
public void setMemory(Integer me) {
-
-
this.memory = me;
-
-
}
-
-
public void setSpeed(float sp) {
-
-
this.speed = sp;
-
-
}
-
}
-
-
-
public class ComputerInvent{
-
-
-
public static void main(String s[]){
-
-
HashMap<String,Computer_listing> hs = new HashMap<String,Computer_listing>();
-
Computer_listing[] computer = new Computer_listing[2];
-
computer[0] = new Computer_listing("IBM123", "IBM ThinkCentera",2, 5000, 340);
-
computer[1] = new Computer_listing("Apple", "15 PowerBook", 2, 5000, 340);
-
Scanner kbd = new Scanner(System.in);
-
int choice;
-
System.out.println("Make a Section: ");
-
System.out.println("1. Enter Info ");
-
System.out.println("2. Print all ");
-
System.out.println("3. Exit ");
-
System.out.print("\nPlease press Enter afer each response");
-
System.out.println("Enter your chose please: ");
-
choice = kbd.nextInt();
-
kbd.nextLine();
-
-
if (choice == 2) {
-
Collection<Computer_listing> values = hs.values();
-
-
Scanner kbd2 = new Scanner(System.in);
-
int choice2;//new section making
-
System.out.println("Make a Section: ");
-
System.out.println("1. Print all ");
-
System.out.println("2. Exit ");
-
System.out.print("\nPlease press Enter afer each response");
-
System.out.println("Enter your chose please: ");
-
choice2 = kbd.nextInt();
-
kbd2.nextLine();
-
if (choice2 == 1) {
-
for (Computer_listing temp : values) {
-
System.out.println("Item is enter in the db\n");
-
System.out.printf("Id: %s \n",temp.getId());
-
System.out.printf("Product name: %s \n",temp.getName());
-
System.out.printf("Product name: %s \n",temp.getHardrive());
-
System.out.printf("Product name: %s \n",temp.getMemory());
-
System.out.printf("Product name: %s \n",temp.getSpeed());
-
System.out.println("--------------------");
-
}
-
-
}// close the choice2==1
-
if (choice2 == 2) {
-
System.out.printf("Good bye");
-
}// close the choice2==2
-
-
if (choice == 3) {
-
System.out.printf("Good bye");
-
}// close the choice == 3
-
-
}//close else
-
-
-
}//close main
-
-
-
}//close class
thanks
Nomad
3 1753
When I run choice == 2 I'm suppose to a an out.println back finding a product.
but I get Null for all the values.
Can someone help me with this. - class Computer_listing {
-
-
private String id;
-
-
private String name;
-
-
private int harddrive;
-
-
private int memory;
-
-
private float speed;
-
-
public Computer_listing(String idx) {
-
-
this.id = idx;
-
-
}
-
-
-
public Computer_listing(String cd, String cn, int hd, int me,
-
float sp) {
-
this.id = cd;
-
this.name = cn;
-
this.harddrive = hd;
-
this.memory = me;
-
this.speed = sp;
-
-
}
-
-
public String getId() {
-
-
return this.id;
-
-
}
-
-
public String getName() {
-
-
return this.name;
-
-
}
-
-
public int getHardrive() {
-
-
return this.harddrive;
-
-
}
-
-
public int getMemory() {
-
-
return this.memory;
-
-
}
-
-
public float getSpeed() {
-
-
return this.speed;
-
-
}
-
-
public void setId(String cd) {
-
-
this.id = cd;
-
}
-
-
public void setName(String cn) {
-
-
this.name = cn;
-
-
}
-
-
public void setHarddrive(Integer hd) {
-
-
this.harddrive = hd;
-
-
}
-
-
public void setMemory(Integer me) {
-
-
this.memory = me;
-
-
}
-
-
public void setSpeed(float sp) {
-
-
this.speed = sp;
-
-
}
-
}
-
-
-
public class ComputerInvent{
-
-
-
public static void main(String s[]){
-
-
HashMap<String,Computer_listing> hs = new HashMap<String,Computer_listing>();
-
Computer_listing[] computer = new Computer_listing[2];
-
computer[0] = new Computer_listing("IBM123", "IBM ThinkCentera",2, 5000, 340);
-
computer[1] = new Computer_listing("Apple", "15 PowerBook", 2, 5000, 340);
-
Scanner kbd = new Scanner(System.in);
-
int choice;
-
System.out.println("Make a Section: ");
-
System.out.println("1. Enter Info ");
-
System.out.println("2. Print all ");
-
System.out.println("3. Exit ");
-
System.out.print("\nPlease press Enter afer each response");
-
System.out.println("Enter your chose please: ");
-
choice = kbd.nextInt();
-
kbd.nextLine();
-
-
if (choice == 2) {
-
Collection<Computer_listing> values = hs.values();
-
-
Scanner kbd2 = new Scanner(System.in);
-
int choice2;//new section making
-
System.out.println("Make a Section: ");
-
System.out.println("1. Print all ");
-
System.out.println("2. Exit ");
-
System.out.print("\nPlease press Enter afer each response");
-
System.out.println("Enter your chose please: ");
-
choice2 = kbd.nextInt();
-
kbd2.nextLine();
-
if (choice2 == 1) {
-
for (Computer_listing temp : values) {
-
System.out.println("Item is enter in the db\n");
-
System.out.printf("Id: %s \n",temp.getId());
-
System.out.printf("Product name: %s \n",temp.getName());
-
System.out.printf("Product name: %s \n",temp.getHardrive());
-
System.out.printf("Product name: %s \n",temp.getMemory());
-
System.out.printf("Product name: %s \n",temp.getSpeed());
-
System.out.println("--------------------");
-
}
-
-
}// close the choice2==1
-
if (choice2 == 2) {
-
System.out.printf("Good bye");
-
}// close the choice2==2
-
-
if (choice == 3) {
-
System.out.printf("Good bye");
-
}// close the choice == 3
-
-
}//close else
-
-
-
}//close main
-
-
-
}//close class
thanks
Nomad
Where did you let the user enter the info?
When you do -
-
Collection<Computer_listing> values = hs.values();
-
make sure there was something put in hs first.
Where did you let the user enter the info?
When you do -
-
Collection<Computer_listing> values = hs.values();
-
make sure there was something put in hs first.
here is the input section for the user...
Same Class... - public static void main(String s[]){
-
-
HashMap<String,Computer_listing> hs = new HashMap<String,Computer_listing>();
-
Computer_listing[] computer = new Computer_listing[2];
-
computer[0] = new Computer_listing("IBM123", "IBM ThinkCentera",2, 5000, 340);
-
computer[1] = new Computer_listing("Apple", "15 PowerBook", 2, 5000, 340);
-
-
-
Scanner kbd = new Scanner(System.in);
-
int choice;
-
System.out.println("Make a Section: ");
-
System.out.println("1. Enter Info ");
-
System.out.println("2. Print all ");
-
System.out.println("3. Exit ");
-
System.out.print("\nPlease press Enter afer each response");
-
System.out.println("Enter your chose please: ");
-
choice = kbd.nextInt();
-
kbd.nextLine();
-
if (choice == 1) {
-
Scanner ifput = new Scanner(System.in);
-
ifput.useDelimiter("\r\n");
-
-
while(true){
-
-
String msg = null;
-
Computer_listing compdb = null;
-
-
System.out.println("Enter <ComputerID> ie IBM123A - Type <Stop> to print");
-
msg = ifput.next();
-
-
if (msg.equalsIgnoreCase("STOP"))
-
-
break;
-
-
else
-
compdb = new Computer_listing(msg);
-
-
System.out.println("Enter Computer Name:");
-
compdb.setName(ifput.next());
-
-
System.out.println("Enter HardDrive: ie 12");
-
compdb.setHarddrive(Integer.parseInt(ifput.next()));
-
-
-
System.out.println("Enter Memory: ie 7865");
-
compdb.setMemory(Integer.parseInt(ifput.next()));
-
-
System.out.println("Enter Clock Speed: ie 765.00");
-
compdb.setSpeed(Float.parseFloat(ifput.next()));
-
-
hs.put(msg,compdb);
-
-
}
-
-
System.out.println("<Done>");
-
-
Collection<Computer_listing> values = hs.values();
-
int i = 0;
-
-
for (Computer_listing temp : values) {
-
System.out.println("Item is enter in the db\n");
-
System.out.printf("Product Id: %s \n",temp.getId());
-
System.out.printf("Product Name: %s \n",temp.getName());
-
System.out.printf("Product Hardrive: %s \n",temp.getHardrive());
-
System.out.printf("Product Memory: %s \n",temp.getMemory());
-
System.out.printf("Product Speed: %s \n",temp.getSpeed());
-
System.out.println("--------------------");
-
i++;
-
-
}
-
} // close the if loop
nomad
here is the input section for the user...
Same Class... - public static void main(String s[]){
-
-
HashMap<String,Computer_listing> hs = new HashMap<String,Computer_listing>();
-
Computer_listing[] computer = new Computer_listing[2];
-
computer[0] = new Computer_listing("IBM123", "IBM ThinkCentera",2, 5000, 340);
-
computer[1] = new Computer_listing("Apple", "15 PowerBook", 2, 5000, 340);
-
-
-
Scanner kbd = new Scanner(System.in);
-
int choice;
-
System.out.println("Make a Section: ");
-
System.out.println("1. Enter Info ");
-
System.out.println("2. Print all ");
-
System.out.println("3. Exit ");
-
System.out.print("\nPlease press Enter afer each response");
-
System.out.println("Enter your chose please: ");
-
choice = kbd.nextInt();
-
kbd.nextLine();
-
if (choice == 1) {
-
Scanner ifput = new Scanner(System.in);
-
ifput.useDelimiter("\r\n");
-
-
while(true){
-
-
String msg = null;
-
Computer_listing compdb = null;
-
-
System.out.println("Enter <ComputerID> ie IBM123A - Type <Stop> to print");
-
msg = ifput.next();
-
-
if (msg.equalsIgnoreCase("STOP"))
-
-
break;
-
-
else
-
compdb = new Computer_listing(msg);
-
-
System.out.println("Enter Computer Name:");
-
compdb.setName(ifput.next());
-
-
System.out.println("Enter HardDrive: ie 12");
-
compdb.setHarddrive(Integer.parseInt(ifput.next()));
-
-
-
System.out.println("Enter Memory: ie 7865");
-
compdb.setMemory(Integer.parseInt(ifput.next()));
-
-
System.out.println("Enter Clock Speed: ie 765.00");
-
compdb.setSpeed(Float.parseFloat(ifput.next()));
-
-
hs.put(msg,compdb);
-
-
}
-
-
System.out.println("<Done>");
-
-
Collection<Computer_listing> values = hs.values();
-
int i = 0;
-
-
for (Computer_listing temp : values) {
-
System.out.println("Item is enter in the db\n");
-
System.out.printf("Product Id: %s \n",temp.getId());
-
System.out.printf("Product Name: %s \n",temp.getName());
-
System.out.printf("Product Hardrive: %s \n",temp.getHardrive());
-
System.out.printf("Product Memory: %s \n",temp.getMemory());
-
System.out.printf("Product Speed: %s \n",temp.getSpeed());
-
System.out.println("--------------------");
-
i++;
-
-
}
-
} // close the if loop
nomad
In - compdb = new Computer_listing(msg);
are you creating a Computer_listing object using only one String as parameter?
Where is the constructor that takes that?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: dougjrs |
last post by:
I have a HashMap that is storing form data that will later be inserted
into a database. I have been able to create the HashMap just fine, but
I wanted to be able to take my HashMap and just "dump"...
|
by: Christian Gollwitzer |
last post by:
Hi,
I'm trying to loop over the elements in a hashmap of the
STL-implementation by SGI. The point is, that because the key/value pair
is stored as std::pair in the COntainer, the code becomes...
|
by: David |
last post by:
Hi,
I have created the following HashMap class.
class HashMap: public hash_map<string, string, HashString,
HashStringCompare>
{
public:
HashMap(): hash_map<string, string, HashString,...
|
by: Sean |
last post by:
Hi all,
I have problem finding the .NET equivalent of HashMap in
C++ STL.
I CANNOT use Hashtable because I want (there will be more
than one objects for the same key) objects with the same...
|
by: xor |
last post by:
I'm doing up a school project using java, and am a little new to it (I've
worked with other languages for years though).
I've seen code posted by the instructor using HashMap like this...
...
|
by: bumrag |
last post by:
This is the car dealership object relating to the coursework, there is also a separate object named car that i think i need to link to. The problem is on the addcar() method. Any help would be...
|
by: panos100m |
last post by:
Hi
these are the conents of my hashmap printing out the entrySet.
entrySet1: OrderDate=10/30/2007,
entrySet2: Level_0={Item_0={ItemTotal= 3.99, ItemName=test® in, ShipDate=10/31/2007,...
|
by: lbrtchx |
last post by:
Hi,
~
I have found myself in need of some code resembling a Hashmap
~
This is easily done in Java this way:
~
import java.util.*;
// __
public class JMith00Test{
|
by: evelina |
last post by:
Hello, I need help. I have the following hashmap:
HashMap<HashMap<Dimension, Integer>, String> mapList = new HashMap<HashMap<Dimension, Integer>, String>();
I want to extract Dimesion from the...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |