Solution for Introduction to Programming Assignment - KOI ICT102
VerifiedAdded on 2022/11/17
|12
|1129
|91
Homework Assignment
AI Summary
This document presents a solution to an Introduction to Programming assignment (ICT102) from King's Own Institute (KOI). The assignment covers fundamental programming concepts using Java, including variable declaration, data types, arithmetic operations, user input using Scanner, array manipulation, and conditional statements. The solution demonstrates how to calculate stock transactions, analyze rainfall data, process sales figures for different departments, and search through arrays of strings. The provided Java code includes clear comments and demonstrates problem-solving approaches for each question, providing a comprehensive understanding of the assignment requirements and programming logic.

Running head: INTRODUCTION TO PROGRAMMING
Introduction to programming
Name of the Student
Name of the University
Authors note
Introduction to programming
Name of the Student
Name of the University
Authors note
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

1INTRODUCTION TO PROGRAMMING
Q1.
public class Question1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int sharenum = 1000;
//number of shares
double btstockprice = 32.87;
//buy price of stocks
double commrate = .02;
//commission rate
double sstockprice = 33.92;
double buyamnt = (sharenum * btstockprice);
double buycomm = ((sharenum * btstockprice) * commrate);
double salamnt = (sharenum * sstockprice);
double salcomm = ((sharenum * sstockprice) * commrate);
Q1.
public class Question1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int sharenum = 1000;
//number of shares
double btstockprice = 32.87;
//buy price of stocks
double commrate = .02;
//commission rate
double sstockprice = 33.92;
double buyamnt = (sharenum * btstockprice);
double buycomm = ((sharenum * btstockprice) * commrate);
double salamnt = (sharenum * sstockprice);
double salcomm = ((sharenum * sstockprice) * commrate);

2INTRODUCTION TO PROGRAMMING
System.out.println(" Total amount paid by Joe for purchsing Stock \t $" +
buyamnt);
System.out.println(" Total amount paid by for Brockers Commision \t $" +
buycomm);
System.out.println(" Total amount acquired by Joe by selling the Stock \t $" +
salamnt);
System.out.println(" Total amount paid to broker after sales of stocks \t $" +
salcomm);
System.out.println(" Total profit amount after the sale of Stocks \t $" +
(salamnt - buyamnt));
}
}
System.out.println(" Total amount paid by Joe for purchsing Stock \t $" +
buyamnt);
System.out.println(" Total amount paid by for Brockers Commision \t $" +
buycomm);
System.out.println(" Total amount acquired by Joe by selling the Stock \t $" +
salamnt);
System.out.println(" Total amount paid to broker after sales of stocks \t $" +
salcomm);
System.out.println(" Total profit amount after the sale of Stocks \t $" +
(salamnt - buyamnt));
}
}
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

3INTRODUCTION TO PROGRAMMING
Q2.
public class Q2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int numyears;
int months = 12;
double[] rainfall = new double[12];
Q2.
public class Q2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int numyears;
int months = 12;
double[] rainfall = new double[12];
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

4INTRODUCTION TO PROGRAMMING
double sum = 0;
double average = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Number of years");
numyears = sc.nextInt();
for (int o = 1; o <= numyears; o++) {
for (int y = 0; y < months; y++) {
//double sum = 0;
System.out.println(" Enter the rainfall for month " + (y + 1));
rainfall[y] = sc.nextDouble(); //taking input from the user
sum = sum + rainfall[y];
//Calculating the sum
System.out.println(sum);
average = sum / months;
//Calculating the average
}
double sum = 0;
double average = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Number of years");
numyears = sc.nextInt();
for (int o = 1; o <= numyears; o++) {
for (int y = 0; y < months; y++) {
//double sum = 0;
System.out.println(" Enter the rainfall for month " + (y + 1));
rainfall[y] = sc.nextDouble(); //taking input from the user
sum = sum + rainfall[y];
//Calculating the sum
System.out.println(sum);
average = sum / months;
//Calculating the average
}

5INTRODUCTION TO PROGRAMMING
System.out.println("Average for the year " + numyears + " and average
rainfall is " + average);
sum = 0;
}
}
}
System.out.println("Average for the year " + numyears + " and average
rainfall is " + average);
sum = 0;
}
}
}
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

6INTRODUCTION TO PROGRAMMING
Q3
*/
public class Q3 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
//double[][] salesarr = new double[6][4];
double sum1 = 0;
Q3
*/
public class Q3 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
//double[][] salesarr = new double[6][4];
double sum1 = 0;
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

7INTRODUCTION TO PROGRAMMING
Scanner sc = new Scanner(System.in);
//System.out.print("Enter 2D array size for storing the Sales of the departments :
");
System.out.println("Enter the value of Number of Departments");
// Scanner sc=new Scanner(System.in);
int rows = sc.nextInt();
System.out.println("Enter the value of Number of Quarters");
int columns = sc.nextInt();
System.out.println("Enter the sales of the departments : ");
int twoD[][] = new int[rows][columns];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
System.out.println("Enter the Sales for Department " + (i + 1) + " and for
qurater " + (j + 1));
twoD[i][j] = sc.nextInt();
//sum1 = sum1 + twoD[i][j];
Scanner sc = new Scanner(System.in);
//System.out.print("Enter 2D array size for storing the Sales of the departments :
");
System.out.println("Enter the value of Number of Departments");
// Scanner sc=new Scanner(System.in);
int rows = sc.nextInt();
System.out.println("Enter the value of Number of Quarters");
int columns = sc.nextInt();
System.out.println("Enter the sales of the departments : ");
int twoD[][] = new int[rows][columns];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
System.out.println("Enter the Sales for Department " + (i + 1) + " and for
qurater " + (j + 1));
twoD[i][j] = sc.nextInt();
//sum1 = sum1 + twoD[i][j];

8INTRODUCTION TO PROGRAMMING
}
//System.out.println("");
//System.out.println("Total sales for department " + (i + 1) + " is" + sum1);
}
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
System.out.println("Sales of the departments " + (i + 1) + " and for qurater "
+ (j + 1) + " is " + twoD[i][j]);
//twoD[i][j] = sc.nextInt();
sum1 = sum1 + twoD[i][j];
}
//System.out.println("");
System.out.println("Total sales for department " + (i + 1) + " is" + sum1);
}
System.out.println("The Average sales of quarter is " + (sum1 / rows));
//f//or (int k = 1; k <= 6; k++) {
}
//System.out.println("");
//System.out.println("Total sales for department " + (i + 1) + " is" + sum1);
}
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
System.out.println("Sales of the departments " + (i + 1) + " and for qurater "
+ (j + 1) + " is " + twoD[i][j]);
//twoD[i][j] = sc.nextInt();
sum1 = sum1 + twoD[i][j];
}
//System.out.println("");
System.out.println("Total sales for department " + (i + 1) + " is" + sum1);
}
System.out.println("The Average sales of quarter is " + (sum1 / rows));
//f//or (int k = 1; k <= 6; k++) {
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

9INTRODUCTION TO PROGRAMMING
// for (int l = 1; l <= 4; l++) {
//System.out.println(" The sales for division " + k + "is " + salesarr[k][l]);
//}
// }
}
}
Q4.
public class Q4 {
// for (int l = 1; l <= 4; l++) {
//System.out.println(" The sales for division " + k + "is " + salesarr[k][l]);
//}
// }
}
}
Q4.
public class Q4 {
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

10INTRODUCTION TO PROGRAMMING
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String[] firstName = {"Jhon", "Caly", "Justin", "Judith", "Daniel", "Trisha",
"Daniel"};
String[] phonenum = {"225-5241", "258-147", "963-852", "862-741", "987-
456", "745-965", "325-147", "865-245", "987-124", "258-964"};
System.out.println("Enter the initials you want to look for");
Scanner sc = new Scanner(System.in);
String inp = sc.next();
for (int i = 0; i < 10; i++) {
if (firstName[i].contains(inp))
//comparing the user input with all the available array elements
{
Checking the name array if the
System.out.print(firstName[i]);
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String[] firstName = {"Jhon", "Caly", "Justin", "Judith", "Daniel", "Trisha",
"Daniel"};
String[] phonenum = {"225-5241", "258-147", "963-852", "862-741", "987-
456", "745-965", "325-147", "865-245", "987-124", "258-964"};
System.out.println("Enter the initials you want to look for");
Scanner sc = new Scanner(System.in);
String inp = sc.next();
for (int i = 0; i < 10; i++) {
if (firstName[i].contains(inp))
//comparing the user input with all the available array elements
{
Checking the name array if the
System.out.print(firstName[i]);

11INTRODUCTION TO PROGRAMMING
System.out.print("\t");
System.out.println(phonenum[i]);
}
}
}
}
System.out.print("\t");
System.out.println(phonenum[i]);
}
}
}
}
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide
1 out of 12
Related Documents
Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.





