Java Programming - 2019 Assignments
- Instructor
- Rob Borkowski
- Term
- Fourth Quarter 2020
Upcoming Assignments
No upcoming assignments.
Past Assignments
Due:
Using your LC email - Go to https://edu.sphero.com/ and Sign-in. Click logon with Google.
Skills Building - Program a Square
Create a Block Program to make the Sphero robot draw a square using the roll and delay blocks.
Test your code with the Sphero to make sure your code works.
Place a copy of the code you created to make the Sphero trace out a square (Not Using Loops) on to a Google Classroom Document and label it "No Loops".
I want to see the Java Script code - Not the Block Code.
Skills Building - Refactoring With Loops
Now let's refactor your code so that the Sphero code will draw a square using a loop.
Place your refactored code on your Google
Document and label it "With Loops"
Place a copy of the refactored code you created to make the Sphero trace out a square using loops on your Google Document and label it "With Loops". I want to see the Java Script code - Not the Block code
Follow along with the video if you aren't sure what to do.
https://youtu.be/6zoXyh5Qoz0
Follow along with the video if you aren't sure what to do.
https://youtu.be/ZfpPvnEsbto
Skills Building - Program a Square
Create a Block Program to make the Sphero robot draw a square using the roll and delay blocks.
Test your code with the Sphero to make sure your code works.
Place a copy of the code you created to make the Sphero trace out a square (Not Using Loops) on to a Google Classroom Document and label it "No Loops".
I want to see the Java Script code - Not the Block Code.
Skills Building - Refactoring With Loops
Now let's refactor your code so that the Sphero code will draw a square using a loop.
Place your refactored code on your Google
Document and label it "With Loops"
Place a copy of the refactored code you created to make the Sphero trace out a square using loops on your Google Document and label it "With Loops". I want to see the Java Script code - Not the Block code
Follow along with the video if you aren't sure what to do.
https://youtu.be/6zoXyh5Qoz0
Follow along with the video if you aren't sure what to do.
https://youtu.be/ZfpPvnEsbto
Due:
I made a mistake on the survey I sent you. On the question regarding this quarter's content, I had "Less Python more Java" as one option and "more Java less Python". Below is the re-phrased question. Please take a moment and answer, even if you answered the survey already.
Due:
Class - For today's assignment, please read my String Class notes. Mark this assignment as complete when finished.
Due:
Create a project called, StringCompare. Write a program that will compare three string pairs. Your program will determine if the two strings in the first pair are equal to each other, if the two strings in the second pair are equal to each other, and if the two strings in the third pair are equal to each other.
Below are your first three pairs to compare. You will need to copy these strings into your program.
Using the compareTo method, compare the pairs of strings. 20 Pts
Based on the output of the compareTo, programmatically produce the appropriate print statement. 20 Pts
For example, if the two strings in String Pair #1 are equal, your program will print "String Pair 1 is equal" or "S1 and S2 are equal". IF the values of the strings were changed, making them not equal, your program would automatically print that String Pair #1 is not equal or S1 and S2 are not equal. Note - Your program needs to determine which print statement to display.
String Pair #1
\/ I l
V l I
String Pair #2
0sw`
OSvv'
String Pair #3
fASG3PB$rO$uOmUCsi1icafkbWni06T*1O0Y*LiiB$Fy%v06mL
fASG3PB$r0d#WzxBFDAHkEtmQhT*vMhbV77%XVLUYz5r#mL
Below are your first three pairs to compare. You will need to copy these strings into your program.
Using the compareTo method, compare the pairs of strings. 20 Pts
Based on the output of the compareTo, programmatically produce the appropriate print statement. 20 Pts
For example, if the two strings in String Pair #1 are equal, your program will print "String Pair 1 is equal" or "S1 and S2 are equal". IF the values of the strings were changed, making them not equal, your program would automatically print that String Pair #1 is not equal or S1 and S2 are not equal. Note - Your program needs to determine which print statement to display.
String Pair #1
\/ I l
V l I
String Pair #2
0sw`
OSvv'
String Pair #3
fASG3PB$rO$uOmUCsi1icafkbWni06T*1O0Y*LiiB$Fy%v06mL
fASG3PB$r0d#WzxBFDAHkEtmQhT*vMhbV77%XVLUYz5r#mL
Due:
• Import and open the StringsEx project from section 4
• Examine ShoppingCart
Perform the following:
–Use the indexOf method to get the index for the space character (" ") within custName. Assign it to spaceIdx.
–Use the substring method and spaceIdx to get the first name portion of custName. Assign it to firstName and print firstName.
• Examine ShoppingCart
Perform the following:
–Use the indexOf method to get the index for the space character (" ") within custName. Assign it to spaceIdx.
–Use the substring method and spaceIdx to get the first name portion of custName. Assign it to firstName and print firstName.
Due:
Looking for max integers.
I wrote this program to prompt the user for three integers and then return the highest of the three integers. I'm getting an error, though, and have been unable to test it. Find the error and fix the program.
Test this program and let me know if the program works as described ( i.e. a program to prompt the user for three integers and then return the highest of the three integers).
Make any changes you need to get the program to run properly.
You can paste your corrected code or you can tell me what you did to fix my program. Be sure to test it thoroughly!
Create a program called MaxIntegers and paste this code:
import java.util.Scanner;
public class MaxIntegers {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println ("Please enter a number");
int num1 = in.nextInt();
System.out.println ("Please enter another number");
int num2 = in.nextInt();
System.out.println ("Please enter one more number");
int num3 = in.nextInt();
int max;
if (num1 > num2 && num1 > num3) {
max = num1;
}
if (num2 > num1 && num2 > num3) {
max = num2;
}
if (num3 > num1 && num3 > num2) {
max = num3;
}
System.out.println(" The max of 3 numbers is " + max);
}
}
I wrote this program to prompt the user for three integers and then return the highest of the three integers. I'm getting an error, though, and have been unable to test it. Find the error and fix the program.
Test this program and let me know if the program works as described ( i.e. a program to prompt the user for three integers and then return the highest of the three integers).
Make any changes you need to get the program to run properly.
You can paste your corrected code or you can tell me what you did to fix my program. Be sure to test it thoroughly!
Create a program called MaxIntegers and paste this code:
import java.util.Scanner;
public class MaxIntegers {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println ("Please enter a number");
int num1 = in.nextInt();
System.out.println ("Please enter another number");
int num2 = in.nextInt();
System.out.println ("Please enter one more number");
int num3 = in.nextInt();
int max;
if (num1 > num2 && num1 > num3) {
max = num1;
}
if (num2 > num1 && num2 > num3) {
max = num2;
}
if (num3 > num1 && num3 > num2) {
max = num3;
}
System.out.println(" The max of 3 numbers is " + max);
}
}
Due:
Create a new project called, ArrayListMenu.
Copy the code from your ArrayList Grade Entry lab and paste into this new project (adjust class name as necessary).
Modify the code so that it prompts the user to type 999 to record ten test grades, press 998 to print the current contents of the arraylist, 997 to see the average of the current array list, or 996 to quit.
After the user has selected one of the options (999, 998, 997, or 996), run that particular part pf the program and LOOP back to your menu (i.e. the question to press 999, 998, 997, or 996).
See me if you have questions
Copy the code from your ArrayList Grade Entry lab and paste into this new project (adjust class name as necessary).
Modify the code so that it prompts the user to type 999 to record ten test grades, press 998 to print the current contents of the arraylist, 997 to see the average of the current array list, or 996 to quit.
After the user has selected one of the options (999, 998, 997, or 996), run that particular part pf the program and LOOP back to your menu (i.e. the question to press 999, 998, 997, or 996).
See me if you have questions
Due:
Create a project called AListGrades
Prompt the user for 10 grades. 25pts
Using an Array List, store those values. 25pts
After 10 grades have been entered:
Return the 10 scores to the screen. 25pts
Return the average score to the screen. 25pts
Prompt the user for 10 grades. 25pts
Using an Array List, store those values. 25pts
After 10 grades have been entered:
Return the 10 scores to the screen. 25pts
Return the average score to the screen. 25pts
Due:
Write a MadLibs program prompting the user for a noun, adjective, verb, etc. and print the input back to the screen.
Here is some starter sentences for you:
Please excuse ProperNOUN who is far too ADJECTIVE to attend NOUN class
ProperNoun is authorized to be at APlace instead of Noun class.
ProperNoun is too cool for Noun class. Instead, Nickname will be attending the Event
Here is some starter sentences for you:
Please excuse ProperNOUN who is far too ADJECTIVE to attend NOUN class
ProperNoun is authorized to be at APlace instead of Noun class.
ProperNoun is too cool for Noun class. Instead, Nickname will be attending the Event
Due:
Create a new project called "ArrayBday"
Copy the code that I have attached and paste it into your main method. You will note that there are three arrays in this code. An array for month, for day, and for year.
Create a print statement that will utilize the three arrays to print the month, day, and year of your birthday.
Copy the code that I have attached and paste it into your main method. You will note that there are three arrays in this code. An array for month, for day, and for year.
Create a print statement that will utilize the three arrays to print the month, day, and year of your birthday.
Due:
Open Java Labs section 8 ArrayListEx1
Create an ArrayList called Subjects
Fill your ArrayList with your current LC courses
Print the contents of your ArrayList
Print the size of your ArrayList
Create an ArrayList called Subjects
Fill your ArrayList with your current LC courses
Print the contents of your ArrayList
Print the size of your ArrayList
Due:
Here is an array that someone showed me today. When they run this array, it is giving them the following error: "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: ".
We did not cover errors and exception handling, yet. However, I did discuss some of the rules around using an array and the limitations of an array. So I am curious if you can identify what, in the code below, could be generating the error message above.
To get a grade for this assignment, you need to submit an answer. It does not have to be a correct answer.
int [ ] even = new int [10];
even[0]= 2;
even[1]= 4;
even[2]= 6;
even[3]= 8;
even[4]= 10;
even[5]= 12;
even[6]= 14;
even[7]= 16;
even[8]= 18;
even[9]= 20;
even[10]= 22;
System.out.println("The value is " + even[6]);
even[6]= 72;
System.out.println("The value is now " + even[6]);
System.out.println("Array length: "+ even.length);
We did not cover errors and exception handling, yet. However, I did discuss some of the rules around using an array and the limitations of an array. So I am curious if you can identify what, in the code below, could be generating the error message above.
To get a grade for this assignment, you need to submit an answer. It does not have to be a correct answer.
int [ ] even = new int [10];
even[0]= 2;
even[1]= 4;
even[2]= 6;
even[3]= 8;
even[4]= 10;
even[5]= 12;
even[6]= 14;
even[7]= 16;
even[8]= 18;
even[9]= 20;
even[10]= 22;
System.out.println("The value is " + even[6]);
even[6]= 72;
System.out.println("The value is now " + even[6]);
System.out.println("Array length: "+ even.length);
Due:
Create a new project called, ArrayElements.
Below is an initialized array. Copy and paste this array into your project.
You were given a random number during class, that is your index. Find your corresponding number and print it.
Print the length of this array.
int [ ] idNum = {13, 14, 44, 6, 73, 65, 47, 25, 79, 23, 30, 64, 95, 83, 61, 99, 78, 42, 16, 70, 48, 22, 81, 20, 63, 33, 2, 96, 41, 53, 87, 17, 58, 26, 36, 85, 71, 43, 51, 59, 57, 1, 5, 32, 24, 62, 82, 67, 34, 91, 46, 12, 40, 93, 97, 4, 90, 27, 15, 66, 86, 76, 31, 50, 8, 54, 29, 80, 74, 39, 72, 21, 45, 55, 9, 28, 94, 89, 11, 92, 37, 52, 18, 88, 49, 60, 77, 98, 69, 3, 84, 10, 56, 35, 19, 38, 68, 75, 7,11,23};
Below is an initialized array. Copy and paste this array into your project.
You were given a random number during class, that is your index. Find your corresponding number and print it.
Print the length of this array.
int [ ] idNum = {13, 14, 44, 6, 73, 65, 47, 25, 79, 23, 30, 64, 95, 83, 61, 99, 78, 42, 16, 70, 48, 22, 81, 20, 63, 33, 2, 96, 41, 53, 87, 17, 58, 26, 36, 85, 71, 43, 51, 59, 57, 1, 5, 32, 24, 62, 82, 67, 34, 91, 46, 12, 40, 93, 97, 4, 90, 27, 15, 66, 86, 76, 31, 50, 8, 54, 29, 80, 74, 39, 72, 21, 45, 55, 9, 28, 94, 89, 11, 92, 37, 52, 18, 88, 49, 60, 77, 98, 69, 3, 84, 10, 56, 35, 19, 38, 68, 75, 7,11,23};
Due:
Continue editing the PrisonTest project for section 7_5 (PrisonTest_Student_7_5)
Modify the Cell class so that …
– Getters exist for the Name and isOpen fields. 10pts
– There’s a private 4-digit security code field. It’s initialized from the constructor and has no Getter method. 10 pts
–There’s a setter for opening/closing the door, and it does the following:
• Accepts a security code as an argument. 20pts
• Prints if the code is incorrect. 5 pts
• If the code is correct and the door is closed, opens it, if the code is correct and the door is open, closes it. 10 pts
• Prints if the door is opened or closed.
Modify the Prisoner class so that …
– The display()method prints the cell name. 10 pts
– The openDoor()method is removed. 5pts
Modify the main method so that …
– The Cell is instantiated properly (meaning...the constructor includes the security key variable) 10 pts
– The prisoner no longer tries to open the cell door (meaning... you are not running the method as the prisoner class object). 10 pts
– It tests a cell class’s ability to open and close its door (meaning... run a method as the cell class object and pass through an integer variable for the security code) 10 pts
Try supplying both correct and incorrect security codes in the Main Method. Observe the error.
Upload all three classes.
Modify the Cell class so that …
– Getters exist for the Name and isOpen fields. 10pts
– There’s a private 4-digit security code field. It’s initialized from the constructor and has no Getter method. 10 pts
–There’s a setter for opening/closing the door, and it does the following:
• Accepts a security code as an argument. 20pts
• Prints if the code is incorrect. 5 pts
• If the code is correct and the door is closed, opens it, if the code is correct and the door is open, closes it. 10 pts
• Prints if the door is opened or closed.
Modify the Prisoner class so that …
– The display()method prints the cell name. 10 pts
– The openDoor()method is removed. 5pts
Modify the main method so that …
– The Cell is instantiated properly (meaning...the constructor includes the security key variable) 10 pts
– The prisoner no longer tries to open the cell door (meaning... you are not running the method as the prisoner class object). 10 pts
– It tests a cell class’s ability to open and close its door (meaning... run a method as the cell class object and pass through an integer variable for the security code) 10 pts
Try supplying both correct and incorrect security codes in the Main Method. Observe the error.
Upload all three classes.
Due:
Please submit your work for the lab we worked on last week. I'll give you the some time in class today to finish it and ask any questions you might have.
The lab assignment:
In your SmartHome Project...
Create/Modify the setDoors method to allow the user to change the number of doors on a garage object.
Do not let the user set the number of doors greater than 5.
IF the number is greater than 5, display a message instructing the user to enter something less than 5.
IF the number is less than 5, change the number of doors and display a message that the number of doors has been set to x
You can submit just the garage class.
The lab assignment:
In your SmartHome Project...
Create/Modify the setDoors method to allow the user to change the number of doors on a garage object.
Do not let the user set the number of doors greater than 5.
IF the number is greater than 5, display a message instructing the user to enter something less than 5.
IF the number is less than 5, change the number of doors and display a message that the number of doors has been set to x
You can submit just the garage class.
Due:
Within your StudentTest project, modify your Student class to keep track (or count) how many times a student object is created. Hold this value in a static variable, within the Student class. Call this variable, studentCount.
Create a non-static integer variable in your student class called, studentNumber. This field is initialized with the current value of the studentCount variable.
Include these two fields in the StudentInfo method.
**Challenge**
The studentNumber is going to be unique for each student object. Can you make that student number so that it is prefaced with the year you are going to graduate (i.e. 20200001, 20200002, etc. or if you are a junior, 20210001, 20210002).
This challenge is optional.
Create a non-static integer variable in your student class called, studentNumber. This field is initialized with the current value of the studentCount variable.
Include these two fields in the StudentInfo method.
**Challenge**
The studentNumber is going to be unique for each student object. Can you make that student number so that it is prefaced with the year you are going to graduate (i.e. 20200001, 20200002, etc. or if you are a junior, 20210001, 20210002).
This challenge is optional.
Due:
See attached. Follow the instructions carefully. Complete parts 1 & 2. Test your code. Submit both parts in one Google Doc.
Please be sure to include all three classes.
Please be sure to include all three classes.
Due:
In your Checking class....
create a Withdraw method to subtract from the user's checking balance.
configure your Withdraw method to first verify the user has enough in their account to accommodate the withdraw. If they do not have enough - display a message that they do not have enough AND do not let the transaction occur.
create or modify your Deposit method to increase the user's interest rate if the deposit is greater than $500.00
Display a friendly message thanking the user for such a large deposit.
Please include all of your code from the Checking class and your code from the AccountTest class. I want to see how you instantiate your Checking objects and run your methods.
create a Withdraw method to subtract from the user's checking balance.
configure your Withdraw method to first verify the user has enough in their account to accommodate the withdraw. If they do not have enough - display a message that they do not have enough AND do not let the transaction occur.
create or modify your Deposit method to increase the user's interest rate if the deposit is greater than $500.00
Display a friendly message thanking the user for such a large deposit.
Please include all of your code from the Checking class and your code from the AccountTest class. I want to see how you instantiate your Checking objects and run your methods.
Due:
In the Savings class
create three fields, name, balance, and interest.
create a method to print the customer's info (above)
create a second method called Withdraw that will subtract from the customer's balance
create third method called Deposit that will add to the customer's balance
Instantiate your Savings object in the AccountTest and run your two methods
Please submit both AccountTest and Savings class code
create three fields, name, balance, and interest.
create a method to print the customer's info (above)
create a second method called Withdraw that will subtract from the customer's balance
create third method called Deposit that will add to the customer's balance
Instantiate your Savings object in the AccountTest and run your two methods
Please submit both AccountTest and Savings class code
Due:
Please read the attached documents on Software Development Process and Java History. You do not have to do the exercises. Read both documents and then answer the question below.
You may complete this assignment at home.
This is a graded assignment, so be sure to answer the question on this form when you are finished reading the material.
You may complete this assignment at home.
This is a graded assignment, so be sure to answer the question on this form when you are finished reading the material.
Due:
Create a new project called BreakContinueLoop 30 pts
Write a program that generates and displays 100 random integers and then displays their sum. 10 pts.
The random integers should be between 1 and 5. This includes the number 1 through the number 5. * Hint: you will need the plus 1 trick we discussed. 10 pts.
You must use a loop to generate the one hundred integers. While or For, your choice. 10 pts.
Skip all odd numbers - do not add them to the sum. When displaying the sum, you might say "The sum of the even numbers is...". 10 pts.
If the random number generated is the number 3 stop the program immediately and display the sum. 10 pts.
20 pts
*** YOUR PROGRAM MUST USE BOTH A BREAK AND A CONTINUE STATEMENT ***
Write a program that generates and displays 100 random integers and then displays their sum. 10 pts.
The random integers should be between 1 and 5. This includes the number 1 through the number 5. * Hint: you will need the plus 1 trick we discussed. 10 pts.
You must use a loop to generate the one hundred integers. While or For, your choice. 10 pts.
Skip all odd numbers - do not add them to the sum. When displaying the sum, you might say "The sum of the even numbers is...". 10 pts.
If the random number generated is the number 3 stop the program immediately and display the sum. 10 pts.
20 pts
*** YOUR PROGRAM MUST USE BOTH A BREAK AND A CONTINUE STATEMENT ***
Due:
Part 1
Tweak the RandomIntro program to keep running until I guess the correct number.
If I guess incorrectly, print "Wrong! Try again" and allow me to enter a new number. Keep this going until I guess it correctly.
When I guess it correctly, print "You Got it!"
You will need to use a while loop for this.
** I would also suggest that you cap the random number to something under 100. You can do this by specifying your number within the parenthesis. Read my Random Class Notes 2019 for details on how to do this.
Part 2
Once you get this working.....
Tweak your program again to give me some clues.
If my guess is too low, print "Wrong! Too Low...try again"
If my guess is too high, print "Wrong! Too High...try again"
The code from today's class, RandomIntro, is located in my earlier post entitled "Random Class Notes 2019". Take a few minutes to read those notes. Be sure to check out my Class Notes on Loops 2019 post, too, it's riveting!
Tweak the RandomIntro program to keep running until I guess the correct number.
If I guess incorrectly, print "Wrong! Try again" and allow me to enter a new number. Keep this going until I guess it correctly.
When I guess it correctly, print "You Got it!"
You will need to use a while loop for this.
** I would also suggest that you cap the random number to something under 100. You can do this by specifying your number within the parenthesis. Read my Random Class Notes 2019 for details on how to do this.
Part 2
Once you get this working.....
Tweak your program again to give me some clues.
If my guess is too low, print "Wrong! Too Low...try again"
If my guess is too high, print "Wrong! Too High...try again"
The code from today's class, RandomIntro, is located in my earlier post entitled "Random Class Notes 2019". Take a few minutes to read those notes. Be sure to check out my Class Notes on Loops 2019 post, too, it's riveting!
Due:
Import and open the WhileLoopEx project.
•Examine the SumofNums program - it sums up a sequence of 10 integers that are input by the user.
•Modify the program to do the same by using a do-while loop.
•Examine the SumofNums program - it sums up a sequence of 10 integers that are input by the user.
•Modify the program to do the same by using a do-while loop.
Due:
Switch Assignment Part 2: Complete the following and then click "Completed" on this form. Be sure to do the work BEFORE you answer "Complete".
Part 1
• Import and open the SwitchExproject.
• Observe SwitchEx2 and execute the program.
• Observe the output.
Part2
•Modify the switchstatement as follows:
•Remove the breakstatements for case ‘A.’
–Execute the program.
–Observe the output.
•Remove the breakstatements for case ‘A’ and case ‘B.’
–Execute the program.
–Observe the output.
• Import and open the SwitchExproject.
• Observe SwitchEx2 and execute the program.
• Observe the output.
Part2
•Modify the switchstatement as follows:
•Remove the breakstatements for case ‘A.’
–Execute the program.
–Observe the output.
•Remove the breakstatements for case ‘A’ and case ‘B.’
–Execute the program.
–Observe the output.
Due:
• Import and open the SwitchExproject.
• Modify SwitchEx1 to implement the following with the switch statement.
– The user enters the month as a number.
– The corresponding month name must be displayed.
– For any invalid month, the output must be displayed as “Invalid month”
• Modify SwitchEx1 to implement the following with the switch statement.
– The user enters the month as a number.
– The corresponding month name must be displayed.
– For any invalid month, the output must be displayed as “Invalid month”
Due:
Write a program that will prompt the user for the temperature outside and then output to the screen a forecast of snow or rain. It snows anywhere at or below 32 degrees.
Submit your code.
Submit your code.
Due:
• Import and open the IfElseExproject.
• Examine ShoppingCart.java.
• Use an if/else statement to implement the following:
– Declare and initialize a boolean variable, outOfStock.
– If quantity > 1, change the message variable to indicate plural.
– If an item is out of stock, inform the user that the item is unavailable. Else print the message and the total cost.
• Examine ShoppingCart.java.
• Use an if/else statement to implement the following:
– Declare and initialize a boolean variable, outOfStock.
– If quantity > 1, change the message variable to indicate plural.
– If an item is out of stock, inform the user that the item is unavailable. Else print the message and the total cost.
Due:
The normal behavior for a stop light is to cycle from Red to Green to Yellow to Red ( and continues with this pattern). Write a java program, StopLight.Java, which will determine the next color of a stop light in this pattern, Red to Green to Yellow to Red based on the current stop light provided by the user.
Task
Implement the following using a suitable if decision statement.
1) Have the user enter the value for the currentColor.
2) Compute the next color stop light based on the currentColor.
3) Alert the user for any invalid value of color.
Task
Implement the following using a suitable if decision statement.
1) Have the user enter the value for the currentColor.
2) Compute the next color stop light based on the currentColor.
3) Alert the user for any invalid value of color.
Due:
- Write a program to prompt the user for a number between 1 and 10.
- Determine if the number the user entered is odd or even.
- If the number is odd print "You Entered an Odd Number".
- Otherwise, print " That was an Even Number".
- Test your program by entering an even number and confirm you got the correct message.
- Test your program again by entering an odd number and confirm that you got the correct message.
Please check your work before submitting your code.
- Determine if the number the user entered is odd or even.
- If the number is odd print "You Entered an Odd Number".
- Otherwise, print " That was an Even Number".
- Test your program by entering an even number and confirm you got the correct message.
- Test your program again by entering an odd number and confirm that you got the correct message.
Please check your work before submitting your code.
Due:
This lab is identical to the boolean lab we did together in class to determine if the user is old enough to vote. We also reviewed this together. Please take your time and read the requirements carefully. To help, I added a value for each requirement.
Import and open the IfElseEx project in your Java Labs folder.
Modify AgeValidity.java to implement the following:
- Prompt the user to enter their age. //Worth 20 points
-Declare a boolean variable, drivingUnderAge. //Worth 20 points
-Initialize drivingUnderAge to false. //Worth 20 points
-Write a boolean expression to check if the age entered by the user is less than or equal to 16, and then set drivingUnderAge to true. //Worth 20 points
-Print the value of drivingUnderAge. //Worth 20 points. Add some text to this print statement to have it make sense...don't just print "true" or "false". For example: "Driving under age? True".
Import and open the IfElseEx project in your Java Labs folder.
Modify AgeValidity.java to implement the following:
- Prompt the user to enter their age. //Worth 20 points
-Declare a boolean variable, drivingUnderAge. //Worth 20 points
-Initialize drivingUnderAge to false. //Worth 20 points
-Write a boolean expression to check if the age entered by the user is less than or equal to 16, and then set drivingUnderAge to true. //Worth 20 points
-Print the value of drivingUnderAge. //Worth 20 points. Add some text to this print statement to have it make sense...don't just print "true" or "false". For example: "Driving under age? True".
Due:
Paste your Calculator class and Calculation class into a Google doc and upload it.
Make sure your Calculation class has the work we did on Friday:
/*Tweak the findtotal() method to require a String value (the person's name), in addition to the menu price.
Modify the System.out.print statement to include the person's name.
launch the method two more times (three in total) in the main method
*/
Make sure your Calculation class has the work we did on Friday:
/*Tweak the findtotal() method to require a String value (the person's name), in addition to the menu price.
Modify the System.out.print statement to include the person's name.
launch the method two more times (three in total) in the main method
*/
Due:
1) Create a new project called AssignmentOperators
2) Declare and initialize two integer variables, x = 20 and y = 6
3) Use the += operator to add X and Y then assign that new value to x. Write a System.out.println statement to show the new value of X.
4) Use the -= operator to subtract Y from X then assign that new value to x. Write a System.out.println statement to show the new value of X.
5) Use the *= operator to multiply X and Y then assign that new value to x. Write a System.out.println statement to show the new value of X.
6) Use the /= operator to divide X by Y then assign that new value to x. Write a System.out.println statement to show the new value of X.
7) Use the %= operator to get the remainder of X divided by Y then assign that new value to x. Write a System.out.println statement to show the new value of X.
2) Declare and initialize two integer variables, x = 20 and y = 6
3) Use the += operator to add X and Y then assign that new value to x. Write a System.out.println statement to show the new value of X.
4) Use the -= operator to subtract Y from X then assign that new value to x. Write a System.out.println statement to show the new value of X.
5) Use the *= operator to multiply X and Y then assign that new value to x. Write a System.out.println statement to show the new value of X.
6) Use the /= operator to divide X by Y then assign that new value to x. Write a System.out.println statement to show the new value of X.
7) Use the %= operator to get the remainder of X divided by Y then assign that new value to x. Write a System.out.println statement to show the new value of X.
Due:
Declare and initialize 3 Strings with the following data
shirtPrice = "15"
taxRate = "0.06"
gibberish = "887ds7nds87dsfs"
Parse and multiply shirtPrice * taxRate to find the tax
- Print this value
Try to parse gibbersh as an Int
- did you get an error? Comment-out this line after you observed the error.
shirtPrice = "15"
taxRate = "0.06"
gibberish = "887ds7nds87dsfs"
Parse and multiply shirtPrice * taxRate to find the tax
- Print this value
Try to parse gibbersh as an Int
- did you get an error? Comment-out this line after you observed the error.
Due:
Create a new project called - Input01
Prompt the user for three integers
Print the sum of the three integers to the screen
Prompt the user for three integers
Print the sum of the three integers to the screen
Due:
Create a new project called, GPA
Write a program that prompts the user for the following:
First Name
Last Name
Grade (year) - int
GPA - double
Use the Scanner to collect this data and read it back.
Example:
Good morning, Tom. Your graduation year is 2018. Your GPA is 3.8
**Be sure to use the correct data types....Grade and GPA should NOT be Strings**
Write a program that prompts the user for the following:
First Name
Last Name
Grade (year) - int
GPA - double
Use the Scanner to collect this data and read it back.
Example:
Good morning, Tom. Your graduation year is 2018. Your GPA is 3.8
**Be sure to use the correct data types....Grade and GPA should NOT be Strings**
Due:
Create new project called Division
Write a program that takes X hours and displays it in terms of days and hours
X = 103
(two println statements is fine. If you can do it with one println statement, great)
** use your knowledge of Java division and modulus
Write a program that takes X hours and displays it in terms of days and hours
X = 103
(two println statements is fine. If you can do it with one println statement, great)
** use your knowledge of Java division and modulus
Due:
In your response, type the number of the question and your answer.
1) What is the value of sum?
int sum;
int num1 = 15; int num2 = 20;
sum = num1 + num2;
2) What is the final value of prod?
int prod;
int num1 = 5; int num2 = 2;
prod = num1 * num2;
3) What is the final value of diff?
int diff;
int num1 = 50; int num2 = 20;
diff = num1 – num2;
4) What is the final value of quot?
int quot;
int num1 = 31; int num2 = 6;
quot = num1 / num2;
5) What is the final value of dblVar2?
double dblVar2 = 2.5;
dblVar2 = 2*dblVar2;
6) True or False - intVar1 is a valid variable name?
7) True or False - 24hrs is a valid variable name?
8) True or False - Tampa Bay is a valid variable name?
9) True or False - Gucci is a valid variable name?
10) True or False - number17 is a valid variable name?
1) What is the value of sum?
int sum;
int num1 = 15; int num2 = 20;
sum = num1 + num2;
2) What is the final value of prod?
int prod;
int num1 = 5; int num2 = 2;
prod = num1 * num2;
3) What is the final value of diff?
int diff;
int num1 = 50; int num2 = 20;
diff = num1 – num2;
4) What is the final value of quot?
int quot;
int num1 = 31; int num2 = 6;
quot = num1 / num2;
5) What is the final value of dblVar2?
double dblVar2 = 2.5;
dblVar2 = 2*dblVar2;
6) True or False - intVar1 is a valid variable name?
7) True or False - 24hrs is a valid variable name?
8) True or False - Tampa Bay is a valid variable name?
9) True or False - Gucci is a valid variable name?
10) True or False - number17 is a valid variable name?
Due:
Part 1 - - Paste your code for the ShoppingCart lab we did together in class
Part 2 -
Create new project called StudentInfo
declare and initialize the following
firstName
lastName
(make it a decimal) gpa
gradYear
Have your program print to the screen: First Name Last Name "has a" GPA "GPA "and will graduate in" gradYear
example: Jane Smith has a 3.6 GPA and will graduate in 2020.
Part 2 -
Create new project called StudentInfo
declare and initialize the following
firstName
lastName
(make it a decimal) gpa
gradYear
Have your program print to the screen: First Name Last Name "has a" GPA "GPA "and will graduate in" gradYear
example: Jane Smith has a 3.6 GPA and will graduate in 2020.
Due:
Start a new Project called IncrementOperators
With int VarB = 21;
Write a system.out.println statement (one println statement) that produces the following output
20, 19, 19, 18
With int VarB = 21;
Write a system.out.println statement (one println statement) that produces the following output
20, 19, 19, 18
Due:
Part 1)
Yesterday we learned about the System.out.println and the System.out.print commands in Java. Write a program that uses both of these commands to output a stick-picture to the screen. Be creative. The silly face I showed as an example does not count!
Be sure to use both System.out.println and System.out.print
Part 2)
In your HelloWorld program...
use the // to comment-out one of your lines of code
use the /* */ comment to write two comment lines
Example:
This is an
example of two comment lines..
Copy your source code, paste it into a Google Doc, and turn it in for this assignment.
Yesterday we learned about the System.out.println and the System.out.print commands in Java. Write a program that uses both of these commands to output a stick-picture to the screen. Be creative. The silly face I showed as an example does not count!
Be sure to use both System.out.println and System.out.print
Part 2)
In your HelloWorld program...
use the // to comment-out one of your lines of code
use the /* */ comment to write two comment lines
Example:
This is an
example of two comment lines..
Copy your source code, paste it into a Google Doc, and turn it in for this assignment.
Due:
Create a Java class called "Months". Copy the code below and paste it into your class.
The output for the code should look like this:
January
Febuary
march
April
May
Please fix my code and submit it.
Here is my code:
public static void main(String[] args) {
System.out.print("January");
{
System.out.println("Febuary")
}
System.out.println("march");
}
System.out.println ("April");
System.out.print ("May");
}
}
The output for the code should look like this:
January
Febuary
march
April
May
Please fix my code and submit it.
Here is my code:
public static void main(String[] args) {
System.out.print("January");
{
System.out.println("Febuary")
}
System.out.println("march");
}
System.out.println ("April");
System.out.print ("May");
}
}