sir hopefully now understand how to declare am arraylist,sir can u tell me how to get the index no of the arraylist and remove item using the index no of the arraylist.i tried to do but i get error pls sir helpme on this please!!!
i didnot do much altering the code
import java.util.ArrayList;
// Class representing the actual mobile entry object
class mobileEntry
{
private int fCredit;
private String phoneModel;
// Constructor which takes a credit and model
public mobileEntry(int freeCredit, String PhoneModelNo)
{
fCredit = freeCredit;
phoneModel = PhoneModelNo;
}
// Properties to get credit and phone model
public int getCredit() {
return fCredit;
}
public String getPhoneModel() {
return phoneModel;
}
}
public class MobileShop
{
// An arraylist of our mobile entries
private ArrayList<mobileEntry> mobile = new ArrayList<mobileEntry>();
// Create a mobileEntry and then add it to our array list
public void addmobile(int freecredit,String phonemodelno)
{
if(freecredit<0)
{
System.out.println("Enter a valid callcredit");
}
else
{
// Notice how we make an object and then add it to mobile arraylist
mobile.add(new mobileEntry(freecredit,phonemodelno));
System.out.println(" Mobile added to display ");
}
}
// Here we use the credit number to loop through the array list, find the object, then return it.
public mobileEntry getEntry(int freeCreditNumber)
{
for (mobileEntry entry : mobile)
{
if (entry.getCredit() == freeCreditNumber)
{
return entry;
}
}
}
public void showMobilesinStock()
{
/**
* i like to put array index number in front
* like this
* "1: w595 with 150 minutes of free calling credit"
*/
for (mobileEntry entry : mobile)
{
System.out.prinln( phoneModel + "with" + fCredit + " minutes of free calling credit ");
}
}
/**
* i want to initialise array index no to some variable calle display no,so user can buy phone using the display no
* if disply no matches the one in the arraylist i want to sell phone and remove it from arraylist */
public void Sellphone(int displayno)
{
if(displayno<0)
{
System.out.println("Number entered is less than 1");
}
else
{
System.out.println("Congragulations you have brought" + phoneModel + "with" fCredit " minutes of free call credit");
//how to remove pone from arraylist
//how to find the correct phone using the display no
}
}
/**
* to sell phone using modelno
*/
public void Sellphone(String PhoneModelNo)
{
if(phoneModel
}
/**
* to display with greatest no of minutes
*/
public void greatestcallcredit()
{
}
}

New Topic/Question
Reply




MultiQuote




|