Results 1 to 1 of 1
  1. #1
    Night is offline Member
    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Default Not sure how to create a Menu which uses my other classes

    Hello, so far I have created two classes, which I will show below

    I have tested both classes and they both seem to work.

    I now need to create a menu which will allow users to enter the information and to find information on their account for the following:

    1. Add the customers details
    2. Make a deposit to the business account
    3. Record a meter reading to the business account
    4. Display current balance of the business account
    5. Display full account details
    6. Change the discount value for the business account
    7. Change the cost per unit for all business accounts
    8. How to use the menu system

    Up to this point every time I have tried to create a menu system I just could not get it to work. I would greatly appreciate if someone could help me out on how to go about doing it.

    Thanks :)

    ------------------------------------------------------------------------------------------------------------------------------------------
    Java Code:
    public class GasAccount 
    {
        private int intAccRefNo;
        private String strName;
        private String strAddress; 
        public double dblBalance;
        private double dblUnits;
        public static double dblUnitsCosts = 0.02;
        
    public GasAccount (int intNewAccRefNo , String strNewName , String strNewAddress)
    {
    }
            
    
    public GasAccount (int intNewAccRefNo , String strNewName , String strNewAddress , double dblNewUnits)
            
    {
    intAccRefNo = intNewAccRefNo; 
    strName = strNewName; 
    strAddress = strNewAddress; 
    dblUnits = dblNewUnits;
    dblBalance = dblUnits * dblUnitsCosts; 
    }
    
    
    public int getAccRefNo() 
     { 
    return intAccRefNo; 
     }
    
    public String getName() 
     { 
     return strName; 
     } 
    
     public String getAddress() 
     { 
     return strAddress; 
     } 
     
      public void deposit(double dblDepositAmount)
      { 
             dblBalance = dblBalance - dblDepositAmount;
              
             }
     public double getBalance() 
     {    
     return dblBalance;
     } 
     
     public double getUnitCost()
     {
        
         return dblUnitsCosts;
     }
     
    public void recordUnits (double dblUnitsUsed)
    {
        dblBalance = dblBalance + dblUnitsUsed * dblUnitsCosts;
        dblUnits = dblUnitsUsed + dblUnits;
    }
    
    public double getUnits()
     {
         return dblUnits;
     }
    
    public void updateUnitsCosts(double dblNewUnitsCosts)
    {
        this.dblUnitsCosts = dblNewUnitsCosts;
    }
    }
    ------------------------------------------------------------------------------------------------------------------------------------------

    And another which extends it -
    Java Code:
    public class BusinessAccount extends GasAccount
    {
        
        private double dblDiscount;
        
        
        public BuisnessAccount (int intNewAccRefNo, String strNewName, String strNewAddress, double dblNewUnits, double dblNewDiscount) 
             
            {
            super (intNewAccRefNo , strNewName , strNewAddress, dblNewUnits);
            dblDiscount = dblNewDiscount;
              
       }     
        
        public void setNewDiscount(double dblNewDiscount)
        {
           dblDiscount = dblNewDiscount;
        }
        
        public double getDiscount()
        {
            return dblDiscount;
        }
        
        @Override
        public void recordUnits (double dblUnitsUsed)
    {
       double dblNewBalance;
       dblBalance = dblBalance + dblUnitsUsed * dblUnitsCosts;
       dblNewBalance = dblUnitsUsed * dblUnitsCosts * dblDiscount / 100;
       dblBalance = dblBalance - dblNewBalance;
    }
        
    }
    Here is what my attempted menu looks like up to the fifth option. I am doing something horribly wrong with calling in the methods from the other classes as BuisnessAccount.getMethod always shows up as an error. I am also pretty sure declaring the variables again is completely wrong as then they have no link to my other classes.

    If someone could help me solve this it would be greatly appreciated
    Java Code:
    import java.util.Scanner; 
    
    public class Menu 
    
    {
    public static void main(String [] args) 
    {
    
    Scanner input = new Scanner(System.in);
    
    int Choice;
    
    {
    System.out.println("------------------------------"); 
    System.out.println ( "1. Add the customers details" ) ; 
    System.out.println ( "2. Make a deposit to the business account" ); 
    System.out.println ( "3. Record a meter reading to the business account" ) ; 
    System.out.println ( "4. Display current balance of the business account" ) ; 
    System.out.println ( "5. Display full account details" ) ; 
    System.out.println ( "6. Change the discount value for the business account" ) ; 
    System.out.println ( "7. Change the cost per unit for all business accounts "); 
    System.out.println ( "8. How to use the menu system "); 
    System.out.println ( "Any other number will exit the program"); 
    System.out.println("------------------------------"); 
    System.out.println ( "\n\nEnter a number from 1 to 8" ); 
    Choice = input.nextInt();
    
    switch (Choice)
    {
    
     case 1 :  
    int intNewAccRefNo;
    String strNewName;
    String strNewAddress;
    Double dblNewUnits;
    Double dblNewDiscount;   
    
    System.out.println("Please enter the account number?"); 
    intNewAccRefNo  = input.nextInt();
    
    System.out.println("Please enter the account name?"); 
    input.nextLine();
    strNewName = input.nextLine(); 
    
    System.out.println("Please enter the account address?"); 
    strNewAddress = input.nextLine(); 
    
    System.out.println("Please enter the number of initial number of units used?"); 
    dblNewUnits = input.nextDouble(); 
    
    System.out.println("Please enter the discount?"); 
    dblNewDiscount = input.nextDouble();
    
        case 2:
    
    double dblDeposit;
    
    System.out.println("Please enter the amount you want to deposit?"); 
    dblDeposit = input.nextDouble(); 
    
    System.out.println ( "The current balance: " + BusinessAccount.getBalance() ) ;
    
    case 3: 
    
    double dblUnits;
    
    System.out.println("Enter the number of Units Used");
    dblUnits = input.nextDouble();
    BusinessAccount.recordUnits(dblUnits); 
    
    case 4:
    
    System.out.println("\n Current Balance: "+ BusinessAccount.getBalance()); 
    
    case 5:
    
     System.out.println("Account Reference Number: " + BusinessAccount.getAccRefNo());
     System.out.println("Address: " + BusinessAccount.getAddress());
     System.out.println("Name: " + BusinessAccount.getName());
     System.out.println("Balance: " + BusinessAccount.getBalance());
     System.out.println("Discount: " + BusinessAccount.getDiscount());
     System.out.println("Units: " + BusinessAccount.getUnits());
    Last edited by Night; 05-19-2013 at 07:00 AM.

Similar Threads

  1. Replies: 28
    Last Post: 12-31-2010, 12:40 AM
  2. Replies: 5
    Last Post: 02-07-2010, 10:05 PM
  3. how to create menu-driven programs?
    By princess.blue in forum Eclipse
    Replies: 0
    Last Post: 12-07-2009, 09:01 AM
  4. Replies: 7
    Last Post: 05-09-2008, 08:54 AM
  5. how to create a menu bar in java
    By tommy in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 08:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •