Questions
Assignment 4, Fraction Comparable Instructions For this assignment, you will be updating the Fraction class from...

Assignment 4, Fraction Comparable

Instructions

For this assignment, you will be updating the Fraction class from Assignment 1. To get started, you can either make a copy of your Assignment 1 Fraction.java or download the Fraction.java template at the bottom of this assignment.

You will need to update Fraction so that it implements the Comparable interface. This will require adding an implements statement to the class declaration as well as the compareTo method. You will also add a simplify method which reduces a fraction to its lowest terms and, to help you with this, a static method gcd which finds the greatest common divisor of two integers.

The requirements of the methods to be added are as follows:

  • int compareTo(Object other): Return -1 if this fraction is smaller than the fraction other, return 0 if this fraction is equal to the fraction other, and return 1 if this fraction is greater than the fraction other. Hint: To compare the two fractions, it will help to first convert them to fractions with a common (equal) denominator.
  • static int gcd(int a, int b): return the greatest common divisor of a and b. To find the gcd of two numbers there are several possible algorithms. One of these was showcased in term 1 lesson 19 - More Loops.
  • void simplify(): reduce the fraction to its simplest possible form: e.g. the fraction 12/18 should be reduced to 2/3. The static method gcd provides a useful helper for this method.

When you have successfully written your simplify method, you should add calls to this method at the end of the Fraction(int n, int d) constructor and the add method. This will ensure that fractions are always stored in their simplest possible form.

To test your code, download the runner class student_fraction_runner.java (Links to an external site.) into the same folder that holds your Fraction.java. Execute the method student_fraction_runner.main, and verify that the output matches the sample run listed below. Remember to change the runner to test with other values to make sure your program fits all the requirements. We will use a similar but different runner to grade the program.

When you are ready, paste your entire Fraction.java class in the box below, click run to test the output, and click submit when you are satisfied with your results.

Note: once you have completely finished the assignment feel free to add more methods (e.g. multiply) or extend the functionality of your Fraction class to include, for example, negative fractions. Make sure you submit your assignment first before making any changes like this.

Sample Run

Fraction 1: 4/5
Fraction 2: 3/2
Fraction 3: 4/5

Compare fraction 1 to fraction 2: -1
Compare fraction 2 to fraction 1: 1

Compare fraction 1 to fraction 3: 0
Compare fraction 3 to fraction 1: 0

Compare fraction 2 to fraction 3: 1
Compare fraction 3 to fraction 2: -1

Milestones

As you work on this assignment, you can use the milestones below to inform your development process:

Milestone 1: Write the static gcd method and test this by calling it on pairs of integers from another class.

Milestone 2: Write the simplify method (you will probably find it useful to call the gcd method). Add calls to this method at the end of the constructor and the add method.

Milestone 3: Implement the Comparable interface and write the method compareTo. Download the runner file and ensure the results are as expected.

In: Computer Science

Site map for your e-commerce site. How many webpages this site has? What’s the name of...

Site map for your e-commerce site. How many webpages this site has? What’s the name of each page? (You may use a rectangle box to represent a page).

In: Computer Science

I'm trying to Generate number every 3 seconds and update the currenet number.I'm able to generate...

I'm trying to Generate number every 3 seconds and update the currenet number.I'm able to generate number every 3 seconds; However, the current number isn't update. I apperciate any help.

public static void main(String[] args) {
    
    Runnable helloRunnable = new Runnable() {
        public void run() {
      
            CurrentNum=task2();
        
            System.out.println("Result    ====    "+CurrentNum);

        }
    };

    ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
    executor.scheduleAtFixedRate(helloRunnable, 0, 3, TimeUnit.SECONDS);
    
     System.out.println("CurrentNum    ====    "+CurrentNum);
     
    
}
public static int task2() {
    // create instance of Random class 
    Random rand = new Random(); 

    // Generate random integers in range 0 to 999 
    int rand_int1 = rand.nextInt(1000); 
    
    return rand_int1;
}

outPut:

    CurrentNum    ====    0
    Result    ====    631
    Result    ====    789
    Result    ====    958

I want the output tobe:

    Result    ====    631
    CurrentNum ====    631
    Result    ====    789
    CurrentNum====    789

In: Computer Science

Python previous function: wrtie a function that takes one argument. The function returns True if the...

Python

previous function:
wrtie a function that takes one argument. The function returns True if the number more than or equal to 0, otherwise it returns False.

write a function for main
create a variable and assign its value to true.

uses a while loop which runs as ling as the variable of the previous step is True, to get a number from the user

and if passing that nimber to the previous function, results in a True value returned, then add that number to a running sum. Otherwide make the loop stop without using break.

After the loops stop, print the running sum of all the balues the user entered

In: Computer Science

Question: Use backtracking algorithm design to write Java code to solve the subset problem: given a...

Question: Use backtracking algorithm design to write Java code to solve the subset problem: given a set of distinct integers, return all possible subsets. for example, input: new int[] {1,2,3}

output: [], [3], [2], [2,3], [1], [1,3], [1,2], [1,2,3]

In: Computer Science

Visual Basic program in visual studio please Write a function that checks whether a string has...

Visual Basic program in visual studio please

Write a function that checks whether a string has a number based. Use what we learned about Asc to complete the following:

Function CheckLength (S As String) As Boolean

‘add a do loop to start at first character

‘if Ascii current character is between Asc (“0”) and Asc (“9”)

‘then we have a hit Return True

‘else check the next character

‘if loop is over, that means no hit was found Return False

End Function

Use this function in an application that allows the user to enter the string/text that should be tested by your CheckLength function.

Please submit your completed application.

In: Computer Science

Dirac's Theorem states that "A simple graph with n vertices (n >= 3) is Hamiltonian if...

Dirac's Theorem states that "A simple graph with n vertices (n >= 3) is Hamiltonian if every vertex has degree n / 2 or greater". Show that K n,n is Hamiltonian for all n >= 3

In: Computer Science

2. Compare and compare the matrix multiplication algorithm and the Floyd-Warshall algorithm to find all pairs...

2. Compare and compare the matrix multiplication algorithm and the Floyd-Warshall algorithm to find all pairs shortest paths from the perspective below.

  1. greedy vs dynamic programming
  2. recurrence relation
  3. relaxation process
  4. time & space complexity

In: Computer Science

You are the network administrator for your organization. Your DHCP server (Server1) has a scope of...

You are the network administrator for your organization. Your DHCP server (Server1) has a scope of 10.10.16.0 to 10.10.16.254 with a subnet mask of /20.

How would the Get-DhcpServerv4Scope ensure that all of the client computers obtain an IP address from Server1.

In: Computer Science

python3 Let x0,...,xn−1 be n numbers stored in the list x. The median of x, denoted...

python3

Let x0,...,xn−1 be n numbers stored in the list x. The median of x, denoted median(x) is the “middle”-value of the numbers in x in the sense that half of the numbers in x are less than the median and the other half of the numbers in x are greater than the median. Let y denote a copy of x sorted in ascending order. Then median(x)=(y[n+1 2 −1] if n is oddy [n 2−1]+y[n 2] 2 if n is even. Complete the function my_median with the following specifications: • It that takes in one parameter, x, which is a list of numbers. • It returns median(x). • Do not alter x. Evaluating your function my_median(x) should not change the value of the list x. • Do not use Python’s built-in median function.

In: Computer Science

tcp 16115

tcp 16115

In: Computer Science

#include <iostream> #include <fstream> #include <vector> #include <string> using namespace std; // Define a Person class,...

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;

// Define a Person class, including age, gender, and yearlyIncome.
class Person {
public:
Person();
void Print();
void SetData(int a); // FIXME Also set gender and yearly income
void SetGender(string gender);
void SetIncome(int income);
int GetAge();
string GetGender();
int GetIncome();

private:
int age;
string gender;
int yearlyIncome;
};

// Constructor for the Person class.
Person::Person() {
age = 0;
gender = "default";
yearlyIncome = 0;
return;
}

// Print the Person class.
void Person::Print() {
cout << "Age = " << this->age
<< ", gender = " << this->gender
<< ", yearly income = " << this->yearlyIncome
<< endl;
return;
}

// Set the age, gender, and yearlyIncome of a Person.
void Person::SetData(int a) { // FIXME Also set gender and yearly income
this->age = a;
return;
}

void Person::SetGender(string gender){
this->gender = gender;
}

void Person::SetIncome(int income){
this->yearlyIncome = income;
}
// Get the age of a Person.
int Person::GetAge() {
return this->age;
}

string Person::GetGender(){
return this->gender;
}

int Person::GetIncome() {
return this->yearlyIncome;
}

// Get a filename from program arguments, then make a Person for each line in the file.
bool ReadPeopleFromFile(int argc, char* argv[], vector<Person> &people) {
Person tmpPrsn;
ifstream inFS;
int tmpAge = 0;
string tmpGender = "";
int tmpYI = 0;

if (argc != 2) {
cout << "\nUsage: [EXECUTABLE FILE] [TEXT DATA FILE], e.g. myprog.exe dev_people.txt" << endl;
return true; // indicates error
}

cout << "Opening file " << argv[1] << ".\n";
inFS.open(argv[1]); // Try to open file
if (!inFS.is_open()) {
cout << "Could not open file " << argv[1] << ".\n";
return true; // indicates error
}

while (!inFS.eof()) {
inFS >> tmpAge;
inFS >> tmpGender;
inFS >> tmpYI;
tmpPrsn.SetData(tmpAge); // FIXME Also set gender and yearly income
tmpPrsn.SetGender(tmpGender);
tmpPrsn.SetIncome(tmpYI);
tmpPrsn.Print();
people.push_back(tmpPrsn);
}
inFS.close();
cout << "Finished reading file." << endl;

return false; // indicates no error
}

// Ask user to enter age range.
void GetUserInput(int &ageLowerRange, int &ageUpperRange, string &gender, int &yILowerIncome,int &yIHigherIncome) {
cout<<"\nEnter lower range of age: ";
cin >> ageLowerRange;

cout << "Enter upper range of age: ";
cin >> ageUpperRange;

cout << "Enter the gender: ";
cin >> gender;

cout << "Enter the lower range of yearlyIncome: ";
cin >> yILowerIncome;

cout << "Enter the higher range of yearlyIncome: ";
cin >> yIHigherIncome;

return;
}

// Return people within the given age range.
vector<Person> GetPeopleInAgeRange(vector<Person> ppl, int lowerRange, int upperRange) {
unsigned int i = 0;

vector<Person> pplInAgeRange;
int age = 0;
for (i = 0; i < ppl.size(); ++i) {
age = ppl.at(i).GetAge();
if ((age >= lowerRange) && (age <= upperRange)) {
pplInAgeRange.push_back(ppl.at(i));
}
}

return pplInAgeRange;
}

// Return people with same Gender.
vector<Person> GetPeopleWithSpecificGender(vector<Person> ptntlCstmrs,string gender){
vector<Person> pplWithSameGender;
string gndr;
for (int i=0;i<ptntlCstmrs.size();i++){
gndr = ptntlCstmrs.at(i).GetGender();
if (gndr.compare(gender) == 0){
pplWithSameGender.push_back(ptntlCstmrs.at(i));
}
}
return pplWithSameGender;
}

// Return people within the given income range.
vector<Person> GetPeopleInIncomeRange(vector<Person> ptntlCstmrs,int lowerRange, int higherRange){
vector<Person> pplInIncomeRange;
int range = 0;
for (int i=0;i<ptntlCstmrs.size();i++){
range = ptntlCstmrs.at(i).GetIncome();
cout << range << endl;
if ((range >= lowerRange) && (range <= higherRange)){
pplInIncomeRange.push_back(ptntlCstmrs.at(i));
}
}
return pplInIncomeRange;
}

int main(int argc, char* argv[]) {
vector<Person> ptntlCstmrs;
bool hadError = false;
int ageLowerRange = 0;
int ageUpperRange = 0;
string gender;
int yILowerIncome = 0;
int yIHigherIncome = 0;

hadError = ReadPeopleFromFile(argc, argv, ptntlCstmrs);
if( hadError ) {
return 1; // indicates error
}

GetUserInput(ageLowerRange, ageUpperRange, gender, yILowerIncome, yIHigherIncome );
ptntlCstmrs = GetPeopleInAgeRange(ptntlCstmrs, ageLowerRange, ageUpperRange);
ptntlCstmrs = GetPeopleWithSpecificGender(ptntlCstmrs,gender);
ptntlCstmrs = GetPeopleInIncomeRange(ptntlCstmrs,yILowerIncome,yIHigherIncome);
cout << "\nNumber of potential customers = "<<ptntlCstmrs.size() << endl;

return 0;
}

this is my code for my assignment, my professor said i'm missing

Based on that rubric, it looks like the code is missing two things:
* Person class in separate files

* Output persons with user-entered gender works for "any"

can someone help me with this?

In: Computer Science

Need someone to fix my code: based on this version, give me another version without adding...

Need someone to fix my code: based on this version, give me another version without adding struct student.

#include <iostream>
#include <iomanip>
using namespace std;

struct student
{
double firstQuizz;
double secondQuizz;
double midTerm;
double finalTerm;
double overallScore;
char gradeLetter;
string name;
};

void getStudentData(student &s);
void calcPercentage(student &s);
void gradeLetter(student &s);
void display(student s[],int n);

int main()
{

int n;
cout<<"enter the number of students"<<endl;
cin>>n;
struct student students[n];

int i; struct student istudent;
for(i=0;i<n;i++)
{
   cout<<":: Student#"<<(i+1)<<" ::"<<endl;
getStudentData(students[i]);
}

for(i=0;i<n;i++)
{
   calcPercentage(students[i]);
   gradeLetter(students[i]);
}

display(students,n);

return 0;
}

void getStudentData(student &s)
{
   cin.ignore();
   cout<<"Student name?";
getline(cin,s.name);
cout<<"Enter marks in first quizz :";
cin>>s.firstQuizz;
cout<<"Enter marks in second quizz :";
cin>>s.secondQuizz;
cout<<"Enter marks in mid term :";
cin>>s.midTerm;
cout<<"Enter marks in final term :";
cin>>s.finalTerm;
}

Programming language: C++
void calcPercentage(student &s)
{
double overAllScore = (s.firstQuizz + s.secondQuizz)*5 * 0.25 + s.midTerm * 0.25 + s.finalTerm* 0.50;
s.overallScore=overAllScore;
}
void gradeLetter(student &s)
{
   double average=s.overallScore;
   char gradeLetter;
  
if (average >= 90 && average<=100)
gradeLetter = 'A';
else if (average >= 80 && average < 90)
gradeLetter = 'B';
else if (average >= 70 && average < 80)
gradeLetter = 'C';
else if (average >= 60 && average < 70)
gradeLetter = 'D';
else if (average < 60)
gradeLetter = 'F';

s.gradeLetter=gradeLetter;
}
void display(student s[],int n)
{
       //setting the precision to two decimal places
   std::cout << std::setprecision(2) << std::fixed;

   cout<<setw(15)<<left<<"Name"<<setw(15)<<right<<"Overall Score"<<setw(15)<<right<<"Grade Letter"<<endl;
   cout<<setw(15)<<left<<"----"<<setw(15)<<right<<"-------------"<<setw(15)<<right<<"------------"<<endl;
   for(int i=0;i<n;i++)
   {
   cout<<setw(15)<<left<<s[i].name<<setw(15)<<right<<s[i].overallScore<<setw(15)<<right<<s[i].gradeLetter<<endl;
   }
  
}

Programming language: C++

Requirement: based on this version, give me another version without adding struct student.

In: Computer Science

use the following codes and change  In the main-content div, for content, add three select dropdowns separated...

use the following codes and change  In the main-content div, for content, add three select dropdowns separated by line breaks. One will have ID changeFont, one will have ID bgColor and the third will have ID resizeDiv. For changeFont, the options should be: [CHANGE FONT SIZE] value blank, 8 pt. value 8t, 10 pt. value 10pt, 12 pt. value 12pt, 14 pt. value 14pt, and 16 pt. value 16pt. For bgColor the options should be [CHANGE BG COLOR] value blank, black value #00000, red value #ff0000, green value #00ff00, blue value #0000ff, white value #ffffff. For resizeDiv the options should be [RESIZE MAIN DIV] value blank, 150px value 150px, 250px value 250px, 350px value 350px, 450px value 450px, 550px value 550px, 650px value 650px.

3. Write three functions: changeFont(), changeBGColor(), and resizeDiv(). changeFont will change the font size of the main div based on what the user selects, or the default of 12pt if the user selects [CHANGE FONT SIZE]. changeBGColor will change the background color to the color selected, and ALSO set the font color to white if the selection is black, red, or blue, and font color will be black if white or green. The default for changeBGColor will be white with black font. resizeDiv will resize the main content div to the PX selected, or 85% if nothing is selected. HINT: onchange.

HTML

<head>

<!-- title for web page -->

<title>jen's CISS221 JavaScript Template</title>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- <link> is used for external stylesheet -->

<link href="JStemplate.css" rel="stylesheet">

</head>

<body>

<div id="banner" class="banner">Mat's Javascript Template</div>

<div id="left-content" class="left-content">Left content</div>

<div id="main-content" class="main-content">This is Main are</div>

<div id="footer" class="footer">&copy;2019 Mat cantor for CISS 221</div>

</body>

</html>

CSS

/* style rule for body */

body{
background-color: #66ff66;

}

/* style rule for banner */

#banner{
padding-top:20pt;
Padding-bottom:20pt;
color:#141414;
background-color:#cccc33;
text-align: center;
font-size: 18pt;
border: 2px solid green ;
padding: 20px;

}

/* style rule for left-content */

#left-content{
background-color: #000000 ;
text-align: center;
height: 45pt;
Width:50pt;
padding-top: 100pt;

color :#cccc33;
float:left;
border: 2px solid green ;
padding: 65px;
}

/* style rule for main-content */

#main-content{
background-color:#ffffff;
text-align: center;

padding-top:120pt;
Padding-bottom:10pt;
color :#cccc33;
border: 2px solid green;
}

/* style rule for footer */

#footer {
background-color: #cccc33;
text-align: center;
font-size: 8pt;
padding-top:10pt;
Padding-bottom:15pt;
border: 2px solid green ;
padding: 20px;
clear:both

}

In: Computer Science

1. ONLY VISUAL STUDIO C# CONSOLE APPLIACTION (NO JAVA CODING) In this part of the assignment,...

1. ONLY VISUAL STUDIO C# CONSOLE APPLIACTION

(NO JAVA CODING)

In this part of the assignment, you are required to create a C# Console Application project. The project name should be A3<FirstName><LastName>P1. For example a student with first name John and Last name Smith would name the project A3JohnSmithP1.


You are creating a console based math program. This program will be shown as a menu with several options. The menu should be created with a do loop.
The first option is to display a list of even numbers beginning at 0. Once this option is selected, the program asks the user for the number of even numbers to display. After the user provides this input, all the values should be displayed at once. This option should be created using a "for" loop.


The second option is to display a sequence of perfect squares. The program should begin by printing the square of 1, and ask the user if they to continue or stop and return to the original menu. If the user does not want to quit, the next square is printed. This continues until the user wishes to end the sequence. This option should be created using a while loop.


The third option is to exit the program. Any invalid option entered by the user should prompt the menu to reappear and ask the same three options.
Any numeric entry by the user should not crash if the user enters a string.
Your program must:
a. Use the appropriate loop for each segment. [3 marks]
b. Encapsulate the logic of options 1 and 2 each within their own method. [4 marks]
c. The functionality of the menu is correct as described. [3 marks]
d. Proper error handling. [3 marks]
e. Adhere to coding standards as described by the course. Marks will be taken off wherever coding standards are not followed.

In: Computer Science