Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com How can I move a user's input into a table and manipulate it with previous methods?

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 10-25-2012, 05:09 PM PM User | #1 Basic Chaos New to the CF scene   Join Date: Oct 2012 Posts: 3 Thanks: 2 Thanked 0 Times in 0 Posts How can I move a user's input into a table and manipulate it with previous methods? Code: ``` //This is the code I have so far.// import java.util.Scanner; public class AnnualPayCalculator { public static void main(String[ ] args) { double salesAmount ; Scanner keyboard = new Scanner(System.in); System.out.print(" Enter the total dollar amount of sales for this year."); salesAmount=keyboard.nextDouble( ); if ( salesAmount >= 320000 ) { System.out.println( " Your total compensation for this year is " + ( 0.0925 * salesAmount + 30000 )); } if ( salesAmount < 320000 ) { System.out.println( " Your total compensation for this year is " + ( 0.08 * salesAmount + 30000 )); } }``` //The above code compiled correctly and is working. This is where I get lost. I need a table with two columns to be created. It must be populated with the user's input for the sales amount in the first column. The program must also add the commission earned for that amount with the annual salary and place it in the second column.// //I also need the table to be populated with figures created by increasing the sales amount in increments of 5000 until the amount is greater than or equal to 1.5 * times the user sales amount (In the first column). The program must also add the commission total with the annual salary for each amount and display it in the second column.// //Does anyone have any suggestions about how the user input can be manipulated and moved into a table?// Last edited by Basic Chaos; 10-26-2012 at 04:43 PM..
 10-25-2012, 05:39 PM PM User | #2 Fou-Lu God Emperor     Join Date: Sep 2002 Location: Saskatoon, Saskatchewan Posts: 16,595 Thanks: 4 Thanked 2,597 Times in 2,566 Posts Table is a bit ambiguous here. I assume you mean a tabular style command line output? That's done by simply using tabs. In Java, you simply provide the \t character to indicate a tab. Since this looks like a school assignment, I can't just provide you the code, but I can certainly provide an example: PHP Code: ``` System.out.println("firstcolumn\tSecondColumn\tThirdColumn");  ``` The \t is important, but you can separate these into multiple System.out.print instead of println to make it clearer. Make sure you finish with a println (even if you provide it with nothing), or add a \n for the last column at the end. As for incrementing, that indicates you need to loop to a condition and increase by an amount. A simple for loop can do this for you. Also, in the future please wrap your code in [php][/php] or [code][/code] tags to preserve the format.
 Users who have thanked Fou-Lu for this post: Basic Chaos (10-25-2012)
 10-25-2012, 09:10 PM PM User | #3 Basic Chaos New to the CF scene   Join Date: Oct 2012 Posts: 3 Thanks: 2 Thanked 0 Times in 0 Posts this is like what I need, but the data should be program generated not typed in by me Code: ```import java.awt.*; import javax.swing.*; class TableDemo { public static void main(String args[]) { JFrame frame = new JFrame("Commission Sample Table"); String columns[] = {"Total Sales","Total Compensation"}; Object data[][] = { {"\$400,000","\$62,000"}, {"405,000","\$67,000"}, {"410,000","\$67,925"} }; JTable table = new JTable(data,columns); frame.setVisible(true); frame.setBounds(0,0,600,600); frame.add(table.getTableHeader(),BorderLayout.PAGE_START); frame.add(table); } }``` Last edited by Basic Chaos; 10-26-2012 at 01:16 PM.. Reason: I edited this because I looked at my code ant it made no sense.
 10-26-2012, 04:51 PM PM User | #4 Fou-Lu God Emperor     Join Date: Sep 2002 Location: Saskatoon, Saskatchewan Posts: 16,595 Thanks: 4 Thanked 2,597 Times in 2,566 Posts Okay, using the swing JTable with the gui instead of the command line? That's no problem to do, but I'd recommend not using Object[][] as your data handling. Instead, use the TableModel of the JTable as it will accept a collection of object. The TableModel is easiest done with the DefaultTableModel (or you can write your own, but that's a more advanced feature). Its use is simply as such: PHP Code: ``` JFrame frame = new JFrame("Commission Sample Table");TableModel tmData = new DefaultTableModel();JTable table = new JTable(tmData);((DefaultTableModel)tmData).addColumn("Total Sales");((DefaultTableModel)tmData).addColumn("Total Compensation");                frame.getContentPane().add(new JScrollPane(table));frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setBounds(0, 0, 600, 600);frame.setVisible(true);  ``` Now, TableModel can be given new rows on the fly. This is still beneficial even if not responding to events; adding new records is simply accepting Object[] or vectors. For an example: PHP Code: ```     public static void insertCalculatedNumbers(DefaultTableModel tm, double dStart)    {        for (double d = dStart; d <= dStart * 1.5; d += 5000)        {            tm.addRow(new Object[]{d, "Calculated Result Here"});        }    }  ``` Given a DefaultTableModel, this will increment dStart by 5000 until it hits 1.5x the size of dStart. It will insert a new row on each iteration. Calculated result is probably best done in another method instead of inline with this code.
 Users who have thanked Fou-Lu for this post: Basic Chaos (10-28-2012)
 10-28-2012, 07:35 PM PM User | #5 Basic Chaos New to the CF scene   Join Date: Oct 2012 Posts: 3 Thanks: 2 Thanked 0 Times in 0 Posts Thanks for your help. I think I understand now Last edited by Basic Chaos; 10-29-2012 at 08:33 AM.. Reason: To Provide a Somewhat Working Code
 10-28-2012, 08:18 PM PM User | #6 O.Ricky Banned   Join Date: Oct 2012 Location: Bangladesh Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts I unquestionably longed for to rise a acknowledgement to be means to appreciate we for all a glorious contribution we have been display on www.codingforums.com . My enlarged internet poke has right away been famous with great strategies to go over with my friends as well as family. we would demonstrate which most of us visitors essentially have been unquestionably sanctified to exist in a conspicuous village with really most undiluted people with profitable hints. we feel indeed beholden to have detected your web pages as well as demeanour brazen to so most some-more extraordinary mins celebration of a mass here. Thank we again for all a details.

 Bookmarks

 Tags java, table

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 12:19 PM.