Question

In: Computer Science

Part 1 (20%) Implement a class with a main method. Using an enhanced for loop, display...

Part 1 (20%)

Implement a class with a main method. Using an enhanced for loop, display each element of this array:

String[] names = {"alice", "bob", "carla", "dennis", "earl", "felicia"};

Part 2 (30%)
In a new class, implement two methods that will each calculate and return the average of an array of numeric values passed into it. Constraints:

  • your two methods must have the same name
  • one method should accept an array of ints; the other should accept an array of doubles
  • both methods must return the average to at least two decimal places of accuracy

Implement a new class demonstrating your methods in action. Call your methods at least twice each with arrays of different sizes each time.

Part 3 (50%)
The Valencia Ice Cream Shoppe pays its summer employees bonuses based on two factors: the number of weeks worked over the summer, and the number of positive customer reviews. The table below shows the bonuses based on these two factors.

Positive Reviews (right)

Weeks Worked (down)

0 1 2 3 4 or more
0 25 45 80 110 150
1 50 60 90 120 180
2 100 125 160 210 265
3 160 190 225 275 340
4 230 270 325 385 450
5 300 360 420 480 600
6 or more 425 500 600 700 875

Examples:

  • Employee A worked 4 weeks and got 2 positive reviews; bonus: $325.
  • Employee B worked 1 week and got 7 positive reviews; bonus: $180
  • Employee C worked 8 weeks and got 0 positive reviews; bonus: $425
  • Total bonuses paid: $930

Write an application that:

  • stores the bonus values in a two-dimensional array
  • allows the user to enter values for weeks worked and reviews received, and displays the amount of the bonus
  • only accepts valid values for input (focus on valid ranges; don't worry about preventing wrong type input)
  • allows the user to keep entering values until some sentinel value is entered, at which point the program ends
  • upon ending, displays the total amount of bonuses paid out based upon the values entered

Please submit:

(1) all source code (.java files)
(2) screenshots showing all programs in action (image files)

Solutions

Expert Solution

Question 1  

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication23;
import java.util.Random;
import java.util.Scanner;

/**
 *
 * @author haptop laptop
 */
public class JavaApplication23 {

    /**
     * @param args the command line arguments
     */
    
  
    public static void main(String[] args) {
        // TODO code application logic here
        String [] names={"alice","bob","carla","dennis","earl","felicia"};
                for(int i=0;i<names.length;i++)
                System.out.print(names[i]+" ");
                
       
       
    }
    
    
}

Question 2

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication23;
import java.util.Random;
import java.util.Scanner;

/**
 *
 * @author haptop laptop
 */

class Test{
   
    double findAverage(int [] array)
    {
        int sum=0;
        for(int i=0;i<array.length;i++)
        {
            sum+=array[i];
            
        }
       double average=(sum*1.0)/(array.length);
       return Math.round(average*100.0)/100.0;//to return up to 2 decimal
       
    }
    double findAverage(double [] array)
    {
        double sum=0;
        for(int i=0;i<array.length;i++)
        {
            sum+=array[i];
        }
       double average=(sum*1.0)/(array.length);
       return Math.round(average*100.0)/100.0;//to return up to 2 decimal
       
        
    }
    
}
public class JavaApplication23 {

    /**
     * @param args the command line arguments
     */
    
  
    public static void main(String[] args) {
        // TODO code application logic here
        int[] myArray1={1,2,3,4,5,6,6};
        double[] myArray2={1.0,2.1,3.2,4.3,5.3,6.2};
        Test t1=new Test();
        System.out.println("Average of first array"+t1.findAverage(myArray1));
        System.out.println("Average of second array"+t1.findAverage(myArray2));
        
       
    }
    
    
}

Question 3

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication23;
import java.util.Random;
import java.util.Scanner;

/**
 *
 * @author haptop laptop
 */

public class JavaApplication23 {

    /**
     * @param args the command line arguments
     */
    
  
    public static void main(String[] args) {
        // TODO code application logic here
        int bonuse[][]={{25,45,80,110,150},{50,60,90,120,180},{100,125,160,210,265},{160,190,225,275,340},{230,270,325,385,450},{300,360,420,480,600},{425,500,600,700,875}};
           Scanner sc=new Scanner(System.in);
            System.out.print("Enter number of employeees? ");
            int n=sc.nextInt();
            int sum=0;
            while(n>0)
            {
                System.out.print("Enter number of week worked and review ");
                int row=sc.nextInt();
                int col=sc.nextInt();
                if(col>=4)
                {
                    col=4;
                }
                if(row>=6)
                    row=6;
                System.out.println("Employee will get $"+bonuse[row][col]);
                
                sum+=bonuse[row][col];
                
                n--;
            }
            System.out.println("Total bonus $"+sum);
        }

       
    }
    
    


Related Solutions

Java Programming Part 1 (20%) Implement a class with a main method. Using an enhanced for...
Java Programming Part 1 (20%) Implement a class with a main method. Using an enhanced for loop, display each element of this array: String[] names = {"alice", "bob", "carla", "dennis", "earl", "felicia"}; Part 2 (30%) In a new class, implement two methods that will each calculate and return the average of an array of numeric values passed into it. Constraints: your two methods must have the same name one method should accept an array of ints; the other should accept...
Part I: Have a program class named TestArrays This class should have a main() method that...
Part I: Have a program class named TestArrays This class should have a main() method that behaves as follows: Have an integer array of size 10. Using a loop, fill the elements with increments of 5, starting with 5 in the first element. Using the array elements, sum the second, fifth and seventh elements. Display the sum with a label. Change the fourth element to 86. Subtract 9 from the ninth element. Using a loop, display the elements of the...
java programming Concepts ArrayList - Collections Sorting Enhanced For Loop Collections Class Auto-boxing Programming Assignment 1....
java programming Concepts ArrayList - Collections Sorting Enhanced For Loop Collections Class Auto-boxing Programming Assignment 1. Describe auto-boxing, including why it is useful. (Google for this one) Write a few lines of code that auto-box an int into an Integer, and un-box an Integer to an int. 2. Declare an ArrayList of Strings. Add 5 names to the collection. "Bob" "Susan" ... Output the Strings onto the console using the enhanced for loop. 3. Sort the list using the method...
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of...
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of Poem objects, read in the information from PoemInfo.txt and create Poem objects to populate the ArrayList. After all data from the file is read in and the Poem objects added to the ArrayList- print the contents of the ArrayList. Paste your PoemDriver.java text (CtrlC to copy, CtrlV to paste) into the open space before. You should not change Poem.java or PoemInfo.txt. Watch your time...
In short, you’re going to implement a linked-list class for storing integers, using a provided main...
In short, you’re going to implement a linked-list class for storing integers, using a provided main program to help you interact and test your work. You’ll want to build the linked-list class function by function, working in “Develop” mode to test out each function you write. main.cpp is a read only file linkedlist.h is the file to work on. main.cpp #include #include #include "linkedlist.h" using namespace std; int main() { linkedlist LL; string cmd; int value, key; // // user...
in netbeans using Java Create a project and a class with a main method, TestCollectors. ☑...
in netbeans using Java Create a project and a class with a main method, TestCollectors. ☑ Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. ☑ Add a method addToCollection. In this method,...
(a) In C++, write down the main method including a for loop. The body of the...
(a) In C++, write down the main method including a for loop. The body of the for loop includes the followings : i. an if condition ii. an array (of any type & of any size) iii. a structure variable (with at least two variables of any type) (b) Show the corresponding code contents in memory for the main method and draw the stack contents while the main method starts execution and reaches at the line prior to return from...
Use the Heap class provided to implement a sort routine in a Main class where the...
Use the Heap class provided to implement a sort routine in a Main class where the user enters a series of values, each value is then pushed onto a heap, then the values are printed out in ascending order. public class Heap { public static final int SIZE = 1025; public Heap() { elt = new Element[SIZE]; lastLoc = 0; } public void push(String k, Object o) { if (!fullCheck()) { lastLoc++; elt[lastLoc] = new Element(k,o); int loc = lastLoc;...
Implement a class called DoublyLinkedList. In the main function, instantiate the DoublyLinkedList class and make sure that there is a user loop and a menu so that the user can access all the list operators.
C++  Implement a class called DoublyLinkedList. In the main function, instantiate the DoublyLinkedList class and make sure that there is a user loop and a menu so that the user can access all the list operators. You should implement the following operators, and any others that you may deem best. DestroyList InitializeList GetFirst InsertFirst, InsertLast, Insert DeleteFirst, DeleteLast, Delete IsEmpty Length Print, ReversePrint
Name the project pa3 [Method 1] In the Main class, write a static void method to...
Name the project pa3 [Method 1] In the Main class, write a static void method to print the following text by making use of a loop. Solutions without a loop will receive no credit. 1: All work and no play makes Jack a dull boy. 2: All work and no play makes Jack a dull boy. 3: All work and no play makes Jack a dull boy. 4: All work and no play makes Jack a dull boy. [Method 2]...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT