needs to be in basic pseudocode. with no specific language. 1) Our college’s Wor
ID: 3869153 • Letter: N
Question
needs to be in basic pseudocode. with no specific language.
1) Our college’s Workforce Solutions department offers non-credit classes in various areas of interest in the community, as shown below, along with their fees.
Class Number
Class Name
Fee
1 Acrylic Painting for Beginners $79.00
2 Advanced Photography $115.00
3 Basic Photography $115.00
4 Blues and Boogie Woogie Piano $85.00
5 Public Speaking and Speech Giving $99.00
6 Sign Language Level I $49.00
Assume that the following declarations have already been made
num totalEnrollment
num averageEnrollment
num highestEnrollment
num lowestEnrollment
num indexOfHighest
num indexOfLowest
num classNumber
num desiredClassNumber
a) Declare any required variables and constants, and arrays for the class names, the fees and the enrollment count for each class. The table above shows only the current group of classes that have been scheduled. The program must be capable of being modified to accommodate more or fewer classes later by editing only one line of code.
b) Assume that the class name and fee arrays have been filled. You do not have to write code to fill them.
c) The program should continuously accept a class number and then display the class’s name, until the user enters an appropriate sentinel value to stop entering input. Each time the user enters a valid class number, the program asks the user if he/she wants to sign up for the class, and if they do, simply updates the count of people who have signed up for the class.
d) Once the user decides to stop, the program should display
i) each class number, name and fee Page 2 of 3
ii) a count of the number of people signed up for each class
iii) the total number of people signed up for classes
iv) the average class enrollment
v) the names of the highest enrolling class and the lowest enrolling class – this should be done without any sorting
example of what I'm looking for is;
start
Declarations
num itemPrice
num salespersonCommission
num customerDiscount
output “Welcome to the sales price calculator.”
output “This program will help you calculate the final”,
"price of a product adding in all factors.”
finalPrice= calculatePrice()
output “The total price after Commission, $” salespersonCommission, “and customer discount,”
“ customerDiscount “%, is”, finalPrice
stop
Explanation / Answer
public static void main(String args[]) {
// Create an array list for order to read data from the file
ArrayList<String> orders = new ArrayList<String>();
// Create sell and buys array list to get the list of
// buyers and sellers
ArrayList<String> sells = new ArrayList<String>();
ArrayList<String> buys = new ArrayList<String>();
// declare the required variables
int price = 0;
int exchange = 0;
// since we are using files put the execution code in try..catch
// block
try {
// create a file object by passing it to scanner class
// to read the file data
Scanner input = new Scanner(System.in);
// read the lines from the text file
while (input.hasNextLine()) {
orders.add(input.nextLine());
}
// separate the orders
for (int i = 0; i < orders.size(); i++) {
System.out.println("" + orders.get(i));
if (orders.get(i).contains("sell")) {
sells.add(orders.get(i));
}
if (orders.get(i).contains("buy")) {
buys.add(orders.get(i));
}
}
// now get the price values from each line from the
// respective orders and compare the values
int buy = 0;
int sell = 0;
for (int i = 0; i < buys.size(); i++) {
buy = getPrice(buys.get(i));
for (int j = 0; j < sells.size(); j++) {
sell = getPrice(sells.get(j));
// if the values are same, then compute the clear price
// values
// and increment the exchange value
if (buy == sell) {
price += 2 * buy;
exchange += 2;
}
}
}
// print the final statement.
System.out.println(" Units of exchanged " + exchange + " total clearing price "+ price);
} catch (Exception e) {
e.printStackTrace();
}
}
// getPrice method that retrieves the integer values from
// each line
public static int getPrice(String s) {
// use the scanner object to access the line values
Scanner in = new Scanner(s).useDelimiter("[^0-9]+");
int i = 0;
int j = 0;
// get the integer values
while (in.hasNext()) {
i = in.nextInt();
j = in.nextInt();
}
// return the required price value
return j;
}
import java.util.Scanner; // program uses class Scanner
public class RetailSales
{
private String buyerName; // name of the purchaser
// int instance variables are initialized to 0 by default
private int total; // sum of purchase price
private int purchaseCounter; // number of purchases made
private int product1; // count of product 1 purchases
private int product2; // count of product 2 purchases
private int product3; // count of product 3 purchases
private int product4; // count of product 4 purchases
private int product5; // count of product 5 purchases
// constructor initializes productName
public RetailSales( String name )
{
buyerName = name;// intitializes productName
}// end contstructor
// method to set product name
public void setBuyerName( String name )
{
buyerName = name;// store the product name
}// end method setProductName
// method to return product name
public String getBuyerName()
{
return buyerName;
}// end method getProductName
// display a welcome message to the purchaser
public void displayMessage()
{
// getBuyerName gets name of purchaser
System.out.printf( "Hello, %s! Please select the products that you wish to purchase.", getBuyerName() );
}// end method displayMessage
// inpute arbitrary number for product selection from user
public void inputPurchase()
{
Scanner input = new Scanner( System.in );
int selection; // product entered by user
System.out.printf( "%s %s %s %s ",
"Enter a product selection using an integer in range of 1-5.",
"Type end-of-line indicator complete purchase",
"On UNIX/Linux/Mac OS X type <Ctrl> d then press Enter",
"On Windows type <Ctrl> z then press Enter" );
// loop until user enters sentery
while( input.hasNext() )
{
selection = input.nextInt(); // read selection
total += selection; // add selection to total
++purchaseCounter; // increment number of selections
// call the method to increment appropriate counter
incrementNumberPurchaseCounter( selection );
}// end method inputPurchase
}
// add 1 to appropriate counter for specified counter
private void incrementNumberPurchaseCounter( int selection )
{
// determine which product number was entered
switch( selection )
{
case 1: // selection was product1
++product1; // increment product1
break;
case 2: // selection was product2
++product2; // increment product2
break;
case 3: // selection was product3
++product3; // increment product3
break;
case 4: // selection was product4
++product4; // increment product4
break;
case 5: // selection was product5
++product5; // increment product5
break;
}// end switch
} // end method incrementNumberPurchaseCounter
// display a report based on the selections entered
public void displayPurchaseReport()
{
System.out.println( " Purchases this session: ");
// if user entered at leaset on grade...
if( purchaseCounter != 0 )
{
// calculate total of all products entered
double sum = (double) total + purchaseCounter;
// output summary of results
System.out.printf( "Total of the %d products enter is %d ", purchaseCounter, total );
System.out.printf( "The total cost is %d ", sum );
System.out.printf( "%s %s%d %s%d %s%d %s%d %s%d ",
"Number of each product purchased: ",
"Product 1: ", product1,
"Product 2: ", product2,
"Product 3: ", product3,
"Product 4: ", product4,
"Product 5: ", product5 );
} // end if
else // no product numbers were entered
System.out.println( "No products were entered" );
} // end method displayPurchaseReport
} // end class
And the Main Class source code
/**
* RetailSalesTest.java
* version 1.00 2011/6/23
*/
public class RetailSalesTest
{
public static void main( String[] args )
{
// create GradeBook object myGradeBook and
// pass course name to constructor
RetailSales myRetailSales = new RetailSales(
"John" );
myRetailSales.displayMessage(); // display welcome message
myRetailSales.inputPurchase(); // read purchase from user
myRetailSales.displayPurchaseReport(); // display report based on purchases
} // end main
} // end class GradeBookTest
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.