USING JAVA
Consider the following methods:
StringBuilder has a method append(). If we run:
StringBuilder s = new StringBuilder();
s.append("abc");
The text in the StringBuilder is now "abc"
Character has static methods toUpperCase() and toLowerCase(), which
convert characters to upper or lower case. If we run Character x =
Character.toUpperCase('c');, x is 'C'.
Character also has a static isAlphabetic() method, which returns
true if a character is an alphabetic character, otherwise returns
false.
You will also need String's charAt() method, which returns the
character at a given index in the String. For example,
"Godzilla".charAt(1) returns 'o'.
Write an application as follows:
public static String getNonAlpha() takes a String as parameter,
builds a StringBuilder consisting of only the nonalphabetic
characters in the String, and returns a String based on the
StringBuilder (eg, sb.toString())
public static String getUpper() takes a String, builds a
StringBuilder of the upper case versions of all the alphabetic
characters in the String, and returns a String based on the
StringBuilder.
Write JUnit tests to verify that the above methods are correct
In: Computer Science
Convert the following decimal numbers to 16-bit 2’s complement binary. Display your result in hexadecimal.
a.3030
b.404
c.5050
d.-5050
e.-20000
Show work with steps
In: Computer Science
Programming languages
Explain orthogonality and its importance.
In: Computer Science
For this activity, you will use a top-down approach to create part of a specification for development of a video game. The game can be any genre or theme that you’d like, but for this exercise, you should choose a single platform (smartphones, iPads, PS4, PC, etc.).
Your “roadmap” should cover the following elements:
Cover the specifications for the software needs and requirements
of the project, presented in a top-down approach (starting with the
“big picture” and breaking down from there into the smaller
requirements). Remember that not all software needs are programming
related. For each need or requirement, propose a software solution.
You don’t have to specify the exact program you would use (for
example, you could say “word processor” instead of “Microsoft
Word”).
You may use any requirement tracking technique or tool you like in
building the requirements list. One program, platform, application,
or piece of software can meet many different needs.
In a separate section, you should describe how you will apply
prototyping techniques and analysis tools to improve the final
product. Again, this discussion should consider what, if any, tools
you will need to implement prototyping.
You can structure the specification however you think best, as long
as it maintains a top-down perspective. Suggested formats include a
flowchart style or a tiered outline.
You can refer to online resources or independent research for this
activity.
In: Computer Science
Create a Java method findLongestPalindrome that takes a Scanner scn as its parameter and returns a String. It returns the longest token from scn that is a palindrome (if one exists) or the empty string (otherwise). (Implementation note: Use the built in isPalindrome method. This method calls for an optimization loop.)
Where the isPalindrome Method takes a String s as a parameter and returns a boolean. It returns true if s reads the same forwards and backwards, i.e., is a Palindrome, and returns false otherwise.
I only need help creating the findLongestPalindrome method, I already have the isPalindrome method.
In: Computer Science
Write a program named StringWorks.java that asks the user to input a line of text from the keyboard. Ask the user if they want their answers case sensitive or not. You output should be
You need to remove punctuation. Use the Character.isLetterOrDigit() method.
Sample output:
Please type in a sentence:
I love java, and Java loves me! That is cool, yes?
Do you want case sensitivity? (y/n):
n
List of words: i love java and java loves me that is cool yes
Sorted alphabetically: and cool i is java java love loves me that yes
Sorted backwards: yes that me loves love java java is i cool and
Shuffled: java that cool is i love and loves me java yes
Without duplicates, sorted alphabetically: and cool i is java love loves me that yes
In: Computer Science
Extend the definition of the class clockType by overloading the pre-increment and post-increment operator function as a member of the class clockType.
Write the definition of the function to overload the post-increment operator for the class clockType as defined in the step above.
Main.cpp
//Program that uses the class clockType.
#include <iostream>
#include "newClock.h"
using namespace std;
int main()
{
clockType myClock(5, 6, 23);
clockType yourClock;
cout << "Line 3: myClock = " << myClock <<
endl;
cout << "Line 4: yourClock = " << yourClock
<< endl;
cout << "Line 5: Enter time in the form "
<< "hrs:mins:secs ";
cin >> myClock;
cout << "Line 7: New value of myClock = "
<< myClock << endl;
++myClock;
cout << "Line 9: After increment myClock is "
<< myClock << endl;
yourClock.setTime(13, 35, 38);
cout << "Line 11: Now yourClock = "
<< yourClock << endl;
if (myClock == yourClock)
cout << "Line 13: myClock and yourClock "
<< "are equal" << endl;
else
cout << "Line 15: myClock and yourClock "
<< "are not equal" << endl;
if (myClock <= yourClock)
cout << "Line 17: myClock is less than "
<< "yourClock" << endl;
else
cout << "Line 19: myClock is not less "
<< "than yourClock" << endl;
cout << "Line 20: Testing post increment operator"
<< endl;
yourClock = myClock++;
cout << "Line 22: myClock = " << myClock <<
endl;
cout << "Line 23: yourClock = " << yourClock
<< endl;
return 0;
}
newClock.cpp
//Implementation file newClock.cpp
#include <iostream>
#include "newClock.h"
using namespace std;
//Overload the pre-increment operator.
//Overload the post-increment operator.
//Overload the equality operator.
bool clockType::operator==(const clockType& otherClock)
const
{
return (hr == otherClock.hr && min == otherClock.min
&& sec == otherClock.sec);
}
//Overload the not equal operator.
bool clockType::operator!=(const clockType& otherClock)
const
{
return (hr != otherClock.hr || min != otherClock.min
|| sec != otherClock.sec);
}
//Overload the less than or equal to operator.
bool clockType::operator<=(const clockType& otherClock)
const
{
return ((hr < otherClock.hr) ||
(hr == otherClock.hr && min < otherClock.min) ||
(hr == otherClock.hr && min == otherClock.min
&&
sec <= otherClock.sec));
}
//Overload the less than operator.
bool clockType::operator<(const clockType& otherClock)
const
{
return ((hr < otherClock.hr) ||
(hr == otherClock.hr && min < otherClock.min) ||
(hr == otherClock.hr && min == otherClock.min
&&
sec < otherClock.sec));
}
//Overload the greater than or equal to operator.
bool clockType::operator>=(const clockType& otherClock)
const
{
return ((hr > otherClock.hr) ||
(hr == otherClock.hr && min > otherClock.min) ||
(hr == otherClock.hr && min == otherClock.min
&&
sec >= otherClock.sec));
}
//Overload the greater than or equal to operator.
bool clockType::operator>(const clockType& otherClock)
const
{
return ((hr > otherClock.hr) ||
(hr == otherClock.hr && min > otherClock.min) ||
(hr == otherClock.hr && min == otherClock.min
&&
sec > otherClock.sec));
}
void clockType::setTime(int hours, int minutes, int
seconds)
{
if (0 <= hours && hours < 24)
hr = hours;
else
hr = 0;
if (0 <= minutes && minutes < 60)
min = minutes;
else
min = 0;
if (0 <= seconds && seconds < 60)
sec = seconds;
else
sec = 0;
}
void clockType::getTime(int& hours, int& minutes,
int& seconds) const
{
hours = hr;
minutes = min;
seconds = sec;
}
//Constructor
clockType::clockType(int hours, int minutes, int seconds)
{
setTime(hours, minutes, seconds);
}
//Overload the stream insertion operator.
ostream& operator<<(ostream& osObject, const
clockType& timeOut)
{
if (timeOut.hr < 10)
osObject << '0';
osObject << timeOut.hr << ':';
if (timeOut.min < 10)
osObject << '0';
osObject << timeOut.min << ':';
if (timeOut.sec < 10)
osObject << '0';
osObject << timeOut.sec;
return osObject; //return the ostream object
}
//overload the stream extraction operator
istream& operator>> (istream& is, clockType&
timeIn)
{
char ch;
is >> timeIn.hr; //Step a
if (timeIn.hr < 0 || timeIn.hr >= 24) //Step a
timeIn.hr = 0;
is.get(ch); //Read and discard :. Step b
is >> timeIn.min; //Step c
if (timeIn.min < 0 || timeIn.min >= 60) //Step c
timeIn.min = 0;
is.get(ch); //Read and discard :. Step d
is >> timeIn.sec; //Step e
if (timeIn.sec < 0 || timeIn.sec >= 60) //Step e
timeIn.sec = 0;
return is; //Step f
}
newClock.h
//Header file newClock.h
#ifndef H_newClock
#define H_newClock
#include <iostream>
using namespace std;
class clockType
{
friend ostream& operator<<(ostream&, const
clockType&);
friend istream& operator>>(istream&,
clockType&);
public:
void setTime(int hours, int minutes, int seconds);
//Function to set the member variables hr, min, and sec.
//Postcondition: hr = hours; min = minutes; sec = seconds
void getTime(int& hours, int& minutes, int& seconds)
const;
//Function to return the time.
//Postcondition: hours = hr; minutes = min; seconds = sec
clockType operator++();
//Overload the pre-increment operator.
//Postcondition: The time is incremented by one second.
clockType operator++(int);
// Overload the post increment operator
// Postcondition: Time is incremented by one
second.
bool operator==(const clockType& otherClock) const;
//Overload the equality operator.
//Postcondition: Returns true if the time of this clock
// is equal to the time of otherClock,
// otherwise it returns false.
bool operator!=(const clockType& otherClock) const;
//Overload the not equal operator.
//Postcondition: Returns true if the time of this clock
// is not equal to the time of otherClock,
// otherwise it returns false.
bool operator<=(const clockType& otherClock) const;
//Overload the less than or equal to operator.
//Postcondition: Returns true if the time of this clock
// is less than or equal to the time of
// otherClock, otherwise it returns false.
bool operator<(const clockType& otherClock) const;
//Overload the less than operator.
//Postcondition: Returns true if the time of this clock
// is less than the time of otherClock,
// otherwise it returns false.
bool operator>=(const clockType& otherClock) const;
//Overload the greater than or equal to operator.
//Postcondition: Returns true if the time of this clock
// is greater than or equal to the time of
// otherClock, otherwise it returns false.
bool operator>(const clockType& otherClock) const;
//Overload the greater than operator.
//Postcondition: Returns true if the time of this clock
// is greater than the time of otherClock,
// otherwise it returns false.
clockType(int hours = 0, int minutes = 0, int seconds =
0);
//Constructor to initialize the object with the values
//specified by the user. If no values are specified,
//the default values are assumed.
//Postcondition: hr = hours; min = minutes;
// sec = seconds;
private:
int hr; //variable to store the hours
int min; //variable to store the minutes
int sec; //variable to store the seconds
};
#endif
In: Computer Science
Hello! I'm trying to work on a python lab in my class, and we basically have to make this method
play_interactive
Now for the fun bit. The function play_interactive will take just one argument --- the length of patterns to use as keys in the dictionary --- and will start an interactive game session, reading either '1' or '2' from the player as guesses, using the functions you wrote above and producing output as shown in the sample game session at the beginning of this writeup. If the player types in any other input (besides '1' or '2'), the game should terminate.
Hint: the input function can be used to read input from the user as a string.
My code so far looks like this, I have the basic loop down and
working, but my guesses list to retain the guesses for this method
isn't updating
def play_interactive(pattern_length=4):
while True:
x = input()
intX = int(x)
guesses = ([])
if(intX == 1 or intX == 2):
guesses.append(intX)
print(len(guesses))
else:
print("Finished")
break
Any help would be appreciated! Thank you so much
In: Computer Science
using C program
Assignment
Write a computer program that converts a time provided in hours, minutes, and seconds to seconds
Functional requirements
Nonfunctional requirements
Sample run
4 hours, 13 minutes and 20 seconds is equal to 15200 seconds. 8 hours, 0 minutes and 0 seconds is equal to 28800 seconds. 1 hours, 30 minutes and 0 seconds is equal to 5400 seconds.
Grading
This assignment will be graded according to the programming grading rubric.
Due date
The assignment is due by the 11:59pm on September 20, 2019.
Requested files
time_to_sec.c
/*
* time_to_sec.c
*
* Created on: Jul 20, 2016
* Author: leune
*/
// appropriate #include statements
/* Convert a time interval specified in hours, minutes and seconds to
* seconds.
* Parameters:
* hours, minutes, seconds: input time elements
* Preconditions:
* 0 <= minutes < 60
* 0 <= seconds < 60
* Return:
* number of seconds in the interval
*/
unsigned int time_to_sec(unsigned int hours, unsigned int minutes,
unsigned int seconds) {
// complete this
}
/* Print a formatted representation of the calculation
* Parameters:
* hours, minutes, seconds: input time elements
* Postcondition:
* Function will write the calculation to standard output.
*/
void format_seconds(unsigned int hours, unsigned int minutes,
unsigned int seconds) {
// complete this
}
int main(void) {
format_seconds(4, 13, 20);
format_seconds(8, 0, 0);
format_seconds(1, 30, 0);
}
In: Computer Science
Create a 1- to 2-page IRP Microsoft Word for an IT organization. In your plan, ensure you:
In: Computer Science
C++
Given two finite sets, list all elements in the Cartesian product of these two sets.
In: Computer Science
Computer Science (C and Assembly Languages)
• Assume there are two 32-bit variables in RAM memory called In and Out. Write C code that sets Out equal to In plus 2.
• Assume there are two 32-bit variables in RAM memory called In and Out. Write assembly code that sets Out equal to In plus 2.
• What are the three stack rules?
• Assume B1 is a 32-bit unsigned global variable. We wish to write code that decrements B1 with the exception that it will not decrement if B1 is already 0. Draw a flowchart of the process. Write the code in both C and assembly.
• Assume G1 is a 32-bit unsigned global
variable. We wish to write code that increments G1 if G1 is less
than 20. Draw a flowchart of the process. Write the code in both C
and assembly.
• Develop the pseudocode and the flowchart for a program that finds the sum of 5 numbers.
• Comment each line of the ARM Assembly
language to explain what the code does. [4 pts]
start
MOV r0, #15
MOV r1, #8
ADD r0, r0, r1
MOV r4, #0x300
• Comment each line of the C language
to explain what the code does. [4 pts]
#include <stdio.h>
int main()
{
int number;
printf("Enter an integer: ");
scanf("%d", &number);
if (number < 0)
{
printf("You entered %d.\n", number);
}
printf("The if statement is easy.");
return 0;
}
In: Computer Science
Python
Albert Einstein famously said that compound interest is the 8th wonder of the world. Hopefully, all of you have had a finance course to teach you why it is so much more powerful than simple interest, which we programmed in class. If you are unfamiliar with compound interest, google it (note - if you google "compound interest for dummies" you will get a MUCH simpler explanation of how it works, without greek function notations!!)
Your assignment this week is to use a for loop, with the range() function to figure out compound interest on a deposit. You will ask the user for the amount of the deposit, the interest rate and the number of years and tell her how much money she has after that amount of time. Be sure to use the isnumeric function, and do NOT use an exponent to figure out compound interest - use a loop!
In: Computer Science
Q4: Write a program that takes as input two opposite corners of a rectangle: (x1,y1) and (x2,y2). Finally, the user is prompted for the coordinates of a third point (x,y). The program should print Boolean value True or False based on whether the point (x,y) lies inside the rectangle. If the point lies on the rectangle, the program should print False.
Program should work irrespective of the order in which the user inputs the opposite coordinates. program user should be able to input coordinates in all possible orders.
- Right upper coordinate first and then left lower coordinate
- Left lower coordinate first and then right upper coordinate
- Left upper coordinate first and then right lower coordinate
- Right lower coordinate first and then left upper coordinate
In: Computer Science
I need to update this java program to take input about each employee from a file and write their information and salary/pay information to a file. use input file
payroll.txt
Kevin
Yang
60
20
Trey
Adams
30
15
Rick
Johnson
45
10
Cynthia
Wheeler
55
11.50
Sarah
Davis
24
10
Muhammad
Rabish
66
12
Dale
Allen
11
18
Andrew
Jimenez
80
15
import java.util.Scanner;
public class SalaryCalcLoop
{
double Rpay = 0, Opay = 0;
void calPay(double hours, double rate) {
if (hours <= 40)
{
Rpay = hours * rate;
Opay = 0;
}
else
{
double Rhr, Ohr;
Rhr = 40;
Ohr = hours - Rhr;
Rpay = Rhr * rate;
Opay = Ohr * (1.5 * rate);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String name;
int shift = 0;
Double rate, hours;
System.out.println("Pay Calculator");
String ch = "";
do
{
System.out.println("Enter Your Name");
name = sc.next();
System.out.println("Enter Your Shift, Enter 0 for Day, Enterv1 for
Night");
System.out.println("0=Day, 1= Night");
shift=sc.nextInt();
System.out.println("Enter Number of Hours Worked");
hours = sc.nextDouble();
System.out.println("Enter Hourly Pay");
rate = sc.nextDouble();
SalaryCalc c = new SalaryCalc();
c.calPay(hours, rate);
Double Tpay = c.Rpay + c.Opay;
System.out.println();
System.out.println("Calculate Pay");
System.out.println("Employee Name: " + name);
System.out.println("Employee Regular Pay: " + c.Rpay);
System.out.println("Employee Overtime Pay: " + c.Opay);
System.out.println("Employee Total Pay: " + Tpay);
if (shift == 0)
{
System.out.println("Employee PayPeriod is Friday");
}
else
{
System.out.println("Employee PayPeriod is Saturday");
}
System.out.println("Press Y to continue. Press any other key to
exit ");
ch=sc.next();
}
while(ch.equalsIgnoreCase("y"));
}
}
Saturday"); } System.out.println("Press Y to continue. Press any other key to exit "); ch=sc.next(); } while(ch.equalsIgnoreCase("y")); } }
In: Computer Science