Its a completely your home work, Let me restate your problem so You can do it by yourself and learn.
Create a Class "Computer" Which stores the details of the computer Specification like
private String manufacturer;
private String model;
private double price;
private int quality;
Generate the setter and getters method for the class.
IN the above Class have a Constrcutor which sets all the above variables to the default values.
Create a Class "ComputerTest", in this class you will be writing the actual logic where you can find the best Lowest priced Computer.
\i.e if you have 10 computers from Different manufacturers with different price, yuou need to write a comparision method where it picks out the best price and best quality.
That will be your output as you say "Cheapo400 at 399 euro"
Thats it, You will be done with your program!!!!
Sample Program
public class Computer {
private String manufacturer;
private String model;
private double price;
private int rating;
// Set some default values for Computer class
public Computer() {
manufacturer = "Dell";
model = "Inspiron";
price = 790;
rating = 8;
}
// Create an object of Computer class which will take in new data
public Computer(String newManufacturer, String newModel, double newPrice,
int newRating) {
manufacturer = newManufacturer;
model = newModel;
price = newPrice;
rating = newRating;
}
// Here is the get and set method.
// get
public String getManufacturer() {
return manufacturer;
}
public String getModel() {
return model;
}
public double getPrice() {
return price;
}
public int getRating() {
return rating;
}
// set
public void setManufacturer(String newManufacturer) {
manufacturer = newManufacturer;
}
public void setModel(String newModel) {
model = newModel;
}
public void setPrice(double newPrice) {
price = newPrice;
}
public void setRating(int newRating) {
rating = newRating;
}
}
import java.util.ArrayList;
import java.util.Iterator;
public class ComputerTest {
ArrayList computerList = new ArrayList();
public void initialise(){
computerList = AddComputers(computerList);
}
public ArrayList AddComputers(ArrayList<Computer> compList){
Computer comp = new Computer();
comp.setManufacturer("Dell");
comp.setModel("Inspiron");
comp.setPrice(786.00);
comp.setRating(8);
compList.add(comp);
Computer comp1 = new Computer("HP", "Presario",356.00 , 7);
compList.add(comp1);
Computer comp2 = new Computer("IBM", "Thinkpad",566.00 , 4);
compList.add(comp2);
Computer comp3 = new Computer("Lenovo", "C Series", 987.00 , 9);
compList.add(comp3);
return compList;
}
public void lowestPrice(){
Computer temp = new Computer();
double lowestPrice = 0.0;
Iterator iter = computerList.iterator();
while(iter.hasNext()){
Computer comp = (Computer) iter.next();
double price = comp.getPrice();
if((lowestPrice == 0.0) || (price <= lowestPrice)){
lowestPrice = price;
temp.setManufacturer(comp.getManufacturer());
temp.setPrice(comp.getPrice());
temp.setRating(comp.getRating());
temp.setModel(comp.getModel());
}
}
System.out.println("Best Deal Manufacturer "
+ temp.getManufacturer() + " at $" + temp.getPrice());
}
public static void main(String args[]){
ComputerTest test = new ComputerTest();
test.initialise();
test.lowestPrice();
}
}