Results 1 to 6 of 6
- 12-19-2010, 06:52 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 6
- Rep Power
- 0
How to create an array that can be modified
hello there all,
I have being asked to create a simple array which contains two different variables that are able to be modified, but i do not have a clue how to modify the array.
If anybody there has some sample projects with this info i will greatfully accept it and will be a real help. a
any information you can also give me will be great, thanks again
- 12-19-2010, 06:55 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,422
- Blog Entries
- 7
- Rep Power
- 17
-
- 12-19-2010, 07:06 PM #4
Member
- Join Date
- Apr 2010
- Posts
- 6
- Rep Power
- 0
reply
if for example a person is asked to enter their name and town, after this information has being entered i have to be able to modify either one of these. If for example they move town.
Sorry about the clarity but i am lost and have being hitting walls constantly he last few days.
-
So you will likely need a class to hold your name and town String, and then have your array be an array of this type of class, correct?
I'm still not sure of what you're needing though. Do you need to post the assignment itself?
- 12-19-2010, 07:19 PM #6
Member
- Join Date
- Apr 2010
- Posts
- 6
- Rep Power
- 0
This is what i have done so far
Java Code:package ie.ds.abs; import javax.swing.JOptionPane; public abstract class Player { protected String name; protected String town; protected String country; protected String club; protected String position; protected int caps; public abstract String getPackage(); public String getName() { return this.name; } public void setName(String name) { this.name = name; } public String getPosition() { return this.position; } public void setPosition(String position) { this.position = position; } public String getTown() { return this.town; } public void setTown(String town) { this.town = town; } public String getCountry() { return this.country; } public void setCountry(String country) { this.country = country; } public String getClub() { return this.club; } public void setClub(String club) { this.club = club; } public int getCaps() { return this.caps; } public void setCaps(int caps) { this.caps = caps; } public void setPlayerInfo() { this.name = JOptionPane.showInputDialog("Enter the Players Name :"); this.country = JOptionPane.showInputDialog("Enter the Players Country :"); this.club = JOptionPane.showInputDialog("Please enter your Players Club :"); this.position = JOptionPane.showInputDialog("Enter the Players Position :"); this.caps = Integer.parseInt(JOptionPane.showInputDialog("Enter the Players Value In Millions")); } public String toString() { String g = "\n"; g = g + "Players League : " + getPackage() + " "; g = g + "Players Name : " + getName() + " "; g = g + "Players Country : " + getCountry() + " "; g = g + "Position : " + getPosition() + " "; g = g + "Players Club : " + getClub() + " "; g = g + "Players Value : €" + getCaps() + "Million "; return g; } }
moderator edit: code tags addedJava Code:package ie.ds.sportsapp; import ie.ds.abs.Player; import ie.ds.impl.Prem; import ie.ds.impl.Scot; import ie.ds.utils.Utilities; import javax.swing.JOptionPane; public class PlayerApp { static int numPlayers=0,maxPlayers=3; //////////////////////////////////////////////////////////////////////////////////////// public boolean isFull(Player[] client) { return (numPlayers == maxPlayers); } //////////////////////////////////////////////////////////////////////////////////////// public boolean isEmpty(Player[] client) { return (numPlayers == 0); } //////////////////////////////////////////////////////////////////////////////////////// public String registerPlayer(Player[] client) { String num = ""; String name = ""; int type = 0; do{ String strType = JOptionPane.showInputDialog("Please enter 1 for Premiership or 2 for a Scottish League"); type= Integer.parseInt(strType); if (type == 1) { Prem bPackage = new Prem(); bPackage.setPlayerInfo(); client[numPlayers] = bPackage; numPlayers += 1; } else if (type == 2) { Scot dPackage = new Scot(); dPackage.setPlayerInfo(); client[numPlayers] = dPackage; numPlayers += 1; } } while(num != name); return name; } ////////////// public void listPlayers(Player[] client) { String G = ""; for (int i = 0; i < numPlayers; ++i) { G = G + client[i]; } JOptionPane.showMessageDialog(null, G, "Player Info", 1); } /////////////////////////////////////////////////////////////////////////////////////// /[COLOR="red"]////////////////////////////////////////////////////////////////////////////////// I HAVE TO PUT THE MODIFY FUNCTION HERE ////////////////////////////////////////////////////////////////[/COLOR]//////////////////////// public void findPlayers(Player[] client) { Player a = client[0]; for (int i = 0; i < numPlayers; ++i) { if (a.getCaps() < client[i].getCaps()) a = client[i]; } JOptionPane.showMessageDialog(null, a, "Most Expensive Player In Database.", 1); } //////////////////////////////////////////////////////////////////////////////////////// public static void main(String[] args) { int option; PlayerApp myApp = new PlayerApp(); Player[] team = new Player[maxPlayers]; do { option = new Utilities().showMenu(); switch(option) { case 1: if(!myApp.isFull(team)) myApp.registerPlayer(team); else JOptionPane.showMessageDialog(null, "No More Players Can be Registered","Player App Data Error",JOptionPane.WARNING_MESSAGE); break; case 2: if(!myApp.isEmpty(team)) myApp.listPlayers(team); break; case 3: if(!myApp.isEmpty(team)) myApp.findPlayers(team); break; case 4: if(!myApp.isEmpty(team)) myApp.removePlayers(team); break; case 5: // Exiting System break; default: break; } } while(option != 5); } }Last edited by Fubarable; 12-19-2010 at 07:34 PM. Reason: moderator edit: code tags added
Similar Threads
-
Create a Get/set for an array
By mechdesignron in forum New To JavaReplies: 4Last Post: 05-04-2010, 09:39 PM -
create a 2d char array from a 1D string array
By jschmall12 in forum New To JavaReplies: 1Last Post: 04-27-2010, 09:01 PM -
Modified Pixels
By monkey04 in forum Java 2DReplies: 1Last Post: 03-12-2009, 08:15 AM -
JSP Last Modified Date
By thagentleman in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 12-18-2008, 04:52 AM -
Checking of file was modified on the server
By Java Tip in forum Java TipReplies: 0Last Post: 03-02-2008, 07:18 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks