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.
thanks
Nomad
but I get Null for all the values.
Can someone help me with this.
Code:
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
Comment