Landing : Athabascau University

Assignment 1 reflection

  • Public
By Osamah Sadeq August 27, 2022 - 2:23pm

Assignment 1 reflection

problem 1 – Multiplication Table.

The program is asking us to create a Java program that will generate a multiplication table. Starting with 1x table, followed by 2x, then 3x, 4x, 5x, and so on we generate a table from 1x to 12x.

The problem was not difficult, and it was straightforward. I started the code with the name with the class name, then the main method.  I also started with one method for the multiplication table that used a nested for loop to do the multiplication for the numbers between 1 and 12. Also, I included an if statement in the code. I learned them from the textbook Intro to java programming. For the editor, I used sublime text to write my code as well as an online compiler to compile them.

In the end, I called the main method to execute the program, and it works perfectly with no issues. The program printed the multiplication part, but the lines were not perfect, so I had to check where the mistake was and fix it. Finally, I added some comments and organized the code. I would say that the program seemed to be easy and fun to work on. Thankfully, I did not run into any issues throughout this coding problem.


Problem 2 - Convert User Temperature

This problem was more advanced than the previous problem where we needed to accommodate user input and that gave me a couple of errors to worry about. The program was asking us to write a code that will convert temperature from Fahrenheit to Celsius and vice versa.  Java scanner was part of my code, as it is easy to handle the user input. Where the scanner is used to take input directly from the user or read from a file. Also, I started the code with the class name and the main method, then initialized all the variables that will help me get the program to run with no issues. As well as initializing a new scanner call statement, where it points to the input stream passed as an argument.  We were provided with the formulas that are responsible for converting from Fahrenheit to Celsius and the other way around which T(F) = (T(C) * 9 / 5) + 32 and T(C) = (T(F) − 32 ) * 5 / 9. I used a do-while loop as I found it easier than other statements for this problem.

The program was working but it gave me the wrong conversion number because I used the Fahrenheit formula for Celsius and the other way around. The program worked fine after that. If the user enters a correct input, then the results will pass the criteria, whereas incorrect inputs
result will request a new input. Once a conversion has been completed, the
program then asks if the user wishes to do another conversion or not. If the user decided to quit the conversation, then it will say Thank you. Goodbye.



Problem 3 - Temp Conversion Table

This program required us to create a table of temperature conversions. The program will show a temperature conversions table, starting from -40 degrees for both F and C, and running at 5-degree intervals for 100 entries in each table. Basically, the table will be split into 2 parts, each part has F and C temperatures, both of them starting at -40.000. The left side of the table will be converting from F to C. -35 F will be -37 C. The right side of the table will be converting from C to F. -35 C will be -31 F. I started the code by the name of the class and the method of fahrenheitToCelsius to accept a temperature in Fahrenheit and convert it to Celsius, then declaring a variable to store the temperature in Celsius. The next is adding the formula that responsible for converting a temperature from Fahrenheit to Celsius, then the formula that responsible for converting from Celsius to Fahrenheit. Then I used a return statement to return a temperature in Celsius. The same thing happened with Fahrenheit. The code was ending with a for loop statement. Over all, this program was ok, although I had some errors at the beginning because the mixed up the 2 formulas.


Problem 4 - Java Help Menu


This program required us to create an interactive help system for Java programming. The system will incorporate a menu system that interacts with the user, and the appropriate help topic will be displayed, based on an input selection. The program was designed to make a looping structure until the user wishes to quit. We have to write a program that once we run, will display 5 statements in java to choose from. The statements are, If, Switch, For, While, and Do-while. If the user selects number 1 which is "If", then a description of this statement will pop up. There will be an option for the user to quit. "Thank you. Goodbye" will pop up. The program started with the name of the class and was followed by the main method, creating a scanner to take user choice input. Then, declaring a string. Then, using the do while loop, first we display the menu and then take the input from the user and using the switch statement we execute the operation which is chosen from the menu by the user. also, I used a switch statement to execute the choices for the menu. There is an option for the user to select x to exit the program, and it will say Thank you. Goodbye.


Program 5 - Display Prime Numbers


This program required us to write a program that writes a program that uses two nested for loops and the modulus operator (%) to detect and print all prime numbers from 1 to 10,000. Prime numbers are integral numbers that are only evenly divisible by themselves and one. Once we run the program we will get all of the prime numbers from 1 to 10,000. I used "for(int n=2;n<=10000;n++)" outer loop to run for 10,000 times. I started the program by the name of the class and then followed the main method. I also used for loop to run the numbers from 1 to 10000 times.


These comments are moderated. Your comment will not be visible unless accepted by the content owner.

Only simple HTML formatting is allowed and any hyperlinks will be stripped away. If you need to include a URL then please simply type it so that users can copy and paste it if needed.