Help writing a small program

hi i have to wrtie 2 classes, relating to stocks and shares, they only have to be fairly basic, one class is the Share class, and the 2nd class is the Portfolio class. i have written th share class, but now going onto the portfolio one i am a bit stuck.
i have created the basic structure with the attributes needed, but then i need to perform 1operation on the data
1) load data from a file ( by repeatadly calling readData on Share objects)
so what i need to know is the code i need to write in order to load data into this portfolio class, from the share class? does anyone have an ideas?

well ok i have been given 2 classes one called infile one called outfile, but then it says the basic methods that need to be performed on a portfolio object are
load data from a file( by repeatadly calling readData on Share objects)
this is all i have been provided with, so i have to beable to do the bit in the brackets

Similar Messages

  • Help Required in writing a small program

    Create ajava program to manage vehicles.the class vehicle must have five attributes

    maybe he cant figure out what five attributes a
    vehicle class can have :-)boolean hasSpinnningRims;boolean isPimped;int noOf Wheels;
    public final int LEFT_IN_MANCHESTER = 0;
    public final int LEFT_IN_BRADFORD= 1;
    public final int DELL_BOY = 3;

  • Help with a small program ..

    hey guyz .. how z it goen??
    i just wanna build a calculator using the swings ..
    in my calculator i want the JTextField to be at the top taking the whole length
    also i want the 16 buttons to be in a GridLayout under the JTextField just like the Windows one but i want the text to be centralized.. and here is the start ..
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Calculator extends JFrame
         JFrame frm = new JFrame();
         JButton [] set;
         JTextField txt = new JTextField("0");
         public Calculator ()
              super("Calculator");
              //this is what i ain't sure about
              /*for (int i = 0; i<16 ;i++)
                        set = new JButton() ;
                             set[0].setText("7");
                             set[1].setText("8");
                             set[2].setText("9");
                             set[3].setText("/");
                             set[4].setText("4");
                             set[5].setText("5");
                             set[6].setText("6");
                             set[7].setText("*");
                             set[8].setText("1");
                             set[9].setText("2");
                             set[10].setText("3");
                             set[11].setText("-");
                             set[12].setText("0");
                             set[13].setText(".");
                             set[14].setText("=");
                             set[15].setText("+");
                        add(set[i]);
              setSize (400,400);
              setLocation(240,312);
              setLayout(new GridLayout(4,4));
              //add(txt,????????????);
              //add(set,............);
              pack();
         public static void main(String[]args)
              Calculator calc = new Calculator();     
              calc.setVisible(true);

              /*for (int i = 0; i<16 ;i++)
                        set = new JButton() ;
                             set[0].setText("7");
                             set[1].setText("8");
                             set[2].setText("9");
                             set[3].setText("/");
                             set[4].setText("4");
                             set[5].setText("5");
                             set[6].setText("6");
                             set[7].setText("*");
                             set[8].setText("1");
                             set[9].setText("2");
                             set[10].setText("3");
                             set[11].setText("-");
                             set[12].setText("0");
                             set[13].setText(".");
                             set[14].setText("=");
                             set[15].setText("+");
                        add(set[i]);
    Lets see what you do on the first iteration. i = 0. You instantiate the JButton at index i, and then you perform operations on the non instantiated objects in the rest of the array upon each iteration. Can you see what you are doing wrong?
    By the way, JButton Constructor takes in a String parameter as a title. You don't need to setText if you instantiate the objects correctly. Take a look at the JButton documentation.

  • Need help writing small program!

    Hi. I'm learning Java programming, and I need help writing a small program. Please someone help me.
    Directions:
    Create a program called CerealCompare using an if-then-else structure that obtains the price and number of ounces in a box for two boxes of cereal. The program should then output which box costs less per ounce.

    class CerealCompare {
        public static void main(String[] args) {
            // your code goes here
    }Hope that helps.
    P.S. Java does not have an if-then-else statement.

  • Help with a simple program.

    I need some help writing a simple program. Can anybody help??
    thanks to all.
    2. HTML Java Source Code Reserved Word Highlighter
    Write a program that inputs a Java source code file and outputs a copy of that file with Java keywords surrounded with HTML tags for bold type. For example this input:
    public class JavaSource
    public static void main ( String[] args )
    if ( args.length == 3 )
    new BigObject();
    else
    System.out.println("Too few arguments.");
    will be transformed into:
    <B>public</B> <B>class</B> JavaSource
    <B>public</B> <B>static</B> <B>void</B> main ( String[] args )
    <B>if</B> ( args.length == 3 )
    <B>new</B> BigObject();
    <B>else</B>
    System.out.println("Too few arguments.");
    In a browser the code will look like this:
    public class JavaSource
    public static void main ( String[] args )
    if ( args.length == 3 )
    new BigObject();
    else
    System.out.println("Too few arguments.");

    Here is something that may get you started...
    import java.io.*; 
    import java.util.*; 
    public class HtmlJava{
         public static void main(String arg[]){
              if(arg.length!=1){
                   System.out.println("Usage java HtmlJava sourceFile");       
              else
                   new HtmlJava(arg[0]);
         HtmlJava(String source){
              try{
                   BufferedReader sourceReader=new BufferedReader(new InputStreamReader(new FileInputStream(source)));
                   BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(source+"Html.txt")));  
                   Vector keywords=new Vector();
                   addKeywords(keywords);
                   String line;
                   StringTokenizer tokenizer=null;
                   String word;
                   while((line=sourceReader.readLine () )!=null){
                        tokenizer=new StringTokenizer(line);
                        while(tokenizer.hasMoreTokens()){
                             word=tokenizer.nextToken();
                             if(keywords.contains(word)){
                                  writer.write(""+word+" ");
                             else{
                                  writer.write(word+" ");
                        writer.write("\r\n");
                   writer.close();
                   sourceReader.close(); 
                   System.out.println("Output File written to "+source+"Html.txt"); 
              catch(Exception ex){
                   ex.printStackTrace();      
         private void addKeywords(Vector keywords){
              keywords.addElement ( "abstract");
              keywords.addElement( "boolean");
              keywords.addElement( "break");
              keywords.addElement( "byte");
              keywords.addElement( "byvalue");
              keywords.addElement( "case");
              keywords.addElement( "cast");
              keywords.addElement( "catch");
              keywords.addElement( "char");
              keywords.addElement( "class");
              keywords.addElement( "const");
              keywords.addElement( "continue");
              keywords.addElement( "default");
              keywords.addElement( "do");
              keywords.addElement( "double");
              keywords.addElement( "else");
              keywords.addElement( "extends");
              keywords.addElement( "false");
              keywords.addElement( "final");
              keywords.addElement( "finally");
              keywords.addElement( "float");
              keywords.addElement( "for");
              keywords.addElement( "future");
              keywords.addElement( "generic");
              keywords.addElement( "goto");
              keywords.addElement( "if");
              keywords.addElement( "implements");
              keywords.addElement( "import");
              keywords.addElement( "inner");
              keywords.addElement( "instanceof");
              keywords.addElement( "int");
              keywords.addElement( "interface");
              keywords.addElement( "long");
              keywords.addElement( "native");
              keywords.addElement( "new");
              keywords.addElement( "null");
              keywords.addElement( "operator");
              keywords.addElement( "outer");
              keywords.addElement( "package");
              keywords.addElement( "private");
              keywords.addElement( "protected");
              keywords.addElement( "public");
              keywords.addElement( "rest");
              keywords.addElement( "return");
              keywords.addElement( "short");
              keywords.addElement( "static");
              keywords.addElement( "super");
              keywords.addElement( "switch");
              keywords.addElement( "synchronized");
              keywords.addElement( "this");
              keywords.addElement( "throw");
              keywords.addElement( "throws");
              keywords.addElement( "transient");
              keywords.addElement( "true");
              keywords.addElement( "try");
              keywords.addElement( "var");
              keywords.addElement( "void");
              keywords.addElement( "volatile");
              keywords.addElement( "while");
    }Hope it helped

  • Need help writing host program using LabView.

    Need help writing host program using LabView.
    Hello,
    I'm designing a HID device, and I want to write a host program using National Instrument's LabView. NI doesn't have any software support for USB, so I'm trying to write a few C dll files and link them to Call Library Functions. NI has some documentation on how to do this, but it's not exactly easy reading.
    I've written a few C console programs (running Win 2K) using the PC host software example for a HID device from John Hyde's book "USB by design", and they run ok. From Hyde's example program, I've written a few functions that use a few API functions each. This makes the main program more streamlined. The functions are; GetHIDPath, OpenHID, GetHIDInfo, Writ
    eHID, ReadHIC, and CloseHID. As I mentioned, my main program runs well with these functions.
    My strategy is to make dll files from these functions and load them into LabView Call Library Functions. However, I'm having a number of subtle problems in trying to do this. The big problem I'm having now are build errors when I try to build to a dll.
    I'm writing this post for a few reasons. First, I'm wondering if there are any LabView programmers who have already written USB HID host programs, and if they could give me some advice. Or, I would be grateful if a LabView or Visual C programmer could help me work out the programming problems that I'm having with my current program. If I get this LabView program working I would be happy to share it. I'm also wondering if there might already be any USB IHD LabView that I could download.
    Any help would be appreciated.
    Regards, George
    George Dorian
    Sutter Instruments
    51 Digital DR.
    Novato, CA 94949
    USA
    [email protected]
    m
    (415) 883-0128
    FAX (415) 883-0572

    George may not answer you.  He hasn't been online here for almost eight years.
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice

  • How would I set this small program to activate every 120 seconds?

    I have this small program that writes the value 0 to a file, but I want it to only activate every 120 seconds, so it doesn't take up a bunch of system resources by constantly running. Can I make it pause for 120 seconds, or set a timer for it, in such a way that it won't make my PC run slow? Here's my code. Thanks if you can help.
    import java.util.*;
    import java.io.*;
    import java.io.File;
    public class Purge extends Random implements Serializable {
         public Purge () {
              writePrimDoubles();
         public static void main (String [] args) {
              Purge test = new Purge();
         public void writePrimDoubles() {
              DataOutputStream outStream;
              long timerStart;
              long timerEnd;
              long size;
              int a = 1;
              try     {          
                   while (a==1) {
                        outStream = new DataOutputStream
                             (new FileOutputStream("packetlog.txt"));
                        timerStart = System.currentTimeMillis();
                        outStream.writeBytes("0");
                        timerEnd = System.currentTimeMillis();
                        outStream.close();
              catch(IOException e) {
                   System.out.println("Error writing to file");
    }

    java.util.Timer, I think may do the trick.

  • Help with a java program

    Hello. I'm posting in these forums because I really don't know where else to go. I have been trying for the past several days to figure out how to go about writing my program but to no avail. The project requires reading many lines each containing several different elements from a datafile named "DATA". A few examples of some lines from that file:
    Department number/Number of units received/Date on which the shipment arrived/Expiration date/Name of Object
    0 78 02/03/2001 02/12/2001 apples
    0 26 06/03/2001 06/10/2001 lemons
    3 62 03/06/2001 03/14/2001 hamburger
    What we have to do with this data is read all of it from the file, separate all the different elements, and based on input from the user, sort everything and print it out to the screen. If the user enters 03, the program will show everything that arrived and expired within the month of March, sorted by date.
    It is a pretty basic program, but my problem is that I have no idea how to go about reading in this data, putting it into a vector (probably the easiest method) or separating the different elements. I've gone to websites and looked through my textbooks but they didn't help much. If anyone has any resources that could help for writing such a program, or if anyone could offer help in writing the program, I would really appreciate it. I can also show what I've managed to write so far, or more details on how the program should work. Thanks in advance.
    Matt

    since im not a pro like some of the guys on here :),
    and believe me thiers people here, who could write your whole app in a hour.
    anyways my advice , would be to do a search on the forums for useing.bufferReader()
    i think you would need to read the file in with bufferreader then split up each line useing the stringTokenizer and then use some algorithm to compare
    the values and split them up into your vector arrays as needed.
    thier is also fileinputStream i think you can use that too.

  • Small issue in small program(code) that need to be fixed ...

    Hi Guys ,
    i need ur help in some kind of issue( technique thing ;) ). i have done small program that ask for numbers then print them and told u how many Odd numbers.
    the issue that i have it, is that the program when print the result (the numbers) it print them correctly but print with them word "null".
    i need ur help to avoid that word.
    How???
    sorry for my bad english, since i don't know english well.
    and thank u soo much for ur help ;)
    this is the code:-
    import javax.swing.JOptionPane;
         // takes number from the user and show u the odd number and print them
    public class Odd {
         public static void main(String[] args) {
              String n,m;
              int a=0;
              int x=1;
              String result = null;
              n=JOptionPane.showInputDialog(null,"How many number do you want to check for the odd ? ");
              int n1 = Integer.parseInt(n);
              int array[]=new int[n1];
              for(int i=0;i<array.length;i++){
                   m=JOptionPane.showInputDialog(null,"Enter number "+x);
                   array[i] = Integer.parseInt(m);
                   result=result+array[i]+"\n";
                   x++;
                   if( array%2 !=0 )
                        a++;
                   JOptionPane.showMessageDialog(null,"The Numbers Are :\n"+ result);
                   JOptionPane.showMessageDialog(null,"The Odd Numbers are:\n " a" Numbers");

    First of all you don't need to feel yourself sorry. Here is a Java forum not an english literature forum and at least I can understand you. At least you don't try to write in your language which we probably may not understand.
    Secondly if you initialize your String value like that you have the null value. You can initialize it like
    String result = new String(); and try it again.

  • Errors with small program

    Ok, I'm trying to get a small program to compile on my windows box. I'm a student and in the lab (on a linux box) the program compiled fine. I keep getting this error:
    Easypieces.java:52: cannot resolve symbol
    symbol : variable volume
    location: class EasyPieces
    System.out.println("Volume:" + volume);
    ^
    2 errors
    Here's the code:
    * Student should complete the five methods, document the class
    * and the methods, and test this well. You may remove the instructor
    * comments.
    public class EasyPieces {
    * Student should complete and document this method
    public void waterBalloons(int radius) {
         double cubedRadius = Math.pow(radius, 3);
         double volume;
         double volume = 4/3 * Math.PI * cubedRadius ;
    * Student should complete and document this method
    public void upsLoad(double computer, double monitor, double other) {
    * Student should complete and document this method
    public void carpool(int people) {
    * Student should complete and document this method
    public void checksum(int number, int base) {
    * Student should complete and document this method
    public void combinationLock() {
    * Instructor provided test cases. Student should add additional
    * test cases as necessary to make sure the program functions as
    * intended.
    public static void main(String[] args) {
    //Create an object of type EasyPieces to use for the testing
    EasyPieces testPiece = new EasyPieces();
    //Instructor provided test for waterBalloons
    testPiece.waterBalloons(6);
    System.out.println("Volume:" + volume);
    //Instructor provided test for upsLoad
    //testPiece.upsLoad(1.2,0.8,1.4);
    //System.out.println("----------------------------------------------------------------------");
    //Instructor provided test for carpool
    //testPiece.carpool(15);
    //System.out.println("----------------------------------------------------------------------");
    //Instructor provided test for checksum
    //testPiece.checksum(156,7);
    //System.out.println("----------------------------------------------------------------------");
    //Instructor provided test for combinationLock
    //testPiece.combinationLock();
    //System.out.println("----------------------------------------------------------------------");
    For some reason it doesn't want to print the variable out...
    Any help?
    Thanks, Greg

    << That code didn't compile on your linux box, guaranteed. :o) >>
    This program didn't but one similiar to it did, and I get the same error message when I try to compile it on my windows box:
    public class zeller {
         public static void main(String args[]) {
              int month = 2;
              int day = 29;
              int year = 2000;
              if (month == 2) {
                   year = year -1;
                   day = day +3;
              if (month == 1) {
                   year = year -1;
                   day = day;
              if (month == 3) {
                   year = year;
                   day = day + 2;
              if (month == 4) {
                   day = day + 5;
              if (month == 5) {
                   day = day;
              if (month == 6) {
                   day = day + 3;
              if (month == 7) {
                   day = day + 5;
              if (month == 8) {
                   day = day +1;
              if (month == 9) {
                   day = day +4;
              if (month == 10) {
                   day = day +6;
              if (month == 11) {
                   day = day +2;
              if (month == 12) {
                   day = day +4;
              int sum = year + year/4 - year/100 + year/400 + day;
              int dayOfWeek = sum % 7;
              System.out.println(dayofweek);
    I get this error in windows (the same error I get with the other program):
    D:\JAVA\jdk142\bin>javac zeller.java
    zeller.java:67: cannot resolve symbol
    symbol : variable dayofweek
    location: class zeller
    System.out.println(dayofweek);
    ^
    1 error
    Greg

  • Help writing a excel macro to do a copy of 4 cells and paste transpose. I need to loop the copy and paste through 6900 rows of data.

      I need help writing a excelmacro to do a copy of 4 cells and paste transpose.  I need to loop the copy and paste through 6900 rows of data.  I started the macro with two rounds of copying & paster transposed but I need help getting it
    to loop through all rows.  Here is what macro looks like now.
        Range("I2:I5").Select
        Application.CutCopyMode = False
        Selection.Copy
        Range("J2").Select
        Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=True
        Range("I6:I9").Select
        Application.CutCopyMode = False
        Selection.Copy
        Range("J6").Select
        Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=True
    End Sub

    Thanks Jim for the solution above.
    Hi Brogents,
    Thanks for posting in our forum. Please note that this forum focuses on questions and feedback for Microsoft Office client. For any
    VBA/Macro related issues, I would suggest you to post in the forum of
    Excel for Developers, where you can get more experienced responses:
    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=exceldev
    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.
    Regards,
    Ethan Hua
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • Need Help Writing Server side to submit form via API

    Hey
    I need help writing a serverside application to submit
    information via API to a separate server.
    I have a client that uses constant contact for email
    campaigns. We want to add to her website a form taht submits the
    information needed to subscribe to her email list, to constant
    contact via API.
    FORM.asp :: (i got this one under control)
    name
    email
    and submits to serverside.asp
    SERVERSIDE.ASP
    In serverside.asp i need to have
    the API URL
    (https://api.constantcontact.com/0.1/API_AddSiteVisitor.jsp)
    username (of the constant contact account)
    password (of the constant contact account)
    name (submited from form.asp)
    email (submitted from form.asp)
    redirect URL (confirm.asp)
    Can anyone help get me going in the right direction?
    i have tried several things i found on the net and just cant
    get anyone to work correctly.
    One main issue i keep having is that if i get it to submit to
    the API url correctly - i get a success code, it doesnt redirect to
    the page i am trying to redirect to.
    ASP or ASP.NET code would be find.
    THANKS
    sam

    > This does require server side programming.
    > if you dont know what that is, then you dont know the
    answer to my question. I
    > know what i need to do - i just dont know HOW to do it.
    If you are submitting a form to a script on a remote server,
    and letting
    that script load content to the browser, YOU have no control
    over what it
    loads UNLESS there is some command you can send it that it
    will understand.
    No amount of ASP on your server is going to change what the
    remote script
    does.
    http://www.constantcontact.com/services/api/index.jsp
    they only allow their customers to see the instructions for
    the API so i
    can't search to see IF there is a redirect you can send with
    the form info.
    But posts on their support board say that there is.
    Alan
    Adobe Community Expert, dreamweaver
    http://www.adobe.com/communities/experts/

  • Help! All CS3 programs continuously crash!!

    I need help - all my CS3 programs have begun crashing! It's happened more frequently since installing Lepoard - but now its unbearably happening.
    I've called Adobe and was told that I can't get tech support because CS4 is now live - though Max was cool and suggested that I reset preferences (Ctrl+Option+Apple+Shift).
    Despite that quick fix - these programs continue to crash! NEED HELP PLEASE!

    Neil,
    Adobe called me on Wednesday stiil couls not figure out the problem, told me to go to Apple. So , I went to apple, upgraded my Ram to 4GB, full diagnostics, and did an archive reinstall.
    Worked great for 2 days. Thought I was in the clear, then today, I opened photoshop to open a few very small jpgs. (I had firefox open) Then all of a sudden Adobe installer show up in my dashboard and shows percentage numbers like it is installing something or getting ready to, and photoshop crashes. The adobe updater asks me if I want to install updates, I said no and cancelled out. All along I have been telling adobe that I think the problem has something to do with my registration. On all of my console crashes reports, adobe crashes right after all of theses notes about registration. I have had to re-register my adobe at least 3 times. The 1st time this all happened a technician told me I somehow had an educational copy, made me uninstall and then install a volume license with a new serial number. I told him none of this made sense as I bought a factory sealed CS3 Design Premiun form the apple store. I also told him I didn't want a volume license, I wanted what I purchased. He told me I had to do it. So I did and it didn't work. So the next technician I got, said that was crazy and she can't believe he made me do that, and that my original copy of CS# and serial number were fine and then had me uninstall that and reinstall mine. Naturally, every time I uninstall and reinstall adobe prompts me to register, which I do. But I feel like either adobe has some conflict and kicks me off because it thinks my registration is invalid or Adobe is conflicting with something on my computer. Which no- one can figure out- mean while I sill can't get any work done. Everyone who has looked at my computer said this is crazy, my computer is fine and can easily handle what i do, I don't have anything crazy on here that is supposed to conflict and I triple checked before I bought everything and have multiple times since. I still can not get any work done and am desparate!! Adobe is closed over the weekend and I have to be able to work on Monday.

  • Help needed in c programming

    hi
    i am writing a c program using fstream.
    can anyone tell me where can i post my questions here in apple discussion board?
    i just don't know in which section does my problem fits.

    The main developer forum is here:
    http://discussions.apple.com/forum.jspa?forumID=727

  • PLEASE   CAN SOMEOME HELP ME INSTALL THIS PROGRAM????

    PLease  can someone help me install this program??  I am not computer literate.

    What program specifically are you struggling with? What operating system are you using? What happens when you try?

Maybe you are looking for