473,750 Members | 2,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem adding a object to an array

47 New Member
here is the instructiions I am to use

Ask the user to input the number of effective cars in the shop (this number should be between 1 and 100, inclusively). In a loop, controlled by the inputted number of effective cars, ask the user to input each car data (i.e. make, model, year and price). You can assume that all input data is correct and no data validation is necessary. As soon as all input data for a car is entered, build a Car object by the constructor with parameters and then save the Car object in the array.

Here is what i have so far:

/* UMUC - CMIS 141 - Project 4
* File: Car.java
* Author: Annie Ideus-Balboa
* Date: May 13th, 2007
* Complete: May 17th, 2007
* Modified for Project 4: May 29th, 2007
* Use indications: Run the program from a command window
*/


import java.util.*;
import java.net.*;
import java.lang.*;

public class Car{

public static String make;
public static String model;
public static int year;
public static int price;


//Car(); constructor with parameters
public Car(String m, String d, int y, int p) {
make = m;
model = d;
year = y;
price = p;
}//end constructor

// return make of car (make accessor)
public String getMake() {
return make;
}//end method

//return model of car (model accessor)
public String getModel() {
return model;
}//end method

//return year of car (year accessor)
public int getYear() {
return year;
}//end method

//return price of car (price accessor)
public int getPrice() {
return price;
}//end method

//print method
public void print() {
System.out.prin tln("Make = " + getMake() + "," + " Model = " + getModel() + "," + " Year = " + getYear() + "," + " Price = $" + getPrice());
}//end method
}

that is Car.java file used to create new Cars

/* UMUC - CMIS 141 - Project 4
* File: CarDealerApp.ja va
* Author: Annie Ideus-Balboa
* Date: May 29thth, 2007
* Use indications: Run the program from a command window
*/


import java.util.*;
import java.net.*;
import java.lang.*;

public class CarDealerApp{



public static void main(String[] args) {

//declare array of Car objects. Array name is carShop
final int MAX_SIZE = 100;
Car carShop[] = new Car[MAX_SIZE];

Scanner stdin = new Scanner(System. in);

//self intro
System.out.prin tln();
System.out.prin tln(" CMIS 141 Project 3");
System.out.prin tln(" File: Car.java");
System.out.prin tln(" Created by: Annie (ALI) Ideus-Balboa");
System.out.prin tln(" Due: June 3rd, 2007");
System.out.prin tln();

System.out.prin t("Please input the number of effective cars currently in the shop?: ");
int numberOfCars = stdin.nextInt() ;

for(int i = 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {

System.out.prin tln();
System.out.prin tln("Your Car (Car c3):");
System.out.prin t("What is the make of your car? ");
String m = stdin.nextLine( );
System.out.prin t("What is the model of your car? ");
String d = stdin.nextLine( );
System.out.prin t("What is the Year of your car? ");
int y = stdin.nextInt() ;
System.out.prin t("What is the Price of your car? $");
int p = stdin.nextInt() ;
Car C = new Car(m, d, y, p);
carShop[i] = C;
}
for (int i= 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {
System.out.prin tln(carShop[i]);
}
}
}

now when I run this the print comes out as
Car@14318bb
Car@ca0b6

Can anyone help me with this? Thanks in Advance ALI :P
May 30 '07 #1
11 2460
nomad
664 Recognized Expert Contributor
here is the instructiions I am to use

Ask the user to input the number of effective cars in the shop (this number should be between 1 and 100, inclusively). In a loop, controlled by the inputted number of effective cars, ask the user to input each car data (i.e. make, model, year and price). You can assume that all input data is correct and no data validation is necessary. As soon as all input data for a car is entered, build a Car object by the constructor with parameters and then save the Car object in the array.

Here is what i have so far:

/* UMUC - CMIS 141 - Project 4
* File: Car.java
* Author: Annie Ideus-Balboa
* Date: May 13th, 2007
* Complete: May 17th, 2007
* Modified for Project 4: May 29th, 2007
* Use indications: Run the program from a command window
*/


import java.util.*;
import java.net.*;
import java.lang.*;

public class Car{

public static String make;
public static String model;
public static int year;
public static int price;


//Car(); constructor with parameters
public Car(String m, String d, int y, int p) {
make = m;
model = d;
year = y;
price = p;
}//end constructor

// return make of car (make accessor)
public String getMake() {
return make;
}//end method

//return model of car (model accessor)
public String getModel() {
return model;
}//end method

//return year of car (year accessor)
public int getYear() {
return year;
}//end method

//return price of car (price accessor)
public int getPrice() {
return price;
}//end method

//print method
public void print() {
System.out.prin tln("Make = " + getMake() + "," + " Model = " + getModel() + "," + " Year = " + getYear() + "," + " Price = $" + getPrice());
}//end method
}

that is Car.java file used to create new Cars

/* UMUC - CMIS 141 - Project 4
* File: CarDealerApp.ja va
* Author: Annie Ideus-Balboa
* Date: May 29thth, 2007
* Use indications: Run the program from a command window
*/


import java.util.*;
import java.net.*;
import java.lang.*;

public class CarDealerApp{



public static void main(String[] args) {

//declare array of Car objects. Array name is carShop
final int MAX_SIZE = 100;
Car carShop[] = new Car[MAX_SIZE];

Scanner stdin = new Scanner(System. in);

//self intro
System.out.prin tln();
System.out.prin tln(" CMIS 141 Project 3");
System.out.prin tln(" File: Car.java");
System.out.prin tln(" Created by: Annie (ALI) Ideus-Balboa");
System.out.prin tln(" Due: June 3rd, 2007");
System.out.prin tln();

System.out.prin t("Please input the number of effective cars currently in the shop?: ");
int numberOfCars = stdin.nextInt() ;

for(int i = 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {

System.out.prin tln();
System.out.prin tln("Your Car (Car c3):");
System.out.prin t("What is the make of your car? ");
String m = stdin.nextLine( );
System.out.prin t("What is the model of your car? ");
String d = stdin.nextLine( );
System.out.prin t("What is the Year of your car? ");
int y = stdin.nextInt() ;
System.out.prin t("What is the Price of your car? $");
int p = stdin.nextInt() ;
Car C = new Car(m, d, y, p);
carShop[i] = C;
}
for (int i= 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {
System.out.prin tln(carShop[i]);
}
}
}

now when I run this the print comes out as
Car@14318bb
Car@ca0b6

Can anyone help me with this? Thanks in Advance ALI :P
I'm not to sure if you can use a array this way. I think you need to use a Arraylist. You can make an index stop at 100 if an if statement but why?
When you have this code
Expand|Select|Wrap|Line Numbers
  1.  Car C = new Car(m, d, y, p);
For example you can have an array of intergers, an array of string Objects, or an array of arrays, but you can not have an array that contains both String Objects and integers.

Also you have a mistake in.
Expand|Select|Wrap|Line Numbers
  1.  
  2. System.out.print("What is the make of your car? ");    
  3.             String m = stdin.nextLine();
  4.             System.out.print("What is the model of your car? ");
  5.             String d = stdin.nextLine();
  6.  
Delete the Line, should look like this:
Expand|Select|Wrap|Line Numbers
  1.  String m = stdin.next();
otherwise you will get
What is the make of your car?What is the model of your car?
and that not what you want.

nomad
PS if you do not know how to make a arraylist please read my Article on Arraylist
May 30 '07 #2
blazedaces
284 Contributor
here is the instructiions I am to use

Ask the user to input the number of effective cars in the shop (this number should be between 1 and 100, inclusively). In a loop, controlled by the inputted number of effective cars, ask the user to input each car data (i.e. make, model, year and price). You can assume that all input data is correct and no data validation is necessary. As soon as all input data for a car is entered, build a Car object by the constructor with parameters and then save the Car object in the array.

Here is what i have so far:

/* UMUC - CMIS 141 - Project 4
* File: Car.java
* Author: Annie Ideus-Balboa
* Date: May 13th, 2007
* Complete: May 17th, 2007
* Modified for Project 4: May 29th, 2007
* Use indications: Run the program from a command window
*/


import java.util.*;
import java.net.*;
import java.lang.*;

public class Car{

public static String make;
public static String model;
public static int year;
public static int price;


//Car(); constructor with parameters
public Car(String m, String d, int y, int p) {
make = m;
model = d;
year = y;
price = p;
}//end constructor

// return make of car (make accessor)
public String getMake() {
return make;
}//end method

//return model of car (model accessor)
public String getModel() {
return model;
}//end method

//return year of car (year accessor)
public int getYear() {
return year;
}//end method

//return price of car (price accessor)
public int getPrice() {
return price;
}//end method

//print method
public void print() {
System.out.prin tln("Make = " + getMake() + "," + " Model = " + getModel() + "," + " Year = " + getYear() + "," + " Price = $" + getPrice());
}//end method
}

that is Car.java file used to create new Cars

/* UMUC - CMIS 141 - Project 4
* File: CarDealerApp.ja va
* Author: Annie Ideus-Balboa
* Date: May 29thth, 2007
* Use indications: Run the program from a command window
*/


import java.util.*;
import java.net.*;
import java.lang.*;

public class CarDealerApp{



public static void main(String[] args) {

//declare array of Car objects. Array name is carShop
final int MAX_SIZE = 100;
Car carShop[] = new Car[MAX_SIZE];

Scanner stdin = new Scanner(System. in);

//self intro
System.out.prin tln();
System.out.prin tln(" CMIS 141 Project 3");
System.out.prin tln(" File: Car.java");
System.out.prin tln(" Created by: Annie (ALI) Ideus-Balboa");
System.out.prin tln(" Due: June 3rd, 2007");
System.out.prin tln();

System.out.prin t("Please input the number of effective cars currently in the shop?: ");
int numberOfCars = stdin.nextInt() ;

for(int i = 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {

System.out.prin tln();
System.out.prin tln("Your Car (Car c3):");
System.out.prin t("What is the make of your car? ");
String m = stdin.nextLine( );
System.out.prin t("What is the model of your car? ");
String d = stdin.nextLine( );
System.out.prin t("What is the Year of your car? ");
int y = stdin.nextInt() ;
System.out.prin t("What is the Price of your car? $");
int p = stdin.nextInt() ;
Car C = new Car(m, d, y, p);
carShop[i] = C;
}
for (int i= 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {
System.out.prin tln(carShop[i]);
}
}
}

now when I run this the print comes out as
Car@14318bb
Car@ca0b6

Can anyone help me with this? Thanks in Advance ALI :P
First of all, from now on please try to use [ code ][ /code ] (without spaces) brackets around your code.

I'm curious... what do you want it to print? All of the data in car, one at a time? All I know is that right now you're trying to print a car(m, d, y, p). Since this is not a string it simply prints the classname@locat ionInMemory, understand? If you want it to print everything (since you already have a print method in car) you should replace the following line:

"System.out.pri ntln(carShop[i]);"

with

"carShop[i].print();"


Hope that solved your problem,
-blazed
May 30 '07 #3
shanakard
13 New Member
Expand|Select|Wrap|Line Numbers
  1. System.out.println(carShop[ i ]);
in the above line u have given a Object of type Car to the println() function
this will run the "println(Ob ject v)" overload of the println function and take the given parameter as a "Object" type parameter.

when any object 'x' is given to println() function it will print the output string of the x.toString() function to the console.

since every class is derived from the Object class and Object Class has a toString() method that prints the class Type of the object and it's memory address it will be output. (like Car@14318bb).

if U want to output the car information for that object U should Overload the toString() method in your Car class.

(for more information read the Object class's toString() function of the java documentation)

Hopes this solves ur problem.
May 30 '07 #4
AZRebelCowgirl73
47 New Member
Ok here is what I have So far:

//this is the car.java file that must be used when running the CarDealerApp.ja va
//file
import java.util.*;
import java.net.*;
import java.lang.*;

public class Car{
public static String make;
public static String model;
public static int year;
public static int price;
//Car(); constructor with parameters
public Car(String m, String d, int y, int p) {
make = m;
model = d;
year = y;
price = p;
}//end constructor
// return make of car (make accessor)
public String getMake() {
return make;
}//end method
//return model of car (model accessor)
public String getModel() {
return model;
}//end method
//return year of car (year accessor)
public int getYear() {
return year;
}//end method
//return price of car (price accessor)
public int getPrice() {
return price;
}//end method
//print method
public void print() {
System.out.prin tln("Make = " + getMake() + "," + " Model = " + getModel() + "," + " Year = " + getYear() + "," + " Price = $" + getPrice());
}//end method
}

// This is the CarDealerApp.ja va file
import java.util.*;
import java.net.*;
import java.lang.*;
public class CarDealerApp{
public static void main(String[] args) {
//declare array of Car objects. Array name is carShop
final int MAX_SIZE = 100;
Car carShop[] = new Car[MAX_SIZE];
Scanner stdin = new Scanner(System. in);
System.out.prin tln();
System.out.prin t("Please input the number of effective cars currently in the shop?: ");
int numberOfCars = stdin.nextInt() ;
for(int i = 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {
System.out.prin tln();
System.out.prin t("What is the make of your car? ");
String m = stdin.next();
System.out.prin t("What is the model of your car? ");
String d = stdin.next();
System.out.prin t("What is the Year of your car? ");
int y = stdin.nextInt() ;
System.out.prin t("What is the Price of your car? $");
int p = stdin.nextInt() ;
Car C = new Car(m, d, y, p);
carShop[i] = C;
System.out.prin tln();
}
for (int i= 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {
carShop[i].print();
}
}
}

Ok now when I run this program I get it to print out each object within the carShop[] array, however when the loop is running it duplicates the last run loop for each object in the array. what I mean to say is this. Say I run the loop 2 times for 2 cars, and i put honda, accord, 1999, $14000 for the first run of the loop for the first car and i put toyota, corolla, 2001 $17000 for the send run of the loop for the second car. When the array dat prints, carShop[0] shows toyota, corolla, 2001, $17000 and carShop[1] shows toyota, corolla, 2001, $17000, it skips the first instance of the loop.

I am not allowed to change the Car.java file.
I also can not use anything but the main() method in the CarDealerApp.ja va file.

Can anyone help me with what I may be missing! Thanks in advance ALI :P
May 30 '07 #5
nomad
664 Recognized Expert Contributor
Ok here is what I have So far:

//this is the car.java file that must be used when running the CarDealerApp.ja va
//file
import java.util.*;
import java.net.*;
import java.lang.*;

public class Car{
public static String make;
public static String model;
public static int year;
public static int price;
//Car(); constructor with parameters
public Car(String m, String d, int y, int p) {
make = m;
model = d;
year = y;
price = p;
}//end constructor
// return make of car (make accessor)
public String getMake() {
return make;
}//end method
//return model of car (model accessor)
public String getModel() {
return model;
}//end method
//return year of car (year accessor)
public int getYear() {
return year;
}//end method
//return price of car (price accessor)
public int getPrice() {
return price;
}//end method
//print method
public void print() {
System.out.prin tln("Make = " + getMake() + "," + " Model = " + getModel() + "," + " Year = " + getYear() + "," + " Price = $" + getPrice());
}//end method
}

// This is the CarDealerApp.ja va file
import java.util.*;
import java.net.*;
import java.lang.*;
public class CarDealerApp{
public static void main(String[] args) {
//declare array of Car objects. Array name is carShop
final int MAX_SIZE = 100;
Car carShop[] = new Car[MAX_SIZE];
Scanner stdin = new Scanner(System. in);
System.out.prin tln();
System.out.prin t("Please input the number of effective cars currently in the shop?: ");
int numberOfCars = stdin.nextInt() ;
for(int i = 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {
System.out.prin tln();
System.out.prin t("What is the make of your car? ");
String m = stdin.next();
System.out.prin t("What is the model of your car? ");
String d = stdin.next();
System.out.prin t("What is the Year of your car? ");
int y = stdin.nextInt() ;
System.out.prin t("What is the Price of your car? $");
int p = stdin.nextInt() ;
Car C = new Car(m, d, y, p);
carShop = C;
System.out.prin tln();
}
for (int i= 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {
[i]carShop.print();
}
}
}

Ok now when I run this program I get it to print out each object within the carShop[] array, however when the loop is running it duplicates the last run loop for each object in the array. what I mean to say is this. Say I run the loop 2 times for 2 cars, and i put honda, accord, 1999, $14000 for the first run of the loop for the first car and i put toyota, corolla, 2001 $17000 for the send run of the loop for the second car. When the array dat prints, carShop[0] shows toyota, corolla, 2001, $17000 and carShop[1] shows toyota, corolla, 2001, $17000, it skips the first instance of the loop.

I am not allowed to change the Car.java file.
I also can not use anything but the main() method in the CarDealerApp.ja va file.

Can anyone help me with what I may be missing! Thanks in advance ALI :P


you are reinitialized the arrary
This will print after each loop
Delete this part

Expand|Select|Wrap|Line Numbers
  1.  carShop = C; 
  2. System.out.println();
  3. for (int i= 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {
  4. carShop.print();
  5. }
  6.  




add this part
carShop[i] = C;
System.out.prin tln();
Car.Carprint();
}
}
}



nomad
May 30 '07 #6
AZRebelCowgirl73
47 New Member
[/i]

you are reinitialized the arrary
This will print after each loop
Delete this part

Expand|Select|Wrap|Line Numbers
  1.  carShop = C; 
  2. System.out.println();
  3. for (int i= 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {
  4. carShop.print();
  5. }
  6.  




add this part
carShop[i] = C;
System.out.prin tln();
Car.Carprint();
}
}
}


nomad
After the loop is finished is when I am suppose to create a instance that prints the contents of the carShop[] array? adding the section you suggested would print each loop as it finished and that would be insufficient for the exercise! Any other ideas and Thanks so much for the help! ALI :P
May 30 '07 #7
shanakard
13 New Member
Expand|Select|Wrap|Line Numbers
  1. public class Car{
  2. public static String make;
  3. public static String model;
  4. public static int year;
  5. public static int price;
  6. //Car(); constructor with parameters
  7. public Car(String m, String d, int y, int p) {
  8. make = m; ...... 
U see the above code all the attributes of the class Car are "static" (i.e:- public static String make)

the thing with static variables are it only keeps one memory location to keep it's data for all the instances of that class. this could be used in cases to count the number of instences of a class (as shown in bellow code) like thing or many other uses.... Actually static variables are an important concept when we wan't to share data among all instances of the same class;

Expand|Select|Wrap|Line Numbers
  1. public class Test{
  2.    private static int count;
  3.  
  4.    public Test(){
  5.        count+=1;
  6.    }
  7.  
  8.    public void finalize(){
  9.        count--;
  10.    }
  11.  
  12.    public static int getCount(){
  13.         return count;
  14.    }
  15.  
  16.    public static void main(String[] args){
  17.        Test a,b,c;
  18.  
  19.        System.out.println("Count before any object is created is "+Test.getCount());     //don't need a instance of the class to access static variables
  20.        a=new Test();
  21.  
  22.        System.out.println("Count after 'a=new Test()' is "+Test.getCount());
  23.        b= new Test();
  24.        c=new Test();
  25.  
  26.        System.out.println("Count after 2 new objects are created is "+c.getCount());    //In java we can also use a instance of the class to access static members
  27.        //if u ever used Integer.parseint() method haven't u wondered where the Integer part came from, obviously it's not any object u created. actually it's a static method in Integer class'
  28.  
  29.        a=null;
  30.        System.gc();  //invokes the garbage collector
  31.  
  32.        System.out.println("Count after object pointed to by 'a' is destroied is "+Test.getCount());
  33.    }
  34.  
  35. }
  36.  
in ur example since the Car classes members are static they only keep a single set of data for all the instances of the car objects.
so unless u change the car class what u request is not possible in java !!!

hope this helps U ;-)
May 31 '07 #8
AZRebelCowgirl73
47 New Member
Expand|Select|Wrap|Line Numbers
  1. public class Car{
  2. public static String make;
  3. public static String model;
  4. public static int year;
  5. public static int price;
  6. //Car(); constructor with parameters
  7. public Car(String m, String d, int y, int p) {
  8. make = m; ...... 
U see the above code all the attributes of the class Car are "static" (i.e:- public static String make)

the thing with static variables are it only keeps one memory location to keep it's data for all the instances of that class. this could be used in cases to count the number of instences of a class (as shown in bellow code) like thing or many other uses.... Actually static variables are an important concept when we wan't to share data among all instances of the same class;

in ur example since the Car classes members are static they only keep a single set of data for all the instances of the car objects.
so unless u change the car class what u request is not possible in java !!!

hope this helps U ;-)
You are my HERO :)) Thanks so much! But now I face a new problem!
Thanks so MUCH!!!! ALI :P
Jun 1 '07 #9
AZRebelCowgirl73
47 New Member
Here is my problem:

I have two java files:

One named Car.java and the other named CarDealerApp.ja va: In the CarDealerApp program, I read in through user input the make, model, year and price of a car and put them into an array called carShop[]. This part of the program is running fine. Every thing in the CarDealerApp.ja va file runs correctly except for the last loop. I need to read in through user input the make of a car and then search the array carShop[] for the make and subtract $1000 from the price listed for all instances of that particular make within the array. I cant seem to make the code work, the user input part does but the for loop does not! Can anyone help! Here is what I have so far: Thanks in advance!! ALI :P

import java.util.*;
import java.net.*;
import java.lang.*;
public class Car{

public String make;
public String model;
public int year;
public int price;

//Car(); constructor with parameters
public Car(String m, String d, int y, int p) {
make = m;
model = d;
year = y;
price = p;
}//end constructor

// return make of car (make accessor)
public String getMake() {
return make;
}//end method

//return model of car (model accessor)
public String getModel() {
return model;
}//end method

//return year of car (year accessor)
public int getYear() {
return year;
}//end method

//return price of car (price accessor)
public int getPrice() {
return price;
}//end method

//set new price of car (price mutator)
public void setPrice(int iPrice) {
price = iPrice;
}//end method

//print method
public void print() {
System.out.prin tln("Make = " + getMake() + "," + " Model = " + getModel() + "," + " Year = " + getYear() + "," + " Price = $" + getPrice());
}//end method
}

import java.util.*;
import java.net.*;
import java.lang.*;

public class CarDealerApp{

public static void main(String[] args) {

//declare array of Car objects. Array name is carShop
final int MAX_SIZE = 100;
Car carShop[] = new Car[MAX_SIZE];

Scanner stdin = new Scanner(System. in);

System.out.prin t("Please input the number of effective cars currently in the shop?: ");
int numberOfCars = stdin.nextInt() ;

for(int i = 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {
System.out.prin tln();
System.out.prin t("What is the make of your car? ");
String m = stdin.next();
System.out.prin t("What is the model of your car? ");
String d = stdin.next();
System.out.prin t("What is the Year of your car? ");
int y = stdin.nextInt() ;
System.out.prin t("What is the Price of your car? $");
int p = stdin.nextInt() ;
Car C = new Car(m, d, y, p);
carShop[i] = C;
}
System.out.prin tln();
System.out.prin tln(" The effective cars currently in the shop are: ");
System.out.prin tln();
for (int i = 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {
carShop[i].print();
}
System.out.prin tln("The Price of all effective cars currently in the shop is: ");
int prices[] = new int[numberOfCars];
int dataSum = 0;
for (int i = 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {
prices[i]= carShop[i].getPrice();
dataSum += prices[i];
}
System.out.prin tln(" Total Price = $" + dataSum);
System.out.prin tln(" Search the shop for car below a certain price. ");
System.out.prin tln();
System.out.prin t("Please enter the price to search for: $ ");
int searchPrice = stdin.nextInt() ;
System.out.prin tln("All cars in the shop with a price of: $" + searchPrice + " or lower are: ");
for (int i = 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {
if (carShop[i].getPrice() <= searchPrice) {
carShop[i].print();
}
}
System.out.prin tln(" Search the shop for car of a certain Make ");
System.out.prin tln(" and reduce their price by $1000. ");
System.out.prin tln();
System.out.prin t("Please enter the make to search for: ");
String searchMake = stdin.next();
System.out.prin tln();
for (int i = 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {
if (carShop[i].getMake() == searchMake) {
int iPrice = carShop[i].getPrice() - 1000;
carShop[i].setPrice(iPric e);
carShop[i].print();

}
}
}
}
Jun 1 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
3901
by: Naran Hirani | last post by:
Hi Guys and Gals, Please can u help me with this little problem. I am collecting a set of values from a web form and putting them into a JS array object. I now want to check/ensure that there or no repeated values in this array. I can think of many ways to do this using one or many loops but was just wondering if there was any other clever way of doing this using string functions or the RegExp
4
4812
by: Derek | last post by:
Hi, I've built a rather large CGI that dumps a lot of data and a fairly complex javascript app out to the client's browser. Granted this may be poor style according to someone web design philosophy but that is the way things need to work for now here. The problem I'm having is that it appears that the browsers (IE, mozilla and netscape) are sometimes getting confused about wether the javascript code is running. By this I mean when I...
4
1455
by: TheBurgerMan | last post by:
Hi all. I have an array of objects (Let's call it Object A) and each of these objects has an array of other objects (Let's call these Object B) in it. I can successfully repeat through Object A's and for each Object A I can successfully repeat Object B's that are in it, like so: Object A-1 Object B-1-A-1 Object B-2-A-1 Object B-3-A-1 Object A-2
1
3894
by: tangus via DotNetMonster.com | last post by:
Hello all, I'm really struggling with getting some Active Directory code to work in ASP.NET. Can you please provide assistance? I am executing the following code: Dim enTry As DirectoryEntry = New DirectoryEntry("LDAP://domain") Dim mySearcher As New DirectorySearcher(enTry) Dim resEnt As SearchResult mySearcher.Filter = ("(objectClass=*)") mySearcher.SearchScope = SearchScope.Subtree
0
3186
by: maitrepoy | last post by:
I have to create a small addin which works on Powerpoint, Word, Outlook, and Excel on Office 2000, XP, and 2003. This addin consists in adding 2 new Buttons in the "File" Menu of office. This is properly done, but the events which should be triggered with the button.click method are not triggered in Word. I don't understand because it properly works in the 3 others host applications. If someone has an issue, I would be most grateful. Thanks...
2
4453
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c */ #include <time.h>
7
1780
by: Trickynick1001 | last post by:
Hi, a newbie here. I don't have a real firm grasp on the idea of Javascript, as I'm used to programming in Qbasic and C. I'm not used to OOP. Anyway, I really don't have any idea what the problem is with this code, it just simply won't work properly. Some of the functions aren't done, but the main one gives me a Not a Number message in the text box where the calculations are supposed to come up. I tried to use a parseInt on my stuff,...
1
2070
by: DJG79 | last post by:
Hi all, I am using an open source menu that i found and it works great, except for one thing that when the web page is not scrolled to the very top the drop down links will not stay visible. Has anyone else had this sort of problem with javascript? and any ideas how to fix it would be greatly appreciated.. I have included a copy of the code below, thanks. /**
2
3156
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button then the calender gone actually i want if i click outside off the calender then it should me removed ..How kan i do this ... Pls inform me as early as possible .. I am waiting for ur quick replay ...Here i attached the source code .... <!DOCTYPE...
5
1492
by: Ranmini | last post by:
Dear prob solver, i have a problem with array lists. i am using array lists for adding objects. i just want to know, when you are adding an object to an arraylist whats the value u pass to the add method??? eg: i have a class call vertex and i want to add an object from that class. so to add that object how to i add that to the arraylist??? do i need to pass the string id or pass an instant of the relevant class??? The code is below ...
0
9577
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...
0
9396
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
9339
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
9256
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
8260
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...
0
6081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4713
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
4887
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3322
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 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.