JAVA CODE
Write two definitions of a boolean method called equals(). The method compares the instance variables of the class for equality. One is in the Purchase class and the other is a static method of the main. Give sample calls for each.
public class PurchaseDemo
{ public static void main(String[] args)
{
Purchase oneSale = new Purchase();
oneSale.readInput();
oneSale.writeOutput();
System.out.println("Cost each $" + oneSale.getUnitCost());
System.out.println("Total cost $" + oneSale.getTotalCost());
}
}
import java.util.Scanner;
/**
Class for the purchase of one kind of item, such as 3
oranges.
Prices are set supermarket style, such as 5 for $1.25.
*/
public class Purchase
{
private String name;
private int groupCount; //Part of a price, like the 2 in //2 for
$1.99.
private double groupPrice; //Part of a price, like the $1.99
// in 2 for $1.99.
private int numberBought; //Number of items bought.
public void setName(String newName)
{
name = newName;
}
/**
Sets price to count pieces for $costForCount.
For example, 2 for $1.99.
*/
public void setPrice(int count, double costForCount)
{
if ((count <= 0) || (costForCount <= 0))
{
System.out.println("Error: Bad parameter in " +
"setPrice.");
System.exit(0);
}
else
{
groupCount = count;
groupPrice = costForCount;
}
}
public void setNumberBought(int number)
{
if (number <= 0)
{
System.out.println("Error: Bad parameter in " +
"setNumberBought.");
System.exit(0);
}
else
numberBought = number;
}
/**
Reads from keyboard the price and number of a purchase.
*/
public void readInput()
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter name of item you are purchasing:");
name = keyboard.nextLine();
System.out.println("Enter price of item as two numbers.");
System.out.println("For example, 3 for $2.99 is entered as");
System.out.println("3 2.99");
System.out.println("Enter price of item as two numbers, " +
"now:");
groupCount = keyboard.nextInt();
groupPrice = keyboard.nextDouble();
while ((groupCount <= 0) || (groupPrice <= 0))
{ //Try again:
System.out.println("Both numbers must " +
"be positive. Try again.");
System.out.println("Enter price of " +
"item as two numbers.");
System.out.println("For example, 3 for " +
"$2.99 is entered as");
System.out.println("3 2.99");
System.out.println(
"Enter price of item as two numbers, now:");
groupCount = keyboard.nextInt();
groupPrice = keyboard.nextDouble();
}
System.out.println("Enter number of items purchased:");
numberBought = keyboard.nextInt();
while (numberBought <= 0)
{ //Try again:
System.out.println("Number must be positive. " +
"Try again.");
System.out.println("Enter number of items purchased:");
numberBought = keyboard.nextInt();
}
}
/**
Displays price and number being purchased.
*/
public void writeOutput()
{
System.out.println(numberBought + " " + name);
System.out.println("at " + groupCount +
" for $" + groupPrice);
}
public String getName()
{
return name;
}
public double getTotalCost()
{
return (groupPrice / groupCount) * numberBought;
}
public double getUnitCost()
{
return groupPrice / groupCount;
}
public int getNumberBought()
{
return numberBought;
}
}
In: Computer Science
Question 1 (Employee): Base Class Information 10 Points
Employee Name: FirstName LastName
Mobile No. 0512345678
Employee Salary: 2000
In: Computer Science
convert -44 to 8-bit sign-magnitude, 1's complement, 2's complement and excess-127.
Please be careful and explain all the steps and details.
In: Computer Science
Python Code
Assignment
1. Place the two provided plaintext files (file_1.txt, file_2.txt) on your desktop.
2. Write a Python program named fun_with_files.py. Save this file to your desktop as well.
3. Have your program write the Current Working Directory to the screen.
4. Have your program open file_1.txt and file_2.txt, read their contents and write their contents into a third file that you will name final.txt .
Note: Ponder the open‐read/write‐close file operation sequence carefully.
5. Ensure your final.txt contains the complete text of file_1.txt followed by the complete text of file_2.txt.
In: Computer Science
Write a program named "cleanDocument.pl" that will do the following:
Below is an example of how the program works:
Calling the Perl file on the command line like so:
$ cleanDocument.pl document.txt bobsled
or
$ cleanDocument.pl $ What file do you want to open? document.txt $ What word do you want to replace? bobsled
If the file looks like below:
$ cat document.txt I like to use my bobsled during the winter. Whenever I bobsled I have a lot of fun.
Then it will be become:
$ cat document.txt I like to use my ------- during the winter. Whenever I ------- I have a lot of fun.
In: Computer Science
You prepare a schedule of your physical exercises for the next fortnight (14 days). You don’t do physical exercise more than once a day. If you have 10 PE sessions planned, explain using the counting principles covered in class how this means you will do PE on consecutive days at least once in the next fortnight.
In: Computer Science
how do you create a list in python to calculate BMI, if you were to want variables like height, weight, BMI, and classification in the list
In: Computer Science
Write a VB program to provide a health analysis. The higher the point total, the less healthy you are. Input will consist of the user's name, age group, smoker status, weight, sex, blood pressure, and cholesterol readings.
Risk Points are assigned as follows:
Age Group
18 or below0 points
19 - 301 point
31 - 602 points
over 604 points
Smoker?
Yes 5 points
No 0 points
Systolic Blood Pressure?
60 - 139 (Normal) 0 points
140 - 159 (Borderline) 2 points
over 159 (High) 4 points
Diastolic Blood Pressure?
40 - 89 (Normal) 0 points
90 - 94 (Borderline) 2 points
over 94 (High) 4 points
LDL (Bad) Cholesterol
< 110 0 points
110 and up 2 points
HDL (Good) Cholesterol
> 1/5 of Total Cholesterol 0 points
≤ 1/5 of Total Cholesterol 2 points
Weight
Female, over 200 lbs 3 points
Female, 150 - 200 lbs 2 points
Female, < 150 lbs 0 points
Male, over 260 lbs 3 points
Male, 200 - 260 lbs 2 points
Male, < 200 lbs 0 points
A sample user-interface design is attached for your use. Note that the user's name, and cholesterol readings are to be entered into textboxes. The sex and smoking status are entered via radio buttons. The weight and blood pressure (systolic and diastolic) are entered via Numeric UpDown controls. The age group is chosen from a combo box control.
The primary button on your form (Analyze Data) will contain all the code to solve this problem in its Click event procedure. You should also make this event procedure executable by simply pressing the ENTER key when the program runs.
Two other buttons...Quit (to pop up a "Farewell Greeting" message box to the user and stop program execution), and a Clear button (to reset all controls back to original values, and move the cursor back to the "Name" textbox), should also have their click event procedures coded.
Finally, a listbox should be included on your form to output the user's results as follows.
Note:
Total Cholesterol is LDL Cholesterol plus HDL Cholesterol.
Health Status is determined as follows:
Total Points Status
0 - 9Good
10 - 18Average
19 - 24Poor
Programming Notes
1. All code to solve this problem will be written in the "Analyze Data" Click event procedure. Therefore, all variables (meaningful, and properly data-typed) will be declared locally to this event procedure. No global (form-level) variables should be used.
2. The following variables and corresponding data types are suggested (You can add prefixes as needed).
Variable Data Type
namestring
weightinteger
HDLinteger
LDLinteger
TotalCholesterolinteger
SystolicBPinteger
DiastolicBPinteger
SmokePointsinteger
WtPointsinteger
AgePointsinteger
LDL Pointsinteger
HDL Pointsinteger
SystolicPointsinteger
DiastolicPointsinteger
TotalPointsinteger
HealthStatusstring
3. Code OPTION STRICT ON at class level to ensure all variables are properly declared in your program.
4. Use IF statements (single, dual, or multiple alternative, as needed) to determine points from Smoking, Systolic blood pressure, Diastolic blood pressure, HDL Cholesterol, LDL Cholesterol, and weight.
For example, suppose you want to assign points for user's smoking status. You would code the following:
Dim SmokePoints As Integer
If radSmokeYes.Checked = True Then
SmokePoints = 5
Else
SmokePoints = 0
End If
5. Use a Select/Case statement to determine points from the age group of the user.
6. Although you set the min/max for 40/300 for Systolic nud (in the Initial Properties Window), use data validation to ensure that user enters an integer between 60 and 200 inclusive into the Systolic Blood Pressure numeric updown control. If not, display an appropriate error message (via titled, descriptive message box), set insertion point back to Systolic Blood Pressure numeric updown control to allow the user to try again and Exit Sub to prevent further execution without having all the "input data.".
7. Do the same as in Step 6 above but set the min/max for 20/200 for Diastolic nud, for the Diastolic Blood Pressure reading, ensuring the user enters an integer between 40 and 120 inclusive.
I just need help with the coding of the project. Any help would be appreciated :)
In: Computer Science
Create an executable bash script named sync. You may find file name pattern matching and the basename command useful. In fact, the sync-skeleton file contains part of the solution to this problem. You may choose to use it anyway you wish. You'll have to create your own test directories (using the mkdir command) and files (using the touch command) to test this script.
You should research the options to the cp command in its main page.
The script takes TWO ARGUMENTS. Let's call them dir1 and dir2. If two arguments are not given display an error message to that effect and exit.
Verify that both given arguments are paths to directories. If one or neither argument is a path to a directory, display an error message to that effect and exit.
If a file exists in dir1 but not in dir2, copy the file from dir1 to dir2 preserving its timestamp. Display a message saying what's being done.
If a file exists in dir2 but not in dir1, copy the file from dir2 to dir1 preserving its timestamp. Display a message saying what's being done.
If a file is in both directories but is newer in dir1 than the file in dir2, copy the file from dir1 to dir2 preserving its timestamp. Display a message saying what's being done.
If a file is in both directories but is newer in dir2 than the file in dir1, copy the file from dir2 to dir1 preserving its timestamp. Display a message saying what's being done.
In: Computer Science
PYTHON PROBLEM:
Goal: Design and implement a Python program to solve the following problem.
Scientists measure an object’s mass in kilograms and weight in newtons. If you know the amount of mass of an object in kilograms, you can calculate its weight in newtons with the following
formula:
[Note: Use or test any random numbers to check whether the weight is heavy, can be lifted or light]
????h? = ???? × 9.8
Write a program that asks the user to enter an object’s mass in kilograms, then calculates its weight in newtons. If the object weighs more than 980 newtons, the program should display the following message
The object is too heavy to be lifted
obviously indicating that it is too heavy to be lifted; otherwise, it should display the message
The object can be lifted
with the obvious meaning. If the object weighs less than 98 newtons, the program must display the following additional message
The object is quite light
1. Write the pseudocode for solving the problem.
2. Write the Python program.
In: Computer Science
Suppose there is only one customer service available in SAMBA Bank in Thursday morning, in every 4 minutes a new customer arrives at the end of waiting line, each customer will need 7 minutes for the service
Write a program to print out the information after the first 60 minutes
(((( data structure course
Programming Language: java
Hint: use the queue concept )))
In: Computer Science
This is to be done using MIPS assembly language.
Display the following menus, ask user to select one item. If 1-3 is selected, display message “item x is selected”, (x is the number of a menu item), display menus again; if 0 is selected, quit from the program.
1. Menu item 1
2. Menu item 2
3. Menu item 3
0. Quit Please select from above menu (1-3) to execute one function. Select 0 to quit
In: Computer Science
create a java class with name ModernArt:
For the first part of the assignment, you will be extending the JApplet class and creating a work of modern using the Graphics class to draw various shapes to the applet window. As part of your masterpiece, you should incorporate the following elements:
You may use more elements than the minimal requirements above, but you must use at least that many. There are unit tests for this question that will determine if you have correctly included the required shapes and colors, but there are no tests to judge your work itself as it is not possible to write unit tests which measure the sheer lack of sophistication typically embodied by so much of modern art.
In: Computer Science
Program in C
Make both a SOURCE AND HEADER FILE WITH FUNCTIONS to run the program. Input data from csv file. Two files. grades.c and grades.h Thank you
data.csv file
Mark Prest,37468,36,113,In Person
Andy Joe,6785923,19,98,Online
Caden Miller,237741,20,70.1,In Person
Luke Jr,2347878,18,45.9,In Online
Ally Rogers,8467483,30,89.99,Online
Maya Jank,5674930,30,90,In Person
Expected output
Name: Mark Prest
ID: 37468
Age: 36
Grade: 113.00
Attending: In Person
Name: Andy Joe
ID: 6785923
Age: 19
Grade: 98.00
Attending: Online
Name: Caden Miller
ID: 237741
Age: 20
Grade: 70.10
Attending: In Person
Name: Luke Jr
ID: 2347878
Age: 18
Grade: 45.90
Attending: Online
Name: Ally Rogers
ID: 8467483
Age: 30
Grade: 89.99
Attending: Online
Name: Maya Jank
NUID: 5674930
Age: 30
Grade: 90.00
Attending: In Person
--------------
2
---- Grade Stats ----
A's: 3
B's: 1
C's: 1
D's: 0
F's: 1
Avg grade: 84.50
---- Enrollment Statistics ----
Number of in person: 5
Number of online: 1
Average age: 25.50
In: Computer Science
Using Java, write the the following code. Only the bold needs to be answered
Here is the driver:
package assign
public class A3Driver {
public static void main(String[] args) {
//Test GSUStudent object
GSUStudentWorker gsw = new GSUStudentWorker("Bunny","Bugs", 2000, 9, 8, 9001234);
gsw.setGPA(3.7);
gsw.setHourlyRate(10.00);
gsw.setTotalHours(30);
System.out.println(gsw);
GSUStudentWorker gsw2 = new GSUStudentWorker("Bunny","Betty", 1999, 9, 8, 9002413);
gsw2.setGPA(4.0);
gsw2.setHourlyRate(10.00);
gsw2.setTotalHours(45);
System.out.println(gsw2);
//Test GSUStoreSupervisor
GSUStoreSupervisor gss = new GSUStoreSupervisor("Duck","Daffy", 1980, 9, 8);
gss.setMonthlyPay(4000);
System.out.println(gss);
//test GSUSuperStudent
GSUSuperStudent gsuper = new GSUSuperStudent("Mouse","Minny", 1990, 9, 8, 9004321);
gsuper.setGPA(3.9);
gsuper.setHourlyRate(10.00);
gsuper.setTotalHours(30);
gsuper.setMonthlyPay(4000);
System.out.println(gsuper);
}
}
1. The Person class
a. Person is an abstract class.
b. All class variables of the Person class must be private.
c.is a class with a single constructor, Person(String lName, String fName, int birthYear, int birthMonth, int birthDay). All arguments of the constructor should be stored as class variables. There should only be getter methods for first and last name variables. There should be no getters or setters forbirthYear, birthMonth, birthDay.
The method computeAge() takes no arguments and returns the person’s computed age (as of today's date) as a string of the form "X years, Y months and Z days". Hint: Use the LocalDate and Period classes.
i. e.g. "21 years, 2 months and 3 days". ii. e.g. "21 years and 3 days".
iii. e.g. "21 years and 2 months". iv. e.g. "21 years".
v. e.g. "2 months and 3 days".
The toString method returns a string comprised of the results of
getFname, getLName and computeAge. E.g.
i. “Bunny Bugs is 19 years and 1 day old”
The equals method returns true if the name and date of birth of this person and the other person are the same, otherwise return false.
2. The Employee interface
a.has a single method, getPay(), which returns a
double
representing the pay earned for the period in dollars and cents.
3. The MonthlyEmployee interface
a. This interface extends the Employee interface.
b. has a single void method, setMonthlyPay(double perMonth),
which
takes a double as an argument. The argument is the amount earned for the month in dollars and cents.
4. The HourlyEmployee interface
a. This interface extends the Employee interface.
b. has a void method, setHourlyRate(double perHour), which takes
a
double as an argument. The argument is the amount earned for
each hour that the employee works.
c. has a void method, setTotalHours(double hoursWorked),
which
takes a double as an argument. The argument is the total hours worked for the week.
Has a final integer variable MAX_WEEKLY_HOURS, which is assigned
a value of 40. This variable is used to assess if the total
hours worked exceeds the mandated hours.
Has a final double variable OVERTIME_RATE, which is assigned a
value of 1.75. This variable is used to compute the pay amount for hours worked that exceeds the mandated hours.
5. The Student class
a. The Student class is abstract.
The Student class extends the Person class.
All (if any) class variables of the Student class must be private.
has an abstract void method, setGPA(double gpa), which takes a double as an argument. The argument is the grade point average of the student using a 4.0 scale.
has an abstract method, getGPA(), which returns a double. The returned value is the grade point average of the student using a 4.0 scale.
6. The GSUStudentWorker class
a. The GSUStudentWorker class extends the Student class and
inherits from the HourlyEmployee interface.
is a class with a single constructor, GSUStudentWorker (String lName, String fName, int birthYear, int birthMonth, int birthday, int eid). There should be a getter and setter for eid, which is the Eagle ID of the student.
All class variables of the Student class must be private.
has a void method, setGPA(double gpa), which takes a double as an argument. The argument is the grade point average of the student using a 4.0 scale.
has a method, getGPA(), which returns a double. The returned value is the grade point average of the student using a 4.0 scale.
f. Has a toString() method that returns a string in the form shown below.
i. Bugs Bunny is 19 years and 15 days old and is a Great Sauce student with a 3.7 GPA who earned $300.00 this week.
7. The GSUStoreSupervisor class
a. The GSUStoreSupervisor class extends the Person class and
inherits from the MonthlyEmployee interface.
is a class with a single constructor, GSUStoreSupervisor(String lName, String fName, int birthYear, int birthMonth, int birthDay).
All class variables of the Student class must be private.
Has a toString() method that returns a string in the form shown below.
i. Daffy Duck is 39 years and 15 days old and is a Great Sauce monthly employee who earned $4000.00 this period.
8. The GSUSuperStudent class
a. GSUSuperStudent has found a way to get paid as a monthly
employee and as a student employee.
The GSUSuperStudent class extends the GSUStudentWorker class and inherits from the MonthlyEmployee interface.
All class variables of the Student class must be private.
Has a toString() method that returns a string in the form shown below.
i. Minny Mouse is 29 years and 15 days old and is a Great Sauce student with a 3.9 GPA who earned $4300.00 this period.
Example output:
__________Example from A3Driver shown below
Bugs Bunny is 19 years and 15 days old and is a Great Sauce student with a 3.7 GPA who earned $300.00 this week.
Betty Bunny is 20 years and 15 days old and is a Great Sauce student with a 4.0 GPA who earned $487.50 this week.
Daffy Duck is 39 years and 15 days old and is a Great Sauce monthly employee who earned $4000.00 this period.
Minny Mouse is 29 years and 15 days old and is a Great Sauce student with a 3.9 GPA who earned $4300.00 this period.
In: Computer Science