943,790 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3994
  • Java RSS
Apr 5th, 2004
0

Cannot get method in project to work

Expand Post »
I am studying Programming and trying to get my assignment to work

the problem is with the MAINTENANCE PART in red I can get it to work!
Can anyone help!!!!

-----------------------------------------------------------------------

public class Assignment2 {
static final int TotalCans = 50; // The total number of cans avaliable
static String Drinks[] ={"Coke", "Sprite", "Water", "Orangina"};
static String Price[] ={"40p", "50p", "80p", "70p"};
static String Coins[] ={"10", "10", "10", "10"};
static String Accept[] ={"5p", "10p", "20p", "50p"};
public static void main(String arg[])

{
/*-- initial setting--------------------------*/
int Cans[] = new int[4];
for (int i=0; i<4; i++)
Cans[i]=(int)(TotalCans*Math.random());

//Then goes the major part of selecting and executing either BUY or Mainenance, each presented with a specific method.
/*-- user’s action menue to choose from----- */
int MenueItem=1;
while (MenueItem!=0){
MenueItem=menue();// a method GO TO QUIT
if (MenueItem==1)
MAINTENANCE(Cans); // a method GO TO MAINTENANCE
else if (MenueItem==2)
Cans=BUY(Cans); // a method BUY A DRINK

}//end of while for choosing action
} //end of main

/*--------- three methods,
menue,
Mainenance,
BUY
to specify----------------------------------*/
/*--‘BUY A DRINK’ to select performance and number of Cans: transform array of booked Cans --- */

public static int[] BUY(int[] per){
for (int i=0;i<per.length;i++)
TextIO.putln((i+1) + "- A can of "+ Drinks[i] + " costs " + Price[i] + " ");
TextIO.putln();
TextIO.putln("Select 1,2,3,4 to select a drink ");
int choice;
choice = TextIO.getInt()-1;
//adjust to indexing
TextIO.putln();
if (per[choice] == TotalCans) {
TextIO.putln("This "+ (choice+1) + " is sold out");
}
else {
TextIO.putln("This machine only accepts 5p, 10p, 20p and 50p coins. Please insert your coins");
int NoOfCans = TextIO.getInt();
int diff=TotalCans-per[choice];
if (NoOfCans > diff)
TextIO.putln("We have only " + diff + " Cans remaining in the machine");
else { // per[choice] = per[choice] + NoOfCans;
per[choice]+=NoOfCans;
TextIO.putln("You have purchased " + NoOfCans + " Cans of ");
}
} // end of else.
return per;
}// end of method BUY

/*--‘BUY’ to select performance and number of Cans: transform array of booked Cans --- */

//------------------------------------------------------------------------------------------------------------------*/
/*--- ‘ONE/MAINTENANCE’ for outputting statistics--- */

public static int[] MAINTENANCE(int[] machine){
TextIO.putln("Want to perform Maintenance checks? ");
TextIO.putln("1 - The amount of cans of each type of drink available currently"); //ISSUE 1
TextIO.putln("2 - The total amount of cans in the machine = "); //ISSUE 2
TextIO.putln("3 - The amount of coins of each denomination there is in this machine currently"); // ISSUE 3
TextIO.putln("4 - The amount of money in total there is in the machine currently ");// ISSUE 4
TextIO.putln();
TextIO.putln("Select 1,2,3,4 to pick which MAINTENANCE check ");
int choice2;
choice2 = TextIO.getInt()-1;
}
}
return machine;
}
class MAINTENANCE2(int [] arr){
switch (int choice2) {
case 1 : {
int ii=0; ii<arr.length; ii++)
TextIO.putln("There are " + arr[ii] + " cans of " + Drinks[ii]+" left");
break; //1 - The amount of cans of each type of drink available currently
}
case 2 : {
TextIO.putln("The total amount of cans in the machine = ? ");
break; //2 - The total amount of cans in the machine
}
case 3 : {
int ii=0; ii<arr.length; ii++)
TextIO.putln("There are " + arr[ii] + " coins of " + Drinks[ii]+" left");
break; //3 - The amount of coins of each denomination there is in this machine currently
}
case 4 : {
TextIO.putln("There is ? in total in this machine ");
break; //4 - The amount of money in total there is in the machine currently
}
}
}
getMaintenance2(){
return MAINTENANCE2;
//------------------------------------------------------------------------------------------------------------------*/

/*--- ‘MENUE’ for choosing action----------- */
public static int menue() {
TextIO.putln();
TextIO.putln("Please enter a number: ");
TextIO.putln(" 0 - to quit ");
TextIO.putln(" 1 - to get a Mainenance ");
TextIO.putln(" 2 - to BUY a drink ");
int item=TextIO.getInt();
return item; }
}// End of class Assignment2
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nics is offline Offline
1 posts
since Apr 2004
Apr 7th, 2004
0

Re: Learner needs help!

whats the error you recieve while compiling?
Reputation Points: 28
Solved Threads: 9
Posting Whiz in Training
BountyX is offline Offline
222 posts
since Mar 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Converting arrays to link lists
Next Thread in Java Forum Timeline: Drag and drop an image





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC