Need someone to rewrite this code to work in the same way:
int testScore; //Numeric test score
String input; //To hold the user's input
// Get the numeric test score.
input = JOptionPane.showInputDialog("Enter your numeric test score and I will tell you the grade: ");
testScore = Integer.parseInt(input);
//Display the grade.
if (testScore < 60)
JOptionPane.showMessageDialog(null, "Your score of "+testScore+" is an F.");
else if (testScore < 70)
JOptionPane.showMessageDialog(null, "Your score of "+testScore+" is a D.");
else if (testScore < 80)
JOptionPane.showMessageDialog(null, "Your score of "+testScore+" is a C.");
else if (testScore < 90)
JOptionPane.showMessageDialog(null, "Your score of "+testScore+"e is a B.");
else
JOptionPane.showMessageDialog(null, "Your score of "+testScore+" is an A.");
}
}
Need ans asap......
In: Computer Science
I was wondering if you can tell me if the following code is correct and if its not can it be fixed so it does not have any syntax errors.
Client one
/**
* Maintains information on an insurance client.
*
* @author Doyt Perry/<add your name here>
* @version Fall 2019
*/
public class Client
{
// instance variables
private String lastName;
private String firstName;
private int age;
private int height;
private int weight;
/**
* First constructor for objects of class Client.
*/
public Client()
{
// initialize all instance variables to placeholder values
this.lastName = "last name";
this.firstName = "first name";
this.age = 0;
this.height = 1;
this.weight = 1;
}
/**
* Second constructor for objects of class Client.
*
*
* Create a client object using explicit parameters to specify
* values for corresponding instance fields.
*
* @param inLastName last Name of client
* @param inFirstName first Name of client
* @param inAge age of client
* @param inHeight height of client
* @param inWeight weight of client
*/
public Client(String inLastName, String inFirstName, int
inAge,
int inHeight, int inWeight)
{
// initialize instance variables
// using values passed in as parameters
this.lastName = inLastName;
this.firstName = inFirstName;
this.age = inAge;
this.height = inHeight;
this.weight = inHeight;
}
/**
* Update the last name of the client.
*
* @param inLastName last name of the client.
*/
public void setLastName(String inLastName)
{
// Set the last name instance variable to parameter
this.lastName = inLastName;
}
/**
* Return the last name of the client.
*
* @return String last name.
*/
public String getLastName()
{
// return the value of the last name instance variable
return this.lastName;
}
/**
* Update the first name.
*
* @param inFirstName first name of the client.
*/
public void setFirstName(String inFirstName)
{
// Set the first name instance variable to parameter.
// REPLACE this comment with your code
}
/**
* Return the first name of the client.
*
* @return String first name.
*/
public String getFirstName;
//return "not cor";
/**
* Update the age of the client.
*
* @param inAge age of the client.
*/
public void setAge(int inAge)
{
// Set the age instance variable to the parameter
this.age = inAge;
}
/**
* Return the age of the client.
*
* @return int first name.
*/
public int getAge()
{
// return the value of the first age instance variable.
return this.age;
}
/**
* Update the height of the client.
*
* @param inHeight height of the client.
*/
public void setHeight(int inHeight)
{
// Set the height instance variable to the parameter
this.height = inHeight;
}
/**
* Return the height of the client.
*
* @return int height of client.
*/
public int getHeight()
{
// return the value of the height instance variable.
return this.height;
}
/**
* Update the weight of the client.
*
* @param inWeight weight of the client.
*/
public void setWeight(int inWeight)
{
// replace this comment with your code
}
/**
* Return the weight of the client.
*
* @return int weight of client.
*/
public int getWeight()
{
// replace this comment & return statement with your code
return -1;
}
/**
* Calculate the BMI of the client.
*
* @return double BMI of client.
*/
public double calcBMI()
{
// return the result of calculating the BMI.
// Refer to "Common Error 4.1" on page 142 in the textbook for more
info
// if WebCat flags the following calculation as an error.
return (704 * this.weight) / this.height * this.height;
}
/**
* Display the client information.
*
* @return String formatted client informatin.
*
* <pre>
* The label should be printed in the format:
*
* last name, first name
* Age: 99
* BMI: 99.999
* </pre>
*/
public String toString()
{
// initialize the variable that will hold the output string
String output = "";
// put the name in lastname, firstname format
output = output + this.lastName + this.firstName + "\n";
// include the client age
output = output + "Age " + this.age + "\n";
// include the email address
output = output + "BMI " + this.calcBMI() + "\n";
// return the output string
return output;
}
}
In: Computer Science
Using C++ Design a class named PersonData with the following member variables:
and at a minimum the following member functions:
Write a NewPersonData function. This is a stand-alone function that you can use in your main to generates a new PersonData object from user input (i.e. internally prompting and retrieving the values necessary to generate a person)
In: Computer Science
I need to write this program in Python. Write a program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The tabular format of the result should include rows for all temperatures between 70 and 270 degrees Celsius that are multiples of 10 degrees Celsius (check the sample below). Include appropriate headings on your columns. The formula for converting between degrees Celsius and degrees Fahrenheit is as follow F=(9/5C) +32
Celsius | Fahrenheit |
---|---|
70 | 158 |
80 | 176 |
90 | 194 |
100 | 212 |
.... | ... |
... | ... |
270 | 518 |
In: Computer Science
PART A - STACKS
To complete this assignment:
Please study the code posted below.
Please rewrite the code implementing a template class using a linked list instead of an array. Note: The functionality should remain the same
***************************************************************************************************************
/**
* Stack implementation using array in C/procedural
language.
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
//#include <climits> // For INT_MIN
#define SIZE 100
using namespace std;
/// Create a stack with capacity of 100
elements
int stack[SIZE];
/// Initially stack is empty
int top = -1;
/** Function declaration to perform push and pop on stack
*/
void push(int element);
int pop();
void display();
int main()
{
int choice, data;
while(1)
{
/* Menu */
cout
<<"------------------------------------\n";
cout <<" STACK IMPLEMENTATION PROGRAM
\n";
cout
<<"------------------------------------\n";
cout <<"1. Push\n";
cout <<"2. Pop\n";
cout <<"3. Size\n";
cout <<"4. Print Stack\n";
cout <<"5. Exit\n";
cout
<<"------------------------------------\n";
cout <<"Enter your choice: ";
cin >>choice;
switch(choice)
{
case 1:
cout <<"Enter data to push into stack:
";
cin >> data;
// Push element to stack
push(data);
break;
case 2:
data = pop();
/// If stack is not empty
if (data != INT_MIN)
cout <<"Data => " << data <<
endl;
break;
case 3:
cout <<"Stack size: " << top + 1 <<
endl;
break;
case 4:
display();
break;
case 5:
cout <<"Exiting from app.\n";
exit(0);
break;
default:
cout <<"Invalid choice, please try
again.\n";
}
cout <<"\n\n";
}
return 0;
}
/**
* Function to push a new element in stack.
*/
void push(int element)
{
/// Check stack overflow
if (top >= SIZE)
{
cout <<"Stack Overflow, can't add more element
element to stack.\n";
return;
}
/// Increase element count in stack
top++;
/// Push element in stack
stack[top] = element;
cout <<"Data pushed to stack.\n";
}
/**
* Function to pop element from top of stack.
*/
int pop()
{
/// Check stack underflow
if (top < 0)
{
cout <<"Stack is empty.\n";
/// Throw empty stack error/exception
/// Since C does not have concept of
exception
/// Hence return minimum integer value as error
value
/// Later in code check if return value is INT_MIN,
then
/// stack is empty
return INT_MIN;
}
/// Return stack top and decrease element count in
stack
return stack[top--];
}
void display()
{
if ( top >=0)
{
for(int i = 0; i <= top ; i++ )
cout << stack[i] << " ";
cout << endl;
}
else
cout << "stack is empty\n\n";
}
****************************************************
PART B - QUEUES
Please study the code posted below.
Please rewrite the code implementing a template class using a linked list instead of an array. Note: The functionality should remain the same
/**
* Queue implementation using linked list C style
implementation ( no OOP).
*/
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <iostream>
#define CAPACITY 100 // Queue max capacity
using namespace std;
/** Queue structure definition */
struct QueueType
{
int data;
struct QueueType * next;
};
/** Queue size */
unsigned int size = 0;
int enqueue(QueueType * &rear, QueueType * &front,
int data);
int dequeue(QueueType * &front);
int getRear(QueueType * &rear);
int getFront(QueueType * &front);
void display(QueueType * front);
int isEmpty();
int isFull();
string prepMenu();
int main()
{
int option, data;
QueueType *rear, *front;
rear = NULL;
front = NULL;
string menu = prepMenu();
cout << menu << endl;
cin >> option;
while (option !=7)
{
switch (option)
{
case 1:
cout << "\nEnter data to enqueue (-99 to stop):
";
cin >> data;
while ( data != -99)
{
/// Enqueue function returns 1 on success
/// otherwise 0
if (enqueue(rear, front, data))
cout << "Element added to queue.";
else
cout << "Queue is full." <<
endl;
cout << "\nEnter data to enqueue (-99 to stop):
";
cin >> data;
}
break;
case 2:
data = dequeue(front);
/// on success dequeue returns element
removed
/// otherwise returns INT_MIN
if (data == INT_MIN)
cout << "Queue is empty."<<
endl;
else
cout << "Data => " << data <<
endl;
break;
case 3:
/// isEmpty() function returns 1 if queue is
emtpy
/// otherwise returns 0
if (isEmpty())
cout << "Queue is empty."<<
endl;
else
cout << "Queue size => "<< size <<
endl;
break;
case 4:
data = getRear(rear);
if (data == INT_MIN)
cout << "Queue is empty." <<
endl;
else
cout << "Rear => " << data <<
endl;
break;
case 5:
data = getFront(front);
if (data == INT_MIN)
cout <<"Queue is empty."<< endl;
else
cout <<"Front => " << data <<
endl;
break;
case 6:
display(front);
break;
default:
cout <<"Invalid choice, please input number between
(0-5).\n";
break;
}
cout <<"\n\n";
cout << menu<< endl;
cin >> option;
}
}
/**
* Enqueues/Insert an element at the rear of a
queue.
* Function returns 1 on success otherwise returns
0.
*/
int enqueue(QueueType * &rear, QueueType * &front,
int data)
{
QueueType * newNode = NULL;
/// Check queue out of capacity error
if (isFull())
{
return 0;
}
/// Create a new node of queue type
newNode = new QueueType;
/// Assign data to new node
newNode->data = data;
/// Initially new node does not point
anything
newNode->next = NULL;
/// Link new node with existing last node
if ( (rear) )
{
rear->next = newNode;
}
/// Make sure newly created node is at rear
rear = newNode;
/// Link first node to front if its NULL
if ( !( front) )
{
front = rear;
}
/// Increment quque size
size++;
return 1;
}
/**
* Dequeues/Removes an element from front of the
queue.
* It returns the element on success otherwise
returns
* INT_MIN as error code.
*/
int dequeue(QueueType * &front)
{
QueueType *toDequque = NULL;
int data = INT_MIN;
// Queue empty error
if (isEmpty())
{
return INT_MIN;
}
/// Get element and data to dequeue
toDequque = front;
data = toDequque->data;
/// Move front ahead
front = (front)->next;
/// Decrement size
size--;
/// Clear dequeued element from memory
free(toDequque);
return data;
}
/**
* Gets, element at rear of the queue. It returns the
element
* at rear of the queue on success otherwise return INT_MIN
as
* error code.
*/
int getRear(QueueType * & rear)
{
// Return INT_MIN if queue is empty otherwise
rear.
return (isEmpty())
? INT_MIN
: rear->data;
}
/**
* Gets, element at front of the queue. It returns the
element
* at front of the queue on success otherwise return INT_MIN
as
* error code.
*/
int getFront(QueueType * &front)
{
// Return INT_MIN if queue is empty otherwise
front.
return (isEmpty())
? INT_MIN
: front->data;
}
/**
* Checks, if queue is empty or not.
*/
int isEmpty()
{
return (size <= 0);
}
/**
* Checks, if queue is within the maximum queue
capacity.
*/
int isFull()
{
return (size > CAPACITY);
}
string prepMenu()
{
string menu = "";
menu+= "
\n-------------------------------------------------------------------\n";
menu+= "1.Enqueue 2.Dequeue 3.Size 4.Get Rear 5.Get Front
6.Display 7.Exit\n";
menu+=
"----------------------------------------------------------------------\n";
menu+= "Select an option: ";
return menu;
}
void display(QueueType * front)
{
for ( QueueType *t = front; t !=NULL; t =
t->next)
cout <<t->data << " ";
cout << endl << endl;
}
In: Computer Science
Write the pseudocodes for these programs:
a)
#include <iostream>
using namespace std;
void print(int arr[],int n){
if(n==0)
return;
cout<<arr[n-1]<<" ";
print(arr,n-1);
}
int main()
{
int n;
cout<<"Enter the size of the array:";
cin>>n;
int arr[n];
int i;
cout<<"Enter the elements of the array:"<<endl;
for(i=0;i<n;i++){
cin >> arr[i];
}
cout<<"Displaying the elements of the array in reverse
order:"<<endl;
print(arr,n);
return 0;
}
b)
#include<iostream>
#include<fstream>
using namespace std;
//student structure
struct student
{
int id;
float gpa;
};
//node structure
struct node
{
student *data;
node *link;
};
//linklist class
class List
{
private:
node *head;
public:
List()
{
head=NULL;
}
//function to insert data into List
void Insert(student *S)
{
node *ptr=head;
node *temp=new node();
temp->data=S;
temp->link=NULL;
if(ptr==NULL)
{
head=temp;
}
else
{
while(ptr->link!=NULL)
{
ptr=ptr->link;
}
ptr->link=temp;
}
}
//function to display data
void display()
{
node *ptr=head;
if(ptr==NULL)
{
cout<<"NO DATA EXISTS"<<endl;
}
else
{
while(ptr!=NULL)
{
student *s=ptr->data;
cout<<s->id<<" "<<s->gpa<<endl;
ptr=ptr->link;
}
}
}
};
int main()
{
ifstream infile;
string filename;
List L;
int id;
float gpa;
cout<<"Enter Filename : ";
cin>>filename;
infile.open(filename.c_str());
if(!infile)
{
cout<<"Unable to open file"<<endl;
return 0;
}
while(infile>>id>>gpa)
{
student *ptr=new student();
ptr->id=id;
ptr->gpa=gpa;
L.Insert(ptr);
}
//displaying data to Console
cout<<"STUDENT DATA"<<endl;
L.display();
}
In: Computer Science
Consider the following relations and relationship
property(propertyNo, ownerID, type, rent, address)
Newspaper(newspaperNo, name, street, city, zipCode, phoenNo)
Advertisement(propertyNo, newspaperNo, date, cost)
1. List the propertyNo of all the properties that have been advertised on “Houston Chronical”
2. List the names of all the newspapers where the properties with rent greater 1000 have been posted.
In: Computer Science
Write in C++
Comment Steps
A bank charges $10 per month plus the following check fees for a commercial checking account:
$0.10 each for fewer than 20 checks
$0.08 each for 20 - 39 checks
$0.06 each for 40 - 59 checks
$0.04 each for 60 or more checks
The bank also charges an extra $15 if the balance of the account falls below $400 (before any check fees are applied). Write a program that asks for the beginning balance and the number of checks written. Compute and display the bank's service fees for the month
INPUT VALIDATION: Do not accept a negative value for the number of checks written. If a negative value is given for the beginning balance, display an urgent message indicating the account is overdrawn.
In: Computer Science
Write a Y86 program in C language that sorts an array of data using Bubble Sort. Allow the user to input up to 10 numbers from the keyboard. Sort the array in place (i.e., no need to allocate additional memory for the sorted array). Your program should be a complete one
In: Computer Science
Write the pseudo code for this problem based on what you learned from the video. The purpose is to design a modular program that asks the user to enter the length and width, and then calculates the area. The formula is as follows:
Area = Width x Length
In: Computer Science
Write a java program to let the user enter the path to any directory on their computers. Then list all the files in that directory.
In: Computer Science
Java Program that prompts the user and reads in an integer between 0 to 50, inclusively. If the entered value is outside the range, program’s output will display the following message: “Error: the entered number is out of range”, and continually re-prompts the user to enter the integer again until the user enters a valid integer. • Once a valid integer has been entered, program prompts the user and reads in a second integer between -5 to 20, inclusively. If the entered value is outside the range, program’s output will display the following message: “Error: the entered number is out of range”, and continually re-prompts the user to enter the integer again until the user enters a valid integer. • Once both integers have been entered, program prompts for and read in the arithmetic operation that the user wish to perform: addition (+), subtraction (+), multiplication (*), division (/), or modulus (%). If the entered operation is other than those listed, program’s output will display the following message: “Error: Invalid operation”, and exit the program. • The requested operation will be performed, and program’s output will show details of the operation. • Division by zero can occur with the user input. In that scenario, program’s output simply display “Error: Division by zero” and exit the program. • You also need to find out whether the result of the operation is negative, positive or zero and program’s output will display accordingly. • Comments your code (variable declaration, blocks of code, calculation)
In: Computer Science
Explain what composition is and how to use it.
In: Computer Science
In: Computer Science
This exercise just lets you focus on data types, statements, etc. in C# to ease you into the language. This
exercise is designed to allow you to focus on the data types
that are appropriate for attributes of real-
world objects. Later, you will start to combine these attributes
with behaviors (methods) and then
transition them into object-oriented classes.
Also, this exercise does not give explicit instructions on every
field required. You will be required to
think through the attributes of these "objects" as you create the
necessary data to support them in an
application.
Create a C# Console application. Within the Main() method in this
application, create variables of the
correct data type for the following:
• Student information, such as:
o First Name
o Last Name
o Birthdate
o Address Line 1
o Address Line 2
o City
o State/Province
o Zip/Postal
o Country
o Any other pertinent information you want to add for a student
record
• Professor information with pertinent fields related to what a
professor in real-life would have.
• A university degree with pertinent fields such as Bachelor or
Master.
o A degree can be Bachelor of Science in Information Technology and
include fields such as
Degree Name, credits required, etc. Some of the fields, such as
course list and prerequisites
will need to wait until you know how to create arrays or
collections.
• A university program with pertinent fields. Fields might
include:
o Program name (examples might be Business, Information
Technology)
o Degrees offered (Bachelor, Master, Ph.D.)
o Department Head
• Information for a course that would be part of your selected
degree and program, with pertinent
fields. Examples might be "Introduction to Computer Science" or
"Introduction to Psychology".
Once you have the variables created, use assignment statements
to assign values to them and use the
Console.WriteLine() method to output the values to the console
window.
Challenge
Investigate the .NET Framework documenation around
Console.ReadLine() and modify your code to use
this method for accepting input from a user of your application and
assign it to the variables you have
created.
In: Computer Science