JMU Pseudocode to Java Programming Code

1REPEAT

2 PROMPT nonRecyclableAmount

3 READ nonRecyclableAmount

4 IF nonRecyclableAmount < 0 ) THEN

5 PRINT “ERROR MESSAGE”

6 END IF

7UNTIL (nonRecyclableAmount > 0)

8REPEAT

9 PROMPT recyclableAmount

10 READ recyclableAmount

11 IF recyclableAmount < 0 ) THEN

12 PRINT “ERROR MESSAGE”

13 END IF

14UNTIL (recyclableAmount < 0 )

15

16DO 1 TO 4

17 PROMPT classStanding

18 READ classStanding

19 SET noOfStudentsEnrolled = -1

20 REPEAT

21 PROMPT noOfStudentsEnrolled

22 READ noOfStudentsEnrolled

23 IF noOfStudentsEnrolled < 0 THEN

24 PRINT “ERROR MESSAGE”

25 END IF

26 UNTIL (noOfStudentsRolled > 0 )

27

28 SET classNonRecyclableAmount = nonRecyclableAmount * noOfStudentsEnrolled

29 SET classRecyclableAmount = recyclableAmount * noOfStudentsEnrolled

30

31 SET totalNoOfSTudents += noOfStudentsEnrolled

32 PRINT classSummary

33END DO

34SET averageNonRecyclableAmount = totalNonRecyclableAmount / 4

35SET averageRecyclableAmount = totalRecyclableAmount / 4

have to convert this to java file. i already did the pseudo. ill provide the full prompt if you cant read it. my teacher gave me 100% with the pseudo, i just cant figure out the code to work

Programming Assignment ¾
Scenario:
The Office of Sustainability at Mason has recently started an ecological study to determine the impact of
the trash generated, by its students, on the surrounding wildlife. You have been hired by the Office of
Sustainability to calculate the amount of trash (recycling and non-recyclable materials) generated by
each class standing (freshman, sophomore, junior, and senior).
Your goal is to create an application that allows a user (a GMU employee) to initially set the average
individual’s yearly non-recyclable and recyclable material amount. The application should only accept
positive values for both the non-recyclable and recyclable material amounts. If the user provides a
negative value, the application should re-prompt the user until the given value is valid. If the given value
is invalid, provide an error message for the user. Once, the valid individuals average yearly nonrecyclable material and recyclable amounts are entered, the application should allow you to enter one
class standing information at a time. Each class standing information is composed of the class standing
name (freshman, sophomore, junior, and senior) and the number of students enrolled. The number of
students must also be a positive number. The application should re-prompt the user until the given
value is valid. If the given value is invalid, provide an error message for the user.
Material Type
Non-Recyclable Material
Recyclable Material
Average Amount of Waste Per Person in LBS (2020)
525.44
1116.56
After each class standing, the application must print a well-formatted message that contains the class
standing, the total number of students for that class, and the number of total amount of waste
generated (non-recyclable and recyclable material). Upon completion of entering all the class standing
data, the application will print a well-formatted report that includes the total number of students across
all class standing, and an average of the Non-recyclable and recyclable materials generated across all
class standing.
Other Requirements:




You may not ask the user how many class standings they will enter
Your solution must not use arrays.
Remember to think about what constitutes valid input. Your solution must address this.
Your solution may not use any functions or language constructs not covered during this
semester’s IT 106 without prior authorization from your instructor, even if you know other
functions or language constructs. We want everyone to be on the same “playing field”,
regardless of previous programming exposure, and get practice with algorithmic design to solve
problems (the intent of the course). Using something existing not discussed in class does not
give you as much practice as solving the problem yourself. Doing this may lead to a substantial
grade penalty, a grade of zero, or an Honor Code inquiry. When in doubt, ask!
Hints:



There are a number of validations that must occur. Think about what type of validation might be
appropriate and make sure these are all handled. Don’t forget about what you learned about
data validation. When invalid data is entered, the user must be provided with an error message
and then re-prompted for the data.
Remember to parse String data using constructs like Integer.parseInt() and
Double.parseDouble() where necessary. Additionally, when using these constructs, don’t forget
to include try/catch for good validation.
Your solution will require use of a loop structure.
To Do (Check blackboard for Due Dates):
Programming Assignment 1: Solution Design
1) Create a defining diagram that shows the input, processing, and output
2) Create a solution algorithm using pseudocode
3) Show testing using the desk checking table method, to include test data, expected results, and a
desk checking table. Make sure your desk checking considers multiple cases including both valid
and invalid test data to prove your algorithm will work in all cases
Upload a Word document containing only items about to Blackboard
Grading Criteria
Requirement
Points
Defining Diagram with input, processing, and output
40
Efficient Solution Algorithm
40
Through Desk Checking Table including test data, and expected results
20
Programming Assignment 2: Solution Implementation
Write a well-documented, efficient Java program that implements the algorithm you identified. Include
appropriate documentation as identified in the documentation expectations document.
Note: You must use the JOptionPane class for input/output. Additionally, if you System.exit as shown in
the textbook, it may only be used as the absolute last line in the program. You may not use System.exit,
or any variant that exits the program in the middle of the program. The program should be designed to
only exit once the algorithm has finished.
Upload the .java file of the final program to Blackboard. Be careful that you do not submit a .class file
instead of a .java file.
Your program must successfully compile using jGrasp. Partial credit is available. Any final program that
does not compile, for any reason, will receive an automatic zero. Other IDEs often place in additional
code that you are unaware of, doing too much of the work for you. You are strongly discouraged from
using IDEs other than jGrasp.
Grading Criteria
Requirement
Implementation of Java Program, using efficient practices where appropriate, such as the use
of constants, good variable names, no redundant code, etc.
Appropriate objective-style documentation
Appropriate intermediate comments
Points
70
10
20
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Midpoint Review
In This Lecture
• Midpoint Review
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Questions?
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Using Constants and Variables
• Variable: named memory location
• Contents may change at run-time
• Contents described by data type
• Constant: value stays fixed after compilation
• Constants may be assigned a symbolic name
– Example: final int MAXIMUM_GRADE = 100;
• Constant’s literal value may be used directly
– Example: 100 may be hard-coded into program
• Don’t do this!
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Using Constants and Variables (Cont’d)
• Data type: specifies data in three ways
• Kind of item being represented
• Amount of memory item occupies
• Operations that may be performed on item
• Eight primitive (basic) data types:
• byte, short, int, long, float, double, char, boolean
• Reference types (classes) are built upon
primitives
• String
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Displaying Variables
• Variables can be output in two ways
• To the console (System.out.println)
– Example: System.out.println(“My grade: ” +
gradeEarned);
• Through a GUI
(JOptionPane.showMessageDialog)
– Example: JOptionPane.showMessageDialog(null, “My
grade: ” + gradeEarned);
• Concatenation: Joins arguments with the (+)
operator
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Initializing and Declaring Variables
• When initializing a variable, you must specify
the data type, and a name for the variable
• Examples:
– int x = 1;
– double d = 1.4;
• An initial value is optional, but must be set
before calculations occur
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Constants
Final datatype CONSTANT_NAME = VALUE;
final double PI = 3.14159;
final int NUM_STUDENTS = 30;
• By convention, constants use names that
contain all capital letters. Words are separated
by underscores
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Floating-Point Types
• Floating-point numbers contain decimal
positions
• float – holds values up to 7 significant digits
• double – holds values up to 15 significant digits
• Significant digits indicate mathematical accuracy
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Floating-Point Types
• Calculations involving floating-point numbers
are approximated, due to accuracy issues.
• Examples:
– JOptionPane.showMessageDialog(null, 1.0 – 0.1 – 0.1 – 0.1 0.1);
• Displays 0.6000000000000001
– JOptionPane.showMessageDialog(null, 1.0 – 0.9);
• Displays: 0.09999999999999998
• Calculations involving integers are stored
precisely
• Calculations yield a precise integer result
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Numeric Type Conversion
• Unifying type: highest type among mixed
operands
• Hierarchy: double, float, long, int, short, byte
• Java converts nonconforming operands to highest
type
• Example:
int hoursWorked = 37
double payRate = 6.73;
double grossPay = hoursWorked * payRate;
hoursWorked temporarily promoted to double type to perform
calculation
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Explicit Typecasting
• Place result type request in () before variable
to be cast
• Example:
double money = 32.11
int dollars = (int) money;
• Expression on right is converted to int
• Data is truncated (possible loss of value)
• Java compiler would not do this without the cast
(no demotions)
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Integer Division
• 5 / 2 yields an integer: 2
• 5.0 / 2 yields a double value 2.5
• 5 % 2 yields 1 (the remainder of the division)
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Remainder Operator
• Examples:
• An even number % 2 is always 0
• An odd number % 2 is always 1
• Suppose today is Saturday. You are your friends are
going to meet in 10 days. What day is in 10 days?
Saturday is the 6th day in a week
A week has 7 days
(6 + 10) % 7 is 2
The 2nd day in a week is Tuesday
After 10 days
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Escape Sequence
• Strings store character sequences
• Escape sequence: backslash and character as
one unit
• Example: char aNewLine = ‘\n’;
• Newline character moves cursor to the next line
• Use of escape sequences
• Example: JOptionPane.showMessageDialog(null,
“Hello\nthere”);
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Escape Sequences (Cont’d)
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Using Input Dialog Boxes
• showInputDialog() used to create input dialog
boxes
• Simplest version takes prompt, returns String
• result = JOptionPane.showInputDialog(“prompt”);
• Note: You must DO something with the String
result
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Example: Using Input Dialog Boxes
Notice that there is a result from
the input – so the method call is part of
an expression
No result from the output – so the
method call is a statement
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Converting Input Dialog to Other Data Types
• showInputDialog returns a String
• Must be converted if the input is a different
data type
• Integer.parseInt
• Double.parseDouble
• Examples:
• age = Integer.parseInt(JOptionPane.showInputDialog(“age?”));
• wage = Double.parseDouble(JOptionPane.showInputDialog(“wage?”));
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Converting Input Dialog to Other Data Types
(Cont’d)
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Operators
• Arithmetic – defined for numeric types (+, -, *, /,
%)
• (% is only for int!)
• Concatenation – defined for String (+(
• Relational – defined for primitive types (>, =,
3)
• &&
and
(4 < 3) && (1 < 2) • || or (4 < 3) || (1< 2) IT 106: Introduction to IT Problem Solving Using Computer Programming Operator Precedence var++, var-+, - (Unary plus and minus), ++var,--var (type) Casting ! (Not) *, /, % (Multiplication, division, and remainder) +, - (Binary addition and subtraction) = (Comparison) ==, !=; (Equality) & (Unconditional AND) ^ (Exclusive OR) | (Unconditional OR) && (Conditional AND) Short-circuit AND || (Conditional OR) Short-circuit OR =, +=, -=, *=, /=, %= (Assignment operator IT 106: Introduction to IT Problem Solving Using Computer Programming Boolean Data Type • boolean type: holds one of two values: true or false • Example statements • boolean isItPayday = false; • boolean areYouBroke = true; • Six binary comparison operators • (= =), (>), ( =), (< =) • Results of operations: boolean true or false • Perform comparisons, assign results to boolean type • boolean isSixBigger = (6 > 5);
• boolean isOTPay = (hours > 40);
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Relational Operators
• Evaluates to a boolean
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Selection Statements
• Pseudocode
• IF….THEN….ENDIF
• IF….THEN….ELSE IF….THEN….ENDIF
• CASEOF …. ENDCASE
• Java
• if/else if/else
• switch
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Simple if Statements
if (booleanExpression)
{
statement(s);
}
if (radius >= 0)
{ area = radius * radius * PI;
JOptionPane.showMessageDialog(null, “The
area for the circle of radius ” + radius + ” is ”
+ area);
}
IT 106: Introduction to IT Problem
Solving Using Computer Programming
if Statement Caution
• Common Logic Error
if (radius >= 0);
{
area = radius*radius*PI;
JOptionPane.showMessageDialog(null,
“The area for the circle of radius ” + radius + ”
is ” + area);
}
Wrong
IT 106: Introduction to IT Problem
Solving Using Computer Programming
if…else Statements
if (booleanExpression) {
statement(s)-for-the-true-case;
}
else {
statement(s)-for-the-false-case;
}
true
Statement(s) for the true case
Boolean
Expression
false
Statement(s) for the false case
IT 106: Introduction to IT Problem
Solving Using Computer Programming
if…else Example
if (radius >= 0) {
area = radius * radius * 3.14159;
JOptionPane.showMessageDialog(null, “The area
for the circle of radius “ + radius + “ is “
+ area);
}
else {
JOptionPane.showMessageDialog(null,“Negative
input”);
}
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Multiple Alternative if Statements
if (score >= 90.0)
grade = ‘A’;
else
if (score >= 80.0)
grade = ‘B’;
else
if (score >= 70.0)
grade = ‘C’;
else
if (score >= 60.0)
grade = ‘D’;
else
grade = ‘F’;
Equivalent
if (score >= 90.0)
grade = ‘A’;
else if (score >= 80.0)
grade = ‘B’;
else if (score >= 70.0)
grade = ‘C’;
else if (score >= 60.0)
grade = ‘D’;
else
grade = ‘F’;
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Be careful of curly braces!
• If there are no curly braces, only the first
statement after the if or else is executed
• Example:
if (x == 100)
boolean awesomeGrade = true;
JOptionPane.showMessageDialog(“You
earned an A+!”);
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Ternary Operator
• Represent an if/else statement block in one
line
• (booleanExp) ? true_branch : false_branch
• Example:
• JOptionPane.showMessageDialog(null,
(num % 2 == 0)? num + “is even” :
num + “is odd”);
IT 106: Introduction to IT Problem
Solving Using Computer Programming
switch Statements
• If a situation exists such that you want to
choose one option from a “chain” of if
statements, use a switch!
• A switch expression can take in:





int
short
byte
char
String
IT 106: Introduction to IT Problem
Solving Using Computer Programming
switch Statement Flow Chart
status is 0
Compute tax for single filers
break
Compute tax for married file jointly
break
Compute tax for married file separatly
break
Compute tax for head of household
break
status is 1
status is 2
status is 3
default
Default actions
Next Statement
IT 106: Introduction to IT Problem
Solving Using Computer Programming
switch Statement Example
switch (status) {
case 0: compute taxes for single filers;
break;
case 1: compute taxes for married file jointly;
break;
case 2: compute taxes for married file separately;
break;
case 3: compute taxes for head of household;
break;
default: JOptionPane.showMessageDialog(null, “Errors:
invalid status”);
break;
}
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Problem Example
• Scenario
• Calculate a letter grade for a student taking a
course that has equally weighted midterm and
final exams. Assume only valid grades will be
provided.
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Step 1: Define the Problem
• Input
• midtermExamGrade, finalExamGrade
• Processes




Prompt for exam scores
Read exam scores
Calculate grade
Print grade
• Output
• finalGrade
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Step 2: Solution Algorithm
BEGIN calculateFinalGrade
PROMPT user for midtermExamGrade
READ midtermExamGrade
PROMPT user for finalExamGrade
READ finalExamGrade
SET averageGrade = (midtermExamGrade + finalExamGrade) / 2;
IF averageGrade > 90 THEN
SET finalGrade =‘A’;
ELSE
IF averageGrade > 80 THEN
SET finalGrade =‘B’;
ELSE
IF grade > 70 THEN
finalGrade = ‘C’;
ELSE
IF grade > 60 THEN
finalGrade = ‘D’;
ELSE
finalGrade = ‘F’;
ENDIF
ENDIF
ENDIF
ENDIF
PRINT ‘The average grade is ‘, averageGrade, ‘ and the final grade is ‘, finalGrade
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Step 3: Test the Algorithm!
• Don’t forget the desk checking!
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Java Solution
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Strings
• A data type of char only represents one
character
• To represent multiple characters, use a String
• Example: String message = “I love JAVA!”;
• Strings can be concatenated with the +
operator
• String message = “I ” + “love ” + “Java”;
• String message = “Exam ” + 1; // Exam 1
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Style and Documentation
• Remember!
• Appropriate documentation (internal and external)
• Naming conventions
– Variables – camelCaseForVariables
– Constants – ALL_UPPERCASE_CHARACTERS
• Proper indentation and line spacing
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Programming Errors
• Syntax Errors
• Detected by the compiler
• A violation of the language rules
• Runtime Errors
• Causes the program to abort
– NumberFormatException
– Divide by 0
• Logic Errors
• Produces incorrect/unexpected result
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Example: Syntax Error
public class ShowSyntaxErrors {
public static void main(String[] args) {
i = 30;
System.out.println(i + 4);
}
}
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Example: Runtime Error
public class ShowRuntimeErrors {
public static void main(String[] args) {
int i = 1 / 0;
}
}
IT 106: Introduction to IT Problem
Solving Using Computer Programming
Example: Logic Error
import
public
int
int
javax.swing.JOptionPane;
class ShowLogicErrors {
x = 2;
y = 3;
JOptionPane.showMessageDialog(null, “The sum of x and y is:
” + x * y);
}
}
IT 106: Introduction to IT Problem
Solving Using Computer Programming

Calculate your order
275 words
Total price: $0.00

Top-quality papers guaranteed

54

100% original papers

We sell only unique pieces of writing completed according to your demands.

54

Confidential service

We use security encryption to keep your personal data protected.

54

Money-back guarantee

We can give your money back if something goes wrong with your order.

Enjoy the free features we offer to everyone

  1. Title page

    Get a free title page formatted according to the specifics of your particular style.

  2. Custom formatting

    Request us to use APA, MLA, Harvard, Chicago, or any other style for your essay.

  3. Bibliography page

    Don’t pay extra for a list of references that perfectly fits your academic needs.

  4. 24/7 support assistance

    Ask us a question anytime you need to—we don’t charge extra for supporting you!

Calculate how much your essay costs

Type of paper
Academic level
Deadline
550 words

How to place an order

  • Choose the number of pages, your academic level, and deadline
  • Push the orange button
  • Give instructions for your paper
  • Pay with PayPal or a credit card
  • Track the progress of your order
  • Approve and enjoy your custom paper

Ask experts to write you a cheap essay of excellent quality

Place an order