0% found this document useful (0 votes)
2 views

Program Review Table

The document summarizes examples of programming concepts used in a student's portfolio code. It includes examples of variables, input/output, choices using a switch statement, loops to display stock holdings, input validation, methods to organize the code, use of arrays to store stock data, and creating objects from a Stock class. The examples are accompanied by brief comments explaining how each concept is implemented in the code.

Uploaded by

Subhan Khan
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Program Review Table

The document summarizes examples of programming concepts used in a student's portfolio code. It includes examples of variables, input/output, choices using a switch statement, loops to display stock holdings, input validation, methods to organize the code, use of arrays to store stock data, and creating objects from a Stock class. The examples are accompanied by brief comments explaining how each concept is implemented in the code.

Uploaded by

Subhan Khan
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Student ID: 2403848

Programming Example code in PortfolioApp.java Comment


Concept
(1 mark each =
8 marks)
char choice; // Line 32
variables int idChoice = kb.nextInt(); // Line 86 These are just few of the examples
of variables in my code. In line 32 I
assigned choice to char and then
later used it in a switch statement.
In line 86 I incorporated a user
input (scanner) with initialising the
variable.

int sharesIn = kb.nextInt(); // Line 103


input/output In line 103, I had asked the user to
System.out.println("You have successfully sold " + sharesIn + " shares of " + stocks[idChoice-1].getName() + enter in the number of shares they
"."); // Line 105 would like to sell.

In line 105, the output used the


print statement to show the amount
the user had inputted to sell.

3
switch(choice) // Line 48
choices { This is an example of a switch
case'1': displayStocks(); break; statement I used to allow the user
case'2': buyShares(); break; to choose the feature they wanted
case'3': sellShares(); break;
to use. Each case links to a
case'4': repriceShare(); break;
case'5': totalValue(); break;
method which was written later
case'6': break; down the code.
default: System.out.println("Options 1-6 only please.");
}

System.out.println("These are your current stock holdings:"); // Line 73


loops for (int i=0 ; i <= 4 ; i++) To display the current stock
{ holdings of the user, I used a for
System.out.println(i+1 + " - " + stocks[i].getName()); loop to print them out. This saved
}
me time and allowed me to write in
less lines.

4
switch(choice)
input validation { In this do while loop, I used the
case'1': displayStocks(); break; switch statement which gave the
case'2': buyShares(); break; user a choice. But in a scenario in
case'3': sellShares(); break;
which the user doesn’t give the
case'4': repriceShare(); break;
case'5': totalValue(); break;
correct input – I used the ‘default:’
case'6': break; function to display a message to
default: System.out.println("Options 1-6 only please."); the user to enter in from the correct
} range.
}while(choice != '6');

static void runProgram() // Line 13


methods static void mainMenu() // Line 30 These are just a few of the
static void listOfstocks() // Line 61 methods I have written in my code.
My main method only has 1 line of
code in it which calls another
method etc.

These makes it easier to


understand whats going on in the
code and easier to see errors in
the future.

5
static Stock[] stocks = new Stock[5]; // Line 6
arrays An array I used to store all 5
stocks[0] = apple; // Line 21 stocks. I declared the array in line
stocks[1] = microsoft; 6 and made it static so its visible to
stocks[2] = tesla;
the whole code.
stocks[3] = amazon;
stocks[4] = accenture;
From line 21, I added each stock to
a location in the array individualy.

Stock apple = new Stock("Apple", 80, 34.5, 1); // Line 15


classes/objects Stock microsoft = new Stock("Microsoft", 85, 23, 2); An example of me creating objects
Stock tesla = new Stock("Tesla", 75, 45, 3); from the class, Stock.
Stock amazon = new Stock("Amazon", 78, 40, 4);
Stock accenture = new Stock("Accenture", 90, 15, 5);

6
7

You might also like