NEED IN JAVA ECLIPSE
For this lab, you will create a program that uses method overloading and a switch statement.
Requirements:
The Patapsco River Valley Running Festival needs a program that will allow them to calculate
the cost of the entry fee for each group of entrants. Once the cost is calculated, it is then
displayed to the user.
The program also totals up the total amount of money that will be collected and displays the total
at the very end when the user states that they have no more entries.
You will use the program you wrote in Lab 3 as the starting point for this lab. All of the data
entry for each program is exactly the same. However, the program now displays the cost of the
race entered and the total cost of all of the races.
CODE FROM LAB 3:
/**
*
*/
package volunteers;
/**
*
*
* This program will create a counter which will count the number of
Howard County residents attending the event versues the number
of
* non- Howard County residents. The program will also tally the
number of runners in each of the race lengths. Finally, the
program
* will collect the age of the runner.
*/
import java.util.Scanner;
public class Volunteers {
// Instantiate scanner
static Scanner input=new Scanner(System.in);
public static void main(String[] args)
{
// declaring and initializing variables
int total_runner=0;
int Howard_County_Residents=0;
int non_Howard_County_Residents=0;
int total_children=0;
int total_adults=0;
int total_senior=0;
int total_5k=0;
int total_10k=0;
int total_HalfMarathon=0;
int total_FullMarathon=0;
int total_fun_run=0;
int age,runChoice;
String userChoice;
while(true)
{
userChoice=takeUserInput("\n\nWould you like to add a runner? Enter
'yes' or 'no'.");
if(userChoice.equals("no"))
break;
total_runner++;
userChoice=takeUserInput("\n\nIs the Runner a Howard County
resident? Enter 'Yes' or 'No':");
if(userChoice.equals("yes"))
Howard_County_Residents++;
else
non_Howard_County_Residents++;
while(true)
{
System.out.println("\n\nWhat is the runner's age?");
age=input.nextInt();
if(age>0)
break;
else
System.out.println("\n\nInvalid Entry. Age must be greater than 0.
Please reenter:");
}
if(age<10 || age>=70)
{
if(age<10)
total_children++;
else
total_senior++;
while(true)
{
System.out.println("\nSelect the event the runner will be running
in:\r\n" +
"1 - 5K\r\n" +
"2 - 10K\r\n" +
"3 - Half Marathon\r\n" +
"4 - Full Marathon\n5 - 1 Mile Fun Run");
runChoice=input.nextInt();
if(runChoice>=1 && runChoice<=5)
break;
else
System.out.println("\nInvalid Entry. Please select a value from the
menu. Please reenter:");
}
}
else
{
total_adults++;
while(true)
{
System.out.println("\nSelect the event the runner will be running
in:\r\n" +
"1 - 5K\r\n" +
"2 - 10K\r\n" +
"3 - Half Marathon\r\n" +
"4 - Full Marathon");
runChoice=input.nextInt();
if(runChoice>=1 && runChoice<=4)
break;
else
System.out.println("\nInvalid Entry. Please select a value from the
menu. Please reenter:");
}
}
if(runChoice==1)
total_5k++;
else if(runChoice==2)
total_10k++;
else if(runChoice==3)
total_HalfMarathon++;
else if(runChoice==4)
total_FullMarathon++;
else
total_fun_run++;
} // printing the stats
System.out.println("\nTotal Runners: "+total_runner);
System.out.println("Total Howard County Residents:
"+Howard_County_Residents);
System.out.println("Total Non-Howard County Residents:
"+non_Howard_County_Residents);
System.out.println("\nTotal number of children:
"+total_children);
System.out.println("Total number of adults: "+total_adults);
System.out.println("Total number of seniors: "+total_senior);
System.out.println("\nTotal 5K Runners: "+total_5k);
System.out.println("Total 10K Runners: "+total_10k);
System.out.println("Total Half Marathon Runners:
"+total_HalfMarathon);
System.out.println("Total Half Marathon Runners:
"+total_FullMarathon);
System.out.println("Total Fun Run Participants:
"+total_fun_run);
}
public static String takeUserInput(String s)
{
String choice;
while(true)
{
System.out.println(s);
choice=input.next();
if(choice.equals("yes") || choice.equals("no"))
break;
else
{
System.out.print("\nInvalid Entry. Only 'yes' or 'no' is
acceptable. Please reenter:");
}
}
return choice;
} // End of main method
} // End of class Volunteer
This enhanced program will need to do the following calculations:
Race Event- 5K
Howard County Res Cost- $25
Non-Howard County Res Cost- $40
Race Event- 10K
Howard County Res Cost- $35
Non-Howard County Res Cost- $50
Race Event- Half Marathon
Howard County Res Cost- $65
Non-Howard County Res Cost- $85
Race Event- Full Marathon
Howard County Res Cost- $85
Non-Howard County Res Cost- $115
Race Event- Fun Run
Howard County Res Cost- $20
Non-Howard County Res Cost- $25
Non-Howard County residents who are 18 years of age or younger or 60 years of age or older get
a $5 discount on their entry fee. There are no discounts for county residents.
You should use a switch statement to implement the table, and you should not use the reserved
word "return" within the switch statement.
NOTE: There should be only ONE named method (an overloaded method is acceptable) to
determine and return the cost of the event for Howard County residents and non-Howard County
residents. Use the method parameters to distinguish between cases.
You should declare constant values for all of the costs listed in the table.
This code should all be contained within one class file.
OUTPUT SHOULD LOOK LIKE THIS:
Would you like to add a runner? Enter 'yes' or 'no'.
test
Invalid Entry. Only 'yes' or 'no' is acceptable. Please reenter:
Would you like to add a runner? Enter 'yes' or 'no'.
yes
Is the Runner a Howard County resident? Enter 'Yes' or 'No':
yes
What is the runner's age?
-2
Invalid Entry. Age must be greater than zero. Please reenter:
What is the runner's age?
32
Select the event the runner will be runnning in:
1 - 5K
2 - 10K
3 - Half Marathon
4 - Full Marathon
3
You have entered the Half Marathon race. The cost is $65.00
Would you like to add a runner? Enter 'yes' or 'no'.
yes
Is the Runner a Howard County resident? Enter 'Yes' or 'No':
no
What is the runner's age?
43
Select the event the runner will be runnning in:
1 - 5K
2 - 10K
3 - Half Marathon
4 - Full Marathon
3
You have entered the Half Marathon race. The cost is $85.00
Would you like to add a runner? Enter 'yes' or 'no'.
yes
Is the Runner a Howard County resident? Enter 'Yes' or 'No':
no
What is the runner's age?
62
Select the event the runner will be runnning in:
1 - 5K
2 - 10K
3 - Half Marathon
4 - Full Marathon
3
You have entered the Half Marathon race. The cost is $80.00
Would you like to add a runner? Enter 'yes' or 'no'.
yes
Is the Runner a Howard County resident? Enter 'Yes' or 'No':
no
What is the runner's age?
9
Select the event the runner will be runnning in:
1 - 5K
2 - 10K
3 - Half Marathon
4 - Full Marathon
5 - 1 Mile Fun Run
5
You have entered the Fun Run race. The cost is $20.00
Would you like to add a runner? Enter 'yes' or 'no'.
yes
Is the Runner a Howard County resident? Enter 'Yes' or 'No':
no
What is the runner's age?
75
Select the event the runner will be runnning in:
1 - 5K
2 - 10K
3 - Half Marathon
4 - Full Marathon
5 - 1 Mile Fun Run
2
You have entered the 10K race. The cost is $45.00
Would you like to add a runner? Enter 'yes' or 'no'.
yes
Is the Runner a Howard County resident? Enter 'Yes' or 'No':
no
What is the runner's age?
23
Select the event the runner will be runnning in:
1 - 5K
2 - 10K
3 - Half Marathon
4 - Full Marathon
4
You have entered the Full Marathon race. The cost is $115.00
Would you like to add a runner? Enter 'yes' or 'no'.
no
Total Runners: 6
Total Howard County Residents: 1
Total Non-Howard County Residents: 5
Total number of children: 1
Total number of adults: 4
Total number of seniors: 1
Total 5K Runners: 0
Total 10K Runners: 1
Total Half Marathon Runners: 3
Total Full Marathon Runners: 1
Total Fun Run Participants: 1
The total cost of all of the races entered is $410.00
In: Computer Science
This is to be done in C++. Preferably using basic functions.
Write a loop that reads one double each time around.
Define two variables to keep track of which is the smallest and which is the largest value you have seen so far.
Each time through the loop write out the value entered. If it's the smallest so far, write the smallest so far after the number. If it is the largest so far, write the largest so far after the number.
Let the user add a unit to each double entered; that is, enter values such as 10cm, 2.5in, 5ft, or 3.33m.
Accept the four units: cm, m, in, ft.
Assume conversion factors 1m == 100cm, 1in == 2.54cm, 1ft == 12in.
Read the unit indicator into a string.
You may consider 12 m (with a space between the number and the unit) equivalent to 12m (without a space).
Reject values without units or with "illegal" representations of units, such as y, yard, meter, km, and gallons.
Keep track of the sum of values entered (as well as the smallest and the largest) and the number of values entered. When the loop ends, print the smallest, the largest, the number of values, and the sum of values. note that to keep the sum, you have to decide on a unit to use for that sum; use meters.
Keep all the values entered (converted into meters) in a vector. At the end, write out those values.
Before writing out the values from the vector, sort them (that'll make them come out in increasing order).
In: Computer Science
python- please finish the three programs, where one flips an image horizonally, then vertically, and one that rotates an image by 90 degrees. please don't use the functions .mirror() .flip() or .rotate() if possible. thanks
def horizontal(image):
"""Flip the specified image left to right and return the modified
image"""
return img
def vertical(image):
"""Flip the specified image upside down and return the modified
image"""
return image
def rotate_90(image):
"""Rotate the specified image 90 degrees to the right and return
the modified image"""
return image
In: Computer Science
Create a new program, called stars.py, for (eventually) drawing a 500x500 pixel picture of the night sky. The stars.py file will define several custom functions. You should write each function and then test it to verify it is working correctly. Make sure you match each function name precisely. Once complete submit it to D2L.
getStarPixelX()
Below are some example function calls and return values. You should test them by having your program call the function and print out the return value. (You can erase your test code later.)
getStarPixelY()
Below are some example function calls and return values. You should test them by having your program call the function and print out the return value. (You can erase your test code later.)
getStarSize()
Below are some example function calls and return values. You should test them by having your program call the function and print out the return value. (You can erase your test code later.)
getStarName()
Below are some example function calls and return values. You should test them by having your program call the function and print out the return value. (You can erase your test code later.)
In: Computer Science
Sources: linkedlist.cpp
#include <iostream>
#include "linkedlist.h"
using namespace std;
LinkedList* NewLinkedList()
{
LinkedList* llp = new LinkedList;
llp->head = new node;
llp->head->next = 0;
return llp;
}
void InsertFirst(LinkedList* llp, int val)
{
node* p = new node;
p->data = val;
p->next = llp->head->next;
llp->head->next = p;
}
void Print(LinkedList* llp)
{
for (node* p = llp->head->next; p != 0; p = p->next)
{
cout << p->data << " ";
}
}
void InsertLast(LinkedList* llp, int val)
{
node* p;
for (p = llp->head; p->next != 0; p = p->next)
{
}
// p now points to the last node in the list
// For you to do: Create a new node, store val in that node, and link the new node after p.
}
Sources: hw1.cpp
#include <iostream>
#include "linkedlist.h"
using namespace std;
int main()
{
LinkedList* llp = NewLinkedList();
InsertFirst(llp, 10);
InsertFirst(llp, 20);
InsertFirst(llp, 30);
cout << endl;
Print(llp);
cout << endl;
InsertLast(llp, 50);
InsertLast(llp, 60);
InsertLast(llp, 70);
cout << endl;
Print(llp);
cout << endl;
return 0;
}
Header: linkedlist.h
#ifndef LINKEDLIST_H_INCLUDED
#define LINKEDLIST_H_INCLUDED
struct node {
int data;
node* next;
};
struct LinkedList {
node* head;
};
LinkedList* NewLinkedList();
void InsertFirst(LinkedList* llp, int val);
void Print(LinkedList* llp);
void InsertLast(LinkedList* llp, int val);
#endif // LINKEDLIST_H_INCLUDED
-----------------------------
Your assignment is to complete the function InsertLast in linkedlist.cpp, compile, and run. The correct output should be:
30 20 10
30 20 10 50 60 70
In: Computer Science
Question about Hard Disks
1. For Redundant Arrays of Inexpensive Disks, which of the following two has more reliability? The Level 0 + 1 (Striping + Mirroring) or Level 1 + 0 (Mirroring + Striping)? Why?
2. Why does the Elevator have better performance than Shortest Seek Time First algorithm for a heavy load? (Elevator is also called the SCAN or C-SCAN)
3. Do accesses to sectors in outer tracks require less time compared to accesses sectors to inner tracks? Why or why not?
In: Computer Science
Create the program using C#
A business records its daily sales totals. Enter the following weekly sales information into an array.
1245.67
1189.55
1089.72
1456.88
2109.34
1987.55
1872.36
Once, the information has been entered into the array. Access the items in the array to find and display the following:
In: Computer Science
In: Computer Science
What are differences between structure and union by coding example in C language?
In: Computer Science
It seems like every day we hear about another data breach. Find and discuss at least TWO recent examples of data breaches. Why are these important? How can these affect a business? In the examples you cite, what was the cost to the business involved? How long did the breach continue before the company find the breach? Cite your sources. Do these cause you to not buy items online or use social media?
In: Computer Science
Write this code in full c++ and in separate files in visual studio.
Binary Search Tree Using a binary search tree, you are tasked with building a dictionary program that stores a word with its definition. Each node of the tree will contain the word and definition. The word is what will be used as the key to sort our data. The dictionary should allow you to search for a word. If the word exists in the dictionary then the definition will display. You can also add words to the dictionary. For testing you should be able to display the current word list. The dictionary will populate from a data file and new words will be saved to the file as well.
In: Computer Science
Lab Directions:
Complete each
of the programs
here. Create a
separate Netbeansproject
for each program using the name I specified. Create a single java
main class for each of the programs using the filename I
specified.
Task
1: (5 points)
Project name:
CtoFConverter
Main
file name:
TempConverter.java
A program that converts an inputted temperature in
C
and provides the equivalent temperature in
F.
Hint: Google is your friend! Given
C,
solve for
F.
Again, check for a valid input value and only respond with
the
F
value if you got it, otherwise output an appropriate error msg to
the user.
Testing: 3 conditions: Bad Input, then test for the known freezing
and boiling points.
EMBED
SCREEN SHOT(S)
OR COPY THE OUTPUT WINDOW
OF NETBEANS HERE SHOWING YOUR PROGRAM TEST RUN(S):
Task
2: (5 points)
Project
name:
FuelCosts
Main
file name: FuelCost.java
Write a program that asks the user to input
Then print how far the car can go with the gas in the tank. Again, check for valid input and exit with an error msg if you do not have it. Testing: here just use some reasonable values that you can inspect the calculations and determine they are correct.
EMBED SCREEN SHOT(S) OR COPY THE OUTPUT WINDOW OF NETBEANS HERE SHOWING YOUR PROGRAM TEST RUN(S):
Submitting your work:
Create a new compressed .zip archive folder. (Don’t give me any other type of archive, it will be returned to you ungraded!) called Lastname_Firstname_Lab_06.zip using your name.
Place
both
of your
Netbeans
project
folders in this archive. (Do
not individually zip the projects!) Place
this word doc file with your screen shots in the archive as well.
(Don’t put this in the individual project folders, put it in the
top level in the archive so I can access it easily.)
(When I
open you archive I should see each of your project folders in it
and this file.)
Submit the one Zip file (with both NetBeans projects and the Word document) for your grade.
In: Computer Science
Prof. Orlando Karam maintains an Ubuntu Linux server for his class. Every semester he needs to create an account for each student. It takes a lot of time to create these accounts one by one interactively. So he decides to automate the process by writing a script. You are Orlando’s TA and volunteered to complete the task. Please propose a solution and write a script (either Bash or Perl) to implement your solution. Basic requirements: The script reads from a CSV file for student information (exported from Excel). The file is made up of the lines like this: Jack,Zheng,jzheng3 //[first name],[last name],[campus email id] Mark,Cuban,mcuban2 … Please make up your own CSV file (with at least 5 students/lines) for testing purpose. Every student is assigned a common initial password (you will determine the password). Students are required to change their passwords at first login. All student accounts should be assigned to a “student” group. This group already exists in the system (you need to create this group first for testing purpose). Make some other assumptions if not specifically required. Reminder: you will and should do some research on how to read and parse CSV files, and how to process passwords programmatically. Execute your script and take two screen shots: a. The “passwd” file content, with the new accounts clearly shown. b. The “shadow” file content, with the new accounts clearly shown. 2. Login with one of the new student account and show that you have successfully logged in using the newly created account. Take a screen shot showing the user id in the terminal. 3. Compile one PDF document with the script, the CSV file content, and all three screen shots, clearly labeled for each part.
In: Computer Science
Financial Records
Create a program to store weekly expenses and revenues over a period of time. The program should
store the expenses and revenues in two global array variables. Values stored in the array at index k
represent the total revenues/expenses recorded during the k(th) week. Assume that the maximum number of weeks tracked is 250.
Add the following functions to your program:
-
A function that finds the total of all expenses incurred since week t for a given t.
-
A function that records the total expenses and revenues for the next unrecorded week. It must check if there is still space in the array.
-
A function that prints the number of weeks recorded
-
A function that prints all revenues and expenses recorded
-
A function that returns a pointer to the largest revenue recorded
Organize the program so the function prototypes are presented
first, and the definitions after the main
function. Your program should keep asking the user to select
one of the following options and execute
the corresponding function based on the user choice:
(A)
computed the total of all expenses,
(B)
add a new expense/revenue ,
(C)
print the number of weeks recorded,
(D)
print all revenues and expenses recorded,
(E)
print the largest revenue recorded, or
(F)
exit the program.
In: Computer Science
In Java design a class named Course to represent a course. The class contains:
Private data fields:
• courseName of type String
• courseNumber of type String
• section of type int
• numberStudents of type int
• finalGrades array of 100 double numbers
A constructor that creates a course with the specified name, number, section , and number of students.
A method setGrades() that will prompt the user to the enter the grades into double [] finalGrades.
int numberStudents, will control how many cells will be used.
A method to find and print the maximum grade.
A method to find and print the average grade.
Implement the class.
Write a test program that
Creates the course course1/CS155 with the values (CS, 155, 01, 20)
Uses setGrades to read 20 grades for the course course1/CS155. Note numberStudents or
finalGrades.length can be used in your for loop holding the value of 20.
print the maximum grade for course1/CS155
print the average grade for course1/CS155
Creates the course course2/CS300 with the values (CS, 300, 03, 30).
Uses setGrades to read 30 grades for the course course2/CS300. Note numberStudents or finalGrades.length can be used in your for loop holding the value of 20.
print the maximum grade for course2/CS300
print the average grade for course2/CS300
In: Computer Science