Over the course of my studies, I've had the opportunity to work on a number of Java projects, both in the classroom and on my own time. Some of these are side projects I've pursued out of personal interest, while others were completed as part of coding classes. You should be able to copy and paste them to a java compiler
Calorie Counter: This is a Calorie counter that I made using java. Copy and paste into any java IDE to run
import java.util.*;
public class CalorieCounter{
static Scanner scnr = new Scanner(System.in);
static int numFood=50;
static int[] calories=new int[numFood];
static String[] food = new String[numFood];
static int day;
static int[] days;
public static void main(String [] args){
int[] calories=new int[numFood];
String[] food = new String[numFood];
4
days = new int[365];
for(int i=0; i<365;i++){
days[i]= i;
}
System.out.println("Enter the day:");
day = scnr.nextInt();
System.out.println ("MAIN MENU\n 0- Exit, 1- List,2- Add/Modify, 3- Total"); // menu option to add to a certain day or list, modify
System.out.print("Select an option: ");
int menuOption = scnr.nextInt();
while(menuOption !=0){
// Menu limit 0-4
while(menuOption >3 || menuOption<0){ // reask menu with while loop
System.out.println("Value is out of range. Please Try again...");
System.out.println ("\nMAIN MENU\n 0- Exit, 1- List, 3- Add/Modify, 4- Total");
System.out.print("Select an option: ");
menuOption = scnr.nextInt();
}
// assign numbers to menu
if (menuOption == 0){
exit();
}
else if (menuOption == 1){
list(calories, food);
}
else if (menuOption == 2){
addModifyCals(calories,food);
}
else if (menuOption == 3){
total(calories);
}
if (menuOption >4 || menuOption<0){
System.out.println("Value is out of range. Please Try again..1.");
}
System.out.println ("MAIN MENU\n 0- Exit, 1- List,2- Add/Modify, 3- Total"); // reask
System.out.print("Select an option: ");
menuOption = scnr.nextInt();
}
}
// calculates the toatl calories for the that day
public static void total(int[] calories){
int sum=0;
for (int i=0;i<numFood;i++){
sum = sum +calories[i];
}
System.out.println("Total calories for today: "+sum);
}
// this is mainly to input calories, cant modify yet
public static void addModifyCals(int[] calories, String[] food){
//days[day]=all these infromation
System.out.println("How many items are you inputing today?");
numFood = scnr.nextInt();
for(int j=0;j< numFood;j++){
System.out.println("Enter the food you would like to input:");
food[j]= scnr.next();
}
for(int k=0;k< numFood;k++){
System.out.println("Enter the calories for "+food[k]+":");
calories[k] = scnr.nextInt();
}
}
// list all input for specific day
public static void list(int[] calories, String[] food){
System.out.println("What day would you like a list of ?");
int userDay = scnr.nextInt();
// System.out.println("Calender list"); // Title
// for(int j=0;j<6;j++){
System.out.println("Day "+days[userDay]+":");
for (int i=0;i< numFood;i++){
System.out.println(food[i] +": "+calories[i]+ " Calories.");
}
}
public static void exit(){ // Exit program, None Display the farewell
System.out.println("Thank you for using this software <Rabiat Sadiq>");
}
}
Output: Takes user input and logs calories for every day a year
Java
Grader: This is a grading system I had to make as a class project in my first java class
import java.util.*;
public class Sections{
static Scanner gIN = new Scanner (System.in); //Global gIN Scanner
static int gClassSize; //Declaring class size as global variable
static double[] gGrades; // Declaring grades as global variable
public static void exit(){ // Exit program, None Display the farewell
System.out.println("Thank you for using this software <Rabiat Sadiq>");
}
public static void listGrades(double [] gGrades){ //List one by one the grades sorted by the index number
System.out.println("LIST OF GRADES"); // Title
for(int i=0;i<gClassSize;i++){
System.out.println("Grade["+i+ "]: "+gGrades[i]); // prints each grade
}
}
public static void report(int gClassSize, double gGrades[]){ //Report Show the number of grades per letter (A – F) in the array
System.out.println ("GRADE REPORT");
getGradesLetter(gGrades);
}
public static void getGradesLetter(double [] gGrades){
int a=0,b=0,c=0,d=0,f=0;
for(int i=0;i<gClassSize;i++){ // adds one letter for each grade
if ((gGrades[i] <= 100.0) && (gGrades[i] >=90.0)){
a++;
}
else if ( (gGrades[i] < 90.0) && (gGrades[i] >= 80.0)){
b++;
}
else if( (gGrades[i] < 80.0)&& (gGrades[i] >=70)){
c++;
}
else if( (gGrades[i] < 70.0) && (gGrades[i] >=60)){
d++;
}
else if(( gGrades[i]) < (60.0) && (gGrades[i] > 0.0) ){
f++;
}
}
System.out.println("F: "+f);
System.out.println("D: "+d);
System.out.println("C: "+c);
System.out.println("B: "+b);
System.out.println("A: "+a);
}
public static void addModifyGrades(double []gGrades){ //Add or modify a grade of a validated value corresponding to a valid index
int gradesLim= gClassSize-1;
System.out.print("Enter the index from (0 to " +gradesLim+"): ");
int index = gIN.nextInt(); // getting user input for index to add/modify
while(index < 0|| (index > gClassSize-1)){ // make sure its in range
System.out.println("Value is out of range. Please Try again...");
System.out.print("Enter the index from (0 to " +gradesLim+"): ");
index = gIN.nextInt();
}
System.out.println("The current value of the grade in index "+ index +" is :"+gGrades[index]);
System.out.print("Enter the grade you want to assign (0.00- 100.00): "); // giving new grade
double newGrade;
newGrade= gIN.nextDouble();
while(newGrade <0.00|| newGrade >100.00) { // make sure its in range
System.out.println("Value is out of range. Please Try again...");
System.out.print("Enter the grade you want to assign (0.00- 100.00): ");
newGrade= gIN.nextDouble();
}
gGrades[index]= newGrade; // assigning the new grade
}
public static void swapGrades(double []gGrades){ //Swap grades between two valid indexes.
int gradesLim= gClassSize-1; // grades limit = 1 minus size of array
System.out.print("Enter the index from (0 to " +gradesLim+"): ");
int idxFrom = gIN.nextInt(); // get first number to swap
while(idxFrom < 0|| idxFrom > gradesLim){ // make sure its in range
System.out.println("Value is out of range. Please Try again...");
System.out.print("Enter the index from (0 to " +gradesLim+"): ");
idxFrom = gIN.nextInt();
}
System.out.print("Enter the index to (0 to " +gradesLim+") that is not "+idxFrom + ": ");
int idxTo = gIN.nextInt(); // // get second number to swap
while(idxTo< 0|| idxTo > gradesLim ||idxTo ==idxFrom){ // make sure its in range and cant enter same number
System.out.println("Value is out of range. Please Try again...");
System.out.print("Enter the index to (0 to " +gradesLim+") that is not "+idxFrom + ": ");
idxTo = gIN.nextInt();
}
SwapValues(idxFrom, idxTo, gGrades); // Swap grades method
}
public static void SwapValues(int idxFrom, int idxTo,double[]gGrades){ // to swap grades
double tempVal=0.0; // temporary value to hold while swapping
tempVal = gGrades[idxFrom];
gGrades[idxFrom] = gGrades[idxTo] ;
gGrades[idxTo] = tempVal;
}
public static void main(String[]args){
System.out.println("UTSA - Fall2021 - CS1083 – Section 002 - Project 2 - written by RABIAT SADIQ"); // heading
System.out.print("\nPlease, Enter the class size: ");
gClassSize = gIN.nextInt(); // class size input from user
while(gClassSize > 100 || gClassSize < 0){ // making sure user input for class size isnt over 100
System.out.println("Value is out of range. Please Try again...");
System.out.print("Please, Enter the class size: ");
gClassSize = gIN.nextInt();
}
double[] gGrades = new double[gClassSize]; // declaring grades array
System.out.println ("MAIN MENU\n 0- Exit, 1- List, 2- Report, 3- Add/Modify, 4- Swap Grades");
System.out.print("Select an option: ");
double menuOption = gIN.nextDouble(); // user input for menu option
while(menuOption !=0){
// Menu limit 0-4
while(menuOption >4 || menuOption<0){ // reask menu with while loop
System.out.println("Value is out of range. Please Try again...");
System.out.println ("\nMAIN MENU\n 0- Exit, 1- List, 2- Report, 3- Add/Modify, 4- Swap Grades");
System.out.print("Select an option: ");
menuOption = gIN.nextDouble();
}
// Menu Selection
if (menuOption == 0){
exit();
}
else if (menuOption == 1){
listGrades(gGrades);
}
else if (menuOption == 2){
report(gClassSize,gGrades);
}
else if (menuOption == 3){
addModifyGrades(gGrades);
}
else if (menuOption == 4){
swapGrades(gGrades);
}
if (menuOption >4 || menuOption<0){
System.out.println("Value is out of range. Please Try again..1.");
}
System.out.println ("\nMAIN MENU\n0- Exit, 1- List, 2- Report, 3- Add/Modify, 4- Swap Grades"); // reask
System.out.print("Select an option: ");
menuOption = gIN.nextDouble();
if(menuOption ==0){
exit();
}
}
}
}
OUTPUT: its takes list of inputed grades in array and is able to change, switch and replace grades, as well as list them.
Animations: moves shapes and colors
import java.util.*;
import java.awt.*;
public class Animations{
static DrawingPanel drawingPanel = new DrawingPanel(800,800);
static Color color = new Color(255,255,255);
static Graphics pen = drawingPanel.getGraphics();
static Scanner scnr = new Scanner (System.in);
static int numShapes;
static int numTimeShapes;
static String[] shapes =new String[20]; //{"Square" ,"Circle","Triangle"}; change later
static int[] shapeSize= new int[20];
static String[] shapeColor = {"Red", "Blue", "Pink", "Yellow", "Green", "Magenta", "Cyan ", "Orange", "Dark_gray",
"Light_gray", "Gray"};
static int[] directionShape= new int[20]; //{0,2,4,6}; // 0 for left,2 = up,4 =right,6 =down
static int[] shapeSpeed= new int[20];
static int[] posX = new int[20]; // x position of top left corner of every shape
static int [] posY = new int[20]; // y position of top left corner of every shape
static int width = 800; //init
static int height = 800;
public static void getShapeInformation() { //Will get the information for all the shapes from the user
for (int i=0;i<numShapes;i++){
System.out.print("Input type of shape:");
shapes[i] = scnr.next();
System.out.print("Input shape size:");
shapeSize[i] = scnr.nextInt();
System.out.print("Input the color of the shape");
shapeColor[i] = scnr.next();
System.out.print("Input the direction for the shape");
directionShape[i] = scnr.nextInt();
System.out.print("Input the speed of the shape");
shapeSpeed[i] = scnr.nextInt();
}
}
public static void initialPosition(DrawingPanel drawingPanel){ // Will calculate the top left position of every shape at the beginning of the program's execution
boolean booleanValue = true;
for(int i= 0;i<numShapes;i++){
//calculate and update initial x&y pos in i-th shape
posX[i] = ((width/2) - (shapeSize[i]/2));
posY[i] = ((drawingPanel.getHeight()/2) -(shapeSize[i]/2));
showShapes(drawingPanel,booleanValue);
drawingPanel.sleep(100);
}
}
public static void showShapesMoving(DrawingPanel drawingPanel){ //Will emulate the movement of the shapes
for (int i=0;i<numTimeShapes;i++){
showShapes(drawingPanel,false);
changePositions();
showShapes(drawingPanel, true);
drawingPanel.sleep(100);
}
}
public static void changePositions() { //Will calculate the new x and y positions of the top left corner of all the shapes
for(int i=0;i<numShapes;i++){
if(directionShape[i] == 0){ //moves left
posX[i] = posX[i] - shapeSpeed[i];
}
if(directionShape[i] == 2){ // moves up
posY[i] = posY[i] + shapeSpeed[i];
}
if(directionShape[i] == 4){ //moves right
posX[i] = posX[i] + shapeSpeed[i];
}
if(directionShape[i] == 6){ // moves down
posY[i] = posY[i] - shapeSpeed[i];
}
}
}
public static void showShapes(DrawingPanel drawingPanel, boolean booleanValue){ //Will call methods to change color and show the specific forms
for(int i =0;i<numShapes;i++){
if (booleanValue){
graphicsSetColor(drawingPanel,i);
}
else{
setNoColor(drawingPanel);
}
if(shapes[i].equals("Square")){
showSquare(drawingPanel,i,booleanValue);
}
else if(shapes[i].equals("Circle")){
showCircle(drawingPanel,i,booleanValue);
}
}
drawingPanel.sleep(100);
setNoColor(drawingPanel);
}
public static void setNoColor(DrawingPanel drawingPanel) { //Will set the color similar to the background (aka. WHITE), used to emulate the movement
pen.setColor(color.WHITE);
}
public static void graphicsSetColor(DrawingPanel drawingPanel, int i){ // Will set the color of the i-th shape to be printed
if (shapeColor[i].equals("Red")){
pen.setColor(color.RED);
}
else if (shapeColor[i].equals("Blue")){
pen.setColor(color.BLUE);
}
else if (shapeColor[i].equals("Pink")){
pen.setColor(color.PINK);
}
else if (shapeColor[i].equals("Yellow")){
pen.setColor(color.YELLOW);
}
else if (shapeColor[i].equals("Green")){
pen.setColor(color.GREEN);
}
else if (shapeColor[i].equals("Magenta")){
pen.setColor(color.MAGENTA);
}
else if (shapeColor[i].equals("Cyan")){
pen.setColor(color.CYAN);
}
else if (shapeColor[i].equals("Orange")){
pen.setColor(color.ORANGE);
}
else if (shapeColor[i].equals("Dark_gray")){
color = new Color(255,255,255);
pen.setColor(color.DARK_GRAY); //darkgrey
}
else if (shapeColor[i].equals("Light_grey")){
pen.setColor(color.LIGHT_GRAY); //lightgrey
}
else if (shapeColor[i].equals("Grey")){
pen.setColor(color.GRAY);
}
// pen.setColor(color.shapeColor);
}
public static void showSquare(DrawingPanel drawingPanel, int i, boolean booleanValue){ // Will show the filled i-th shape as a square with BLACK border
pen.fillRect(posX[i],posY[i],shapeSize[i],shapeSize[i]);
//setNoColor(drawingPanel);
if(booleanValue){
pen.setColor(color.BLACK);
pen.drawRect(posX[i],posY[i],shapeSize[i],shapeSize[i]);
setNoColor(drawingPanel);
}
}
public static void showCircle(DrawingPanel drawingPanel, int i, boolean booleanValue){ // Will show the filled i-th shape as a circle with BLACK border
pen.fillOval(posX[i],posY[i],shapeSize[i],shapeSize[i]);
if(booleanValue){
pen.setColor(color.BLACK);
pen.drawOval(posX[i],posY[i],shapeSize[i],shapeSize[i]);
}
}
public static void main(String [] args){ //Will show your specifics and obtain basic information for the execution
System.out.println("UTSA - Fall 2021 - CS1083 – Section 002 - Project 3 - written by RABIAT SADIQ \n");
System.out.println("Please input width, height of the panel, # of shapes, # of times to move followed by the shape, size, color, direction, and speed of every shape: ");
System.out.print("Input width of drawing panel:");
System.out.print("Input heigth of drawing panel:");
width = scnr.nextInt(); //init
height = scnr.nextInt();
System.out.print("Input number of shapes:");
numShapes = scnr.nextInt();
System.out.print("Input number of times shape would move:");
numTimeShapes = scnr.nextInt();
getShapeInformation();
drawingPanel = new DrawingPanel(width,height);
initialPosition(drawingPanel);
showShapesMoving(drawingPanel);
}
}
/*
testing numbers 600 800 10 50 Square 100 Red 0 3 Circle 80 Blue 2 2 Square 60 Green 4 1 Circle 50 Black
0 4 Square 80 Blue 6 5 Circle 25 Magenta 0 10 Square 60 Orange 2 4 Circle 80 Light_gray
4 6 Square 120 Yellow 6 2 Circle 60 Cyan 0 7
*/
ScreenSaver: little moving screen
import java.awt.*;
import java.util.*;
class ScreenSaver{
static DrawingPanel panel = new DrawingPanel(500,500);
static Color color = new Color(255,255,255);
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
String name = sc.next();
Graphics pen = panel.getGraphics();
panel.setBackground(color.BLACK);
// pen.setColor(color);
int iterator = 0; //decrease rgb
int red=255;
int green=255;
int blue=255;
for(int i=1;i<500;i++){
pen.setColor(color);
pen.drawString(name,450 -i,450-i);
panel.sleep(50);
pen.setColor(Color.BLACK);
pen.fillRect(0,0,500,500);
color = new Color(red,green,blue );
if (iterator == 0){
red=red-5;
iterator =1;
}
else if(iterator == 1)
{
green=green-5;
iterator=2;
}
else if (iterator == 2){
blue=blue-5;
iterator =0;
}
if (red ==0 && blue == 0 && green== 0){
red= 255;
green= 255;
blue = 255;
}
Task manager app: using android studio to create a task manager app,
mainly worked on journal portion, as well as debugging