Results 1 to 2 of 2
  1. #1
    mehnihma is offline Member
    Join Date
    Sep 2011
    Posts
    19
    Rep Power
    0

    Default Help with assignment

    Can you hel me to connect these two codes that I can print out the tabe with contents from frist code?

    And how to make lines between names?

    Thanks

    code 1

    Java Code:
    
    class Account_1
    {
    	String owner;
    	int balance;
    
    	public Account_1() 
    	{
    	} // end constructor Account()
    
    	public void initialise(String name)
    	{
    		owner = name;
    		balance = 0;
    	} // end method initialise
    
    	public void deposit (int anAmount)
    	{
    		balance = balance + anAmount;
    	} // end method deposit
    
    	public int withdraw (int anAmount)
    	{
    		int amountWithdrawn;
    
    		if (anAmount <= balance) 
    			amountWithdrawn = anAmount;
    		else
    			amountWithdrawn = 0;
    
    		balance = balance - amountWithdrawn;
    
    		return amountWithdrawn;
    	} // end method withdraw
    
    	public void print()
    	{
    		System.out.println("Owner = "+ owner +"   Balance = "+balance);
    } // end method print
    
    } // end class Account
    
    
    class Account_2
    {
    	String owner;
    	int balance;
    
    	public Account_2() 
    	{
    	} // end constructor Account()
    
    	public void initialise(String name)
    	{
    		owner = name;
    		balance = 0;
    	} // end method initialise
    
    	public void deposit (int anAmount)
    	{
    		balance = balance + anAmount;
    	} // end method deposit
    
    	public int withdraw (int anAmount)
    	{
    		int amountWithdrawn;
    
    		if (anAmount <= balance) 
    			amountWithdrawn = anAmount;
    		else
    			amountWithdrawn = 0;
    
    		balance = balance - amountWithdrawn;
    
    		return amountWithdrawn;
    	} // end method withdraw
    
    	public void print()
    	{
    		System.out.println("Owner = "+ owner +"   Balance = "+balance);
    } // end method print
    
    } // end class Account
    
    
    class Account_3
    {
    	String owner;
    	int balance;
    
    	public Account_3() 
    	{
    	} // end constructor Account()
    
    	public void initialise(String name)
    	{
    		owner = name;
    		balance = 0;
    	} // end method initialise
    
    	public void deposit (int anAmount)
    	{
    		balance = balance + anAmount;
    	} // end method deposit
    
    	public int withdraw (int anAmount)
    	{
    		int amountWithdrawn;
    
    		if (anAmount <= balance) 
    			amountWithdrawn = anAmount;
    		else
    			amountWithdrawn = 0;
    
    		balance = balance - amountWithdrawn;
    
    		return amountWithdrawn;
    	} // end method withdraw
    
    	public void print()
    	{
    		System.out.println("Owner = "+ owner +"   Balance = "+balance);
    } // end method print
    
    } // end class Account
    
    
    public class Account {
    		public static void main(String[] args){
    		
    		Account_1 acc1 = new Account_1();
    		Account_2 acc2 = new Account_2();
    		Account_3 acc3 = new Account_3();
    		acc1.initialise(null);
    		acc1.owner="Jane";
    		acc1.deposit(100);
    		acc1.withdraw(40);	
    		acc2.initialise("Fred");
    		acc2.deposit(200);
    		acc2.withdraw(125);
    		acc2.print();
    		acc3.initialise("George");
    		acc3.deposit(50);
        acc3.withdraw(75);
        acc2.deposit(60);
        acc1.withdraw(20);
        acc1.print();
        acc2.print();
        acc3.print();
       
       
       
       
     
    			
    
      }
        }


    Code 2:
    Java Code:
    import java.awt.*;
    import javax.swing.*;
    public class Table {
    	public static void main(String args[])
    	{
     
    		JFrame frame = new JFrame("Table");
    		String columns[] = {"Account Name","Owner","Balance"};
    		Object data[][] = {
    				{"account_1","Fred",new Integer(75)},
    				{"account_2", "Jane", new Integer(40)},
    				{"account_1","Fred",new Integer(135)},
    				{"account_3","George",new Integer(50)}
    		};
    		JTable table = new JTable(data,columns);
    		frame.setVisible(true);
    		frame.setBounds(0,0,500,500);
    		frame.add(table.getTableHeader(),BorderLayout.PAGE_START);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.add(table);
    	}
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Help with assignment

    Quote Originally Posted by mehnihma View Post
    Can you hel me to connect these two codes that I can print out the tabe with contents from frist code?

    And how to make lines between names?

    Thanks

    code 1

    Java Code:
    
    class Account_1
    {
    	String owner;
    	int balance;
    
    	public Account_1() 
    	{
    	} // end constructor Account()
    
    	public void initialise(String name)
    	{
    		owner = name;
    		balance = 0;
    	} // end method initialise
    
    	public void deposit (int anAmount)
    	{
    		balance = balance + anAmount;
    	} // end method deposit
    
    	public int withdraw (int anAmount)
    	{
    		int amountWithdrawn;
    
    		if (anAmount <= balance) 
    			amountWithdrawn = anAmount;
    		else
    			amountWithdrawn = 0;
    
    		balance = balance - amountWithdrawn;
    
    		return amountWithdrawn;
    	} // end method withdraw
    
    	public void print()
    	{
    		System.out.println("Owner = "+ owner +"   Balance = "+balance);
    } // end method print
    
    } // end class Account
    
    
    class Account_2
    {
    	String owner;
    	int balance;
    
    	public Account_2() 
    	{
    	} // end constructor Account()
    
    	public void initialise(String name)
    	{
    		owner = name;
    		balance = 0;
    	} // end method initialise
    
    	public void deposit (int anAmount)
    	{
    		balance = balance + anAmount;
    	} // end method deposit
    
    	public int withdraw (int anAmount)
    	{
    		int amountWithdrawn;
    
    		if (anAmount <= balance) 
    			amountWithdrawn = anAmount;
    		else
    			amountWithdrawn = 0;
    
    		balance = balance - amountWithdrawn;
    
    		return amountWithdrawn;
    	} // end method withdraw
    
    	public void print()
    	{
    		System.out.println("Owner = "+ owner +"   Balance = "+balance);
    } // end method print
    
    } // end class Account
    
    
    class Account_3
    {
    	String owner;
    	int balance;
    
    	public Account_3() 
    	{
    	} // end constructor Account()
    
    	public void initialise(String name)
    	{
    		owner = name;
    		balance = 0;
    	} // end method initialise
    
    	public void deposit (int anAmount)
    	{
    		balance = balance + anAmount;
    	} // end method deposit
    
    	public int withdraw (int anAmount)
    	{
    		int amountWithdrawn;
    
    		if (anAmount <= balance) 
    			amountWithdrawn = anAmount;
    		else
    			amountWithdrawn = 0;
    
    		balance = balance - amountWithdrawn;
    
    		return amountWithdrawn;
    	} // end method withdraw
    
    	public void print()
    	{
    		System.out.println("Owner = "+ owner +"   Balance = "+balance);
    } // end method print
    
    } // end class Account
    
    
    public class Account {
    		public static void main(String[] args){
    		
    		Account_1 acc1 = new Account_1();
    		Account_2 acc2 = new Account_2();
    		Account_3 acc3 = new Account_3();
    		acc1.initialise(null);
    		acc1.owner="Jane";
    		acc1.deposit(100);
    		acc1.withdraw(40);	
    		acc2.initialise("Fred");
    		acc2.deposit(200);
    		acc2.withdraw(125);
    		acc2.print();
    		acc3.initialise("George");
    		acc3.deposit(50);
        acc3.withdraw(75);
        acc2.deposit(60);
        acc1.withdraw(20);
        acc1.print();
        acc2.print();
        acc3.print();
       
       
       
       
     
    			
    
      }
        }


    Code 2:
    Java Code:
    import java.awt.*;
    import javax.swing.*;
    public class Table {
    	public static void main(String args[])
    	{
     
    		JFrame frame = new JFrame("Table");
    		String columns[] = {"Account Name","Owner","Balance"};
    		Object data[][] = {
    				{"account_1","Fred",new Integer(75)},
    				{"account_2", "Jane", new Integer(40)},
    				{"account_1","Fred",new Integer(135)},
    				{"account_3","George",new Integer(50)}
    		};
    		JTable table = new JTable(data,columns);
    		frame.setVisible(true);
    		frame.setBounds(0,0,500,500);
    		frame.add(table.getTableHeader(),BorderLayout.PAGE_START);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.add(table);
    	}
    }
    Your question doesn't make sense as you don't tell us any detail of what you're stuck on and just exactly what you're trying to do. For instance, what the heck do you mean by "lines between the names"?

    Next, your Account code is extremely redundant since three of the classes, Account_1, Account_2, and Account_3 have the exact same code, and really there should be only one class and then you create three instances of this one class.

Similar Threads

  1. Can somebody help me in this assignment?
    By lulzim in forum New To Java
    Replies: 25
    Last Post: 03-01-2011, 11:02 PM
  2. Need help with a HW assignment
    By mackavelirip in forum New To Java
    Replies: 4
    Last Post: 02-17-2011, 01:36 AM
  3. Help with an assignment
    By aqeel2010 in forum New To Java
    Replies: 5
    Last Post: 01-14-2011, 09:04 AM
  4. Need help with a assignment
    By helpMe.Java in forum New To Java
    Replies: 7
    Last Post: 06-06-2010, 04:49 PM

Posting Permissions

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