Question

In: Computer Science

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 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 Cool 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

Solutions

Expert Solution

Please up vote ,comment if any query . Thanks for question .Be safe .

Program Part1: ***************************Main.java*****************************

public class Main {

public static void main(String[] args) {
  
//string array declaration
String[] names = {"alice", "bob", "carla", "dennis", "earl", "felicia"};
  
for(int i=0;i<names.length;i++)
{
System.out.println(names[i]);//print each element in new line
}
  
}
}

Output : Part1

Program Part2 :*******************************ArrayTesting.java***********************************

public class ArrayTesting {
  
//this function takes integer array and size
public double getAverage(int []array,int size)
{
double sum=0.0; //sum store in this
for(int i=0;i<size;i++)
{
sum+=array[i]; //add each element into sum
}
sum=sum/size; //get average
sum=Math.round(sum * 100.0) / 100.0; //convert it into 2 decimal point
return sum; //return average
}
//takes double array and size
public double getAverage(double []array,int size)
{
double sum=0.0;
for(int i=0;i<size;i++)
{
sum+=array[i]; //add
}
sum=sum/size; //get average
sum=Math.round(sum * 100.0) / 100.0; //round for 2 decimal point
return sum; //return average
}
  
  

  
}


Program Part2 : Main class testing *******************Main.java***************************

public class Main {

public static void main(String[] args) {
  
int []intArray={3,4,5,7,8,9,11,71}; //integer array of size 8
double []doubleArray={3.134,4.2444,5.3458,7.4345,8.545,9.64350,11.7345,71.819};
int size =8; //size declaration
ArrayTesting Obj=new ArrayTesting(); //object create
System.out.println(Obj.getAverage(intArray, size)); //print average
System.out.println(Obj.getAverage(doubleArray, size));//print average of double array
  
}
}

Output :Part2

Program Part3 : **********************Main.java********************************

import java.util.Scanner;
public class Main {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in); //Input scanner object
int totalBonus=0; //total bonus
char name='A'; //employee name
int [][]bonusArray={{25,45,80,110,150}, //2d array for bonus
{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}};
  
while(true) //infinite loop
{
int totalWeeks;
int review;
System.out.print("Enter number of weeks employee worked : "); //prompt for total weeks
totalWeeks=sc.nextInt();
if(totalWeeks==-1) //if weeks -1
{
  
break; //exit loop and print total bonus
}
else
{
System.out.print("Enter customer reviews : "); //enter review
review=sc.nextInt();
if(review==-1) //if -1 exit program
{
  
break;
}
else
{
if(review>=4)//if enter 4 or more set 4
review=4;
if(totalWeeks>=6) //if 6 ot more 6
totalWeeks=6;
int bonus=bonusArray[totalWeeks][review]; //get bonus in bonus
//print bonus of each employee
System.out.println("Employee "+name+" worked "+totalWeeks+" weeks and got "+review+" positive reviews; bonus:$"+bonus);
totalBonus+=bonus; //get total bonus
name+=1; //increment A to B
}
}
}
//print exit using break print total bonus
System.out.println("Total bonus paid: $"+totalBonus);
  
}
}


Output : Part3

Please up vote ,comment if any query . Be safe .


Related Solutions

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...
Using the Java programming language: Create and implement a class Car that models a car. A...
Using the Java programming language: Create and implement a class Car that models a car. A Car is invented to have a gasoline tank that can hold a constant max of 12.5 gallons, and an odometer that is set to 0 for a new car. All cars have an original fuel economy of 23.4 miles per gallon, but the value is not constant. Provide methods for constructing an instance of a Car (one should be zero parameter, and the other...
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...
Java Programming Create a class named Problem1, and create a main method, the program does the...
Java Programming Create a class named Problem1, and create a main method, the program does the following: - Prompt the user to enter a String named str. - Prompt the user to enter a character named ch. - The program finds the index of the first occurrence of the character ch in str and print it in the format shown below. - If the character ch is found in more than one index in the String str, the program prints...
Use Java programming to implement the following: Implement the following methods in the UnorderedList class for...
Use Java programming to implement the following: Implement the following methods in the UnorderedList class for managing a singly linked list that cannot contain duplicates. Default constructor Create an empty list i.e., head is null. boolean insert(int data) Insert the given data into the end of the list. If the insertion is successful, the function returns true; otherwise, returns false. boolean delete(int data) Delete the node that contains the given data from the list. If the deletion is successful, the...
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,...
Java Programming Using the class below, please ), write a static method called parse that parses...
Java Programming Using the class below, please ), write a static method called parse that parses a String for balanced parentheses. we seek only to determine that the symbol ‘{‘ is balanced with ‘}’. parse accepts a single String parameter and returns an int. If parse returns a minus 1, then there are no errors, otherwise, parse should return the position within the String where an error occurred. For example parse(“{3 + {4/2} }”)   would return -1 parse(“{ { 4*X}”)...
Java programming language should be used Implement a class called Voter. This class includes the following:...
Java programming language should be used Implement a class called Voter. This class includes the following: a name field, of type String. An id field, of type integer. A method String setName(String) that stores its input into the name attribute, and returns the name that was just assigned. A method int setID(int) that stores its input into the id attribute, and returns the id number that was just assigned. A method String getName() that return the name attribute. A method...
Required components: A controller class with Java main() method and a PaymentCalculator class to hold the...
Required components: A controller class with Java main() method and a PaymentCalculator class to hold the data and methods for the application. Scenario/Information: If you carry a balance on a credit card, it can be nice to see how long it would take to payoff the card. For this scenario, you should design a Java application the prints a credit card payment schedule. Inputs for your program should include: Customer’s name (first and last), the account number (as an integer),...
JAVA PROGRAMMING Implement a class Purse. A purse contains a collection of coins. For simplicity, we...
JAVA PROGRAMMING Implement a class Purse. A purse contains a collection of coins. For simplicity, we will only store the coin names in an ArrayList<String>. Supply a method void addCoin(String coinName). Add a method toString to the Purse class that prints the coins in the purse in the format Purse[Quarter,Dime,Nickel,Dime]. Write a method reverse that reverses the sequence of coins in a purse. Implement a TestPurse class with a main method in it. It will use the toString method to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT