This document provides solutions to hands-on exercises for an introductory Java programming course. It demonstrates how to create classes and objects, use methods, implement method overloading and inheritance. It also shows how to use a Java library by implementing a card dealer class that utilizes the StdRandom library to randomly deal playing cards.
Selection Statements
Using if and if...else
Nested if Statements
Using switch Statements
Conditional Operator
Repetition Statements
Looping: while, do, and for
Nested loops
Using break and continue
PT1420 Modules in Flowchart and Visual Basic .docxamrit47
PT1420: Modules in Flowchart and Visual Basic
Page 1
This lab requires you to think about the steps that take place in a program by designing a
flowchart. Use an application such as Raptor or Visio. Read the following program prior to
completing the lab.
Data Communications Corp wants a small program that will calculate the cost of UTP it
installs for their clients. Write a program that will ask the user to input the name of the
client and the number of feet of cable installed. The program should then calculate and
display a final bill. Cost per foot of UTP is .21 cents. Be sure to add on a tax of 6%. Final
bill should include the total cost and client name. Be sure to add modules to your
program.
Step 1: In main, create a module called declareVariables() that will set your variables to 0 or “ “.
Click the Call Symbol on the Left and Drag and Drop to the flow lines between Start and Stop.
Double click on the Call Symbol and type the name of your first module. For example, type
declareVariables in the Enter Call box. Do not put the ( ) when using Raptor. Click the Done
button. A new box will pop up that will ask you to create a new tab. Click Yes. A new tab will be
created for your new method. Notice the new Tab called declareVariables.
Watch the Help Video 4-2 to see how to add modules and initialize variables in Raptor and
Visio.
PT1420: Modules in Flowchart and Visual Basic
Page 2
Step 2: Continue this process to add your additional methods, which are inputData(),
calcCosts(), and displayBill(). Main should look like this:
In Raptor
In Visio
Start
End
declareVariables()
inputData()
calcCosts()
displayBill()
Step 3: Click on the inputData module and add the necessary code to input clientName and
feetUTP. Watch the Help Video 4-2 to see how to input variables in Raptor and Visio.
Step 4: Click the calcCosts module and add the necessary code to compute calculations. Watch
the Help Video 4-2 to see how to add calculations in Raptor and Visio.
Step 5: Click the displayBill module and add the necessary code to display the clientName and
totalCost to the screen. Watch the Help Video 4-2 to see how to display variables in Raptor and
Visio.
PT1420: Modules in Flowchart and Visual Basic
Page 3
Step 6: If you are using Raptor, you can run your program. Click Run, then Execute to Finish. For
your input, enter a client name such as Bumpco Inc and ...
Selection Statements
Using if and if...else
Nested if Statements
Using switch Statements
Conditional Operator
Repetition Statements
Looping: while, do, and for
Nested loops
Using break and continue
PT1420 Modules in Flowchart and Visual Basic .docxamrit47
PT1420: Modules in Flowchart and Visual Basic
Page 1
This lab requires you to think about the steps that take place in a program by designing a
flowchart. Use an application such as Raptor or Visio. Read the following program prior to
completing the lab.
Data Communications Corp wants a small program that will calculate the cost of UTP it
installs for their clients. Write a program that will ask the user to input the name of the
client and the number of feet of cable installed. The program should then calculate and
display a final bill. Cost per foot of UTP is .21 cents. Be sure to add on a tax of 6%. Final
bill should include the total cost and client name. Be sure to add modules to your
program.
Step 1: In main, create a module called declareVariables() that will set your variables to 0 or “ “.
Click the Call Symbol on the Left and Drag and Drop to the flow lines between Start and Stop.
Double click on the Call Symbol and type the name of your first module. For example, type
declareVariables in the Enter Call box. Do not put the ( ) when using Raptor. Click the Done
button. A new box will pop up that will ask you to create a new tab. Click Yes. A new tab will be
created for your new method. Notice the new Tab called declareVariables.
Watch the Help Video 4-2 to see how to add modules and initialize variables in Raptor and
Visio.
PT1420: Modules in Flowchart and Visual Basic
Page 2
Step 2: Continue this process to add your additional methods, which are inputData(),
calcCosts(), and displayBill(). Main should look like this:
In Raptor
In Visio
Start
End
declareVariables()
inputData()
calcCosts()
displayBill()
Step 3: Click on the inputData module and add the necessary code to input clientName and
feetUTP. Watch the Help Video 4-2 to see how to input variables in Raptor and Visio.
Step 4: Click the calcCosts module and add the necessary code to compute calculations. Watch
the Help Video 4-2 to see how to add calculations in Raptor and Visio.
Step 5: Click the displayBill module and add the necessary code to display the clientName and
totalCost to the screen. Watch the Help Video 4-2 to see how to display variables in Raptor and
Visio.
PT1420: Modules in Flowchart and Visual Basic
Page 3
Step 6: If you are using Raptor, you can run your program. Click Run, then Execute to Finish. For
your input, enter a client name such as Bumpco Inc and ...
"The joy of Scala" - Maxim Novak / Wix
Around eight years ago I started my journey as a developer. Since then, I've played around with many languages and thought that C# offers the best developer productivity. After joining Wix two years ago, I was exposed to the amazing world of Scala and Functional Programming and never looked back.
In Scala the code is much more concise, less ceremonious, immutable by default, combines functional with object oriented, seamlessly interoperates with Java, and many software engineering patterns are already baked into the language. Most importantly - Scala is FUN! By the end of the session you too will, hopefully, convert to Scala and never look back.
Recording of the lecture (Hebrew) - https://youtu.be/TcnYTwff2xU
The complexity of frontend applications over the years led to the creation of more robust solutions, where data logic won’t be messed up at scale. A shift took place from the traditional services approach, in which data is tightly coupled to the Views of their Components, towards more composable and shareable solutions. Each of these solutions is what we call a "state-manager".
Goal of this presentation is the comparative analysis between different react frontend state managers such as Redux, MobX, Recoil and React-Query. State Machines will also be presented, showing a completely different perception of how state can be orchestrated. Different mental models of the aforementioned state managers along with their different technical implementations will be presented to the audience. Ultimately, the audience can use this presentation for future reference on faster deciding which state-manager fits their own projects. Before delving into the comparison there will be a description of the main data flow in the browser. Concepts like reactivity, immutability, predictability, concurrency and performance will be detected on the main flow and will act as our comparison metrics among the state-managers.
This is a C# project . I am expected to create as this image shows. .pdfindiaartz
This is a C# project . I am expected to create as this image shows. If the image isnot clearly
showing , it\'s the Chegg\'s system. Please , if you see it quit long, assist me with the starting and
hinting bulltes point or functions that may simplify. Thannks...
The design of the Calculator form
Operation
· To clear the contents of memory, the user clicks the MC button. To save the value that’s
currently displayed in memory, the user clicks the MS button. To recall the value that’s currently
in memory and display it in the calculator, the user clicks the MR button. And to add the value
that’s currently displayed to the value in memory, the user clicks the M+ button.
· An M is displayed in the box above the MC button whenever the memory contains a value.
· See project 12-1 for additional details.
Specifications
· Create a class named MemoryCalculator that inherits the Calculator class described in
project 12-1. The MemoryCalculator class should add properties and methods as needed to
implement the memory function.
Note:
· MemoryCalculator class design:
Method Description
MemoryStore Stores the calculator’s current value in memory.
MemoryRecall Sets the calculator’s current value to the value stored in memory.
MemoryAdd Adds the calculator’s current value to the value currently stored in
memory.
MemoryClear Clears the current memory value.
Solution
Calculator.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Calculator
{
public class Calculator
{
public decimal currentValue;
private decimal operand1;
public decimal operand2;
private Operator op;
public enum Operator { Addd, Subtract, Multiply, Divide, None };
//Needed to be changed from private to public
public Calculator()
{
this.currentValue = 0;
this.operand1 = 0;
this.operand2 = 0;
this.op = Operator.None;
}
public decimal CurrentValue
{
get { return this.currentValue; }
}
public void Clear()
{
this.currentValue = 0;
this.operand1 = 0;
this.operand2 = 0;
this.op = Operator.None;
}
public void Add(decimal val)
{
this.operand1 = val;
this.currentValue = val;
this.op = Operator.Addd;
}
public void Subtract(decimal val)
{
this.operand1 = val;
this.currentValue = val;
this.op = Operator.Subtract;
}
public void Multiply(decimal val)
{
this.operand1 = val;
this.currentValue = val;
this.op = Operator.Multiply;
}
public void Divide(decimal val)
{
this.operand1 = val;
this.currentValue = val;
this.op = Operator.Divide;
}
public void Equals(decimal val)
{
operand2 = val;
switch (this.op)
{
case Operator.Addd:
currentValue = operand1 + operand2;
break;
case Operator.Subtract:
currentValue = operand1 - operand2;
break;
case Operator.Multiply:
currentValue = operand1 * operand2;
break;
case Operator.Divide:
//Try catch to prevent dividing by zero
try
{
currentValue = operand1 / operand2;
}
catch (DivideByZeroException)
{
MessageBox.Show(\"You cannot divide by zero\", \"Error!\");
}
break;
case Opera.
I am Irene M. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from from California, USA. I have been helping students with their homework for the past 10 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
C# Programming. Using methods to call results to display. The code i.pdffatoryoutlets
Assembly Language:
For this program you will call a procedure that finds the minimum and maximum elements of an
array, and the last positions in the array where the minimum and maximum element occurs.
The output of the program is:
The position in array of last occurrence of minimum element is: 4
The minimum element in the array is: 5
The position in array of last occurrence of maximum element is: 6
The maximum element in the array is: 90
Use an array named Array to contain the elements (as DWORDS):
5, 46, 90, 50, 5, 6, 90, 8, 20
All variables in main are DWORDS.
The name of the procedure is MinandMax, and its equivalent call in C++ would be:
MinandMax(int &max, int &maxposn, int &min, int &maxposn,int& Array, int Arrsze);
All arguments must be passed on the stack. You must use the C++ calling conventions for
ordering of arguments on the stack. You must use the conventions for caller and callee saved
registers on slide 26 of SS7 assuming that all registers EAX, EBX, ECX, EDX, EDI, ESI may be
used for some purpose in main other than support for calling MinandMax.
Registers EAX, EBX, ECX, EDX, EDI, ESI are used for some purpose in MinandMax.
In MinandMax, there is only one loop. Thus, you must use conditionals within the loop to
implement finding the maximum element, minimum element, position of the maximum element
and position of the minimum element.
The ebp register must be saved within MinandMax.
The caller is responsible for cleaning up the stack.
The last line in the program should be END main
Solution
Answer:
.zero 1
.LC0:
.string \"\ \ \\t ENTER THE SIZE OF THE ARRAY\\342\\200\\246:\"
.LC1:
.string \"\ \ \\t ENTER THE ELEMENTS OF THE ARRAY\\342\\200\\246: \"
.LC2:
.string \"\ \ \\t THE LARGEST ELEMENT IS\\342\\200\\246: %d\"
.LC3:
.string \"\ \ \\t AND ITS POSSITION IS\\342\\200\\246: %d\"
.LC4:
.string \"\ \ \\tTHE SMALlEST ELEMENT IS\\342\\200\\246: %d\"
main:
push rbp
mov rbp, rsp
sub rsp, 144
mov esi, OFFSET FLAT:.LC0
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const*)
lea rax, [rbp-132]
mov rsi, rax
mov edi, OFFSET FLAT:std::cin
call std::basic_istream >::operator>>(int&)
mov esi, OFFSET FLAT:.LC1
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const*)
mov DWORD PTR [rbp-20], 1
.L3:
mov eax, DWORD PTR [rbp-132]
cmp DWORD PTR [rbp-20], eax
jg .L2
lea rax, [rbp-128]
mov edx, DWORD PTR [rbp-20]
movsx rdx, edx
sal rdx, 2
add rax, rdx
mov rsi, rax
mov edi, OFFSET FLAT:std::cin
call std::basic_istream >::operator>>(int&)
add DWORD PTR [rbp-20], 1
jmp .L3
.L2:
mov eax, DWORD PTR [rbp-124]
mov DWORD PTR [rbp-4], eax
mov DWORD PTR [rbp-12], 1
mov DWORD PTR [rbp-20], 1
.L6:
mov eax, DWORD PTR [rbp-132]
cmp DWORD PTR [rbp-20], eax
jg .L4
mov eax, DWORD PTR [rbp-20]
cdqe
mov eax, DWORD PTR [rbp-128+rax*4]
cmp eax, DWORD PTR [rbp-4]
jle .L5
mov eax, DWORD PTR [rbp-20]
cdqe
mov eax, DWORD PTR [rbp-128+rax*4]
mov DWORD PTR [rbp-4], ea.
03-Factory Method for design patterns.pdfssusera587d2
The Factory Design Pattern is a creational design pattern that provides a way to encapsulate the instantiation process of an object. It involves defining an interface for creating an object but lets subclasses decide which class to instantiate. The Factory pattern is used when a class cannot anticipate the class of objects it needs to create beforehand or when a class wants its subclasses to specify the objects it creates.
Here’s a high-level overview of the components involved in the Factory Design Pattern:
Product: This is an abstract class or interface that defines the operations for the objects that the factory will create.
Concrete Products: These are the classes that implement the Product interface, each representing a specific type of object to be created.
Creator: An abstract class or interface that declares the factory method, responsible for creating Product objects.
Concrete Creators: Subclasses of the Creator that implement the factory method and decide which specific Concrete Product to create.
Factory Method: A method defined in the Creator class that is responsible for creating Product objects. It’s typically declared as abstract in the Creator and implemented in the Concrete Creators.
The Factory Method pattern allows for the creation of objects without specifying the exact class of object that will be created. This is done by creating objects via a factory method rather than by direct construction calls (using the new operator). This method is often referred to as a “Virtual Constructor”.
For
Apollo Client is a community driven, powerful and flexible GraphQL client which brings an entire new world of data management to your applications.
Yuri is a JavaScript anarchist. He merges directly to the master branch, doesn’t move tickets in Jira and make mistakes in Pull Requests on purpose just to test colleagues. Believes that REST is dead and GraphQL is a new way to better living.
Similar to Java 102 intro to object-oriented programming in java - exercises (20)
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Globus
Large Language Models (LLMs) are currently the center of attention in the tech world, particularly for their potential to advance research. In this presentation, we'll explore a straightforward and effective method for quickly initiating inference runs on supercomputers using the vLLM tool with Globus Compute, specifically on the Polaris system at ALCF. We'll begin by briefly discussing the popularity and applications of LLMs in various fields. Following this, we will introduce the vLLM tool, and explain how it integrates with Globus Compute to efficiently manage LLM operations on Polaris. Attendees will learn the practical aspects of setting up and remotely triggering LLMs from local machines, focusing on ease of use and efficiency. This talk is ideal for researchers and practitioners looking to leverage the power of LLMs in their work, offering a clear guide to harnessing supercomputing resources for quick and effective LLM inference.
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Shahin Sheidaei
Games are powerful teaching tools, fostering hands-on engagement and fun. But they require careful consideration to succeed. Join me to explore factors in running and selecting games, ensuring they serve as effective teaching tools. Learn to maintain focus on learning objectives while playing, and how to measure the ROI of gaming in education. Discover strategies for pitching gaming to leadership. This session offers insights, tips, and examples for coaches, team leads, and enterprise leaders seeking to teach from simple to complex concepts.
Developing Distributed High-performance Computing Capabilities of an Open Sci...Globus
COVID-19 had an unprecedented impact on scientific collaboration. The pandemic and its broad response from the scientific community has forged new relationships among public health practitioners, mathematical modelers, and scientific computing specialists, while revealing critical gaps in exploiting advanced computing systems to support urgent decision making. Informed by our team’s work in applying high-performance computing in support of public health decision makers during the COVID-19 pandemic, we present how Globus technologies are enabling the development of an open science platform for robust epidemic analysis, with the goal of collaborative, secure, distributed, on-demand, and fast time-to-solution analyses to support public health.
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Hivelance Technology
Cryptocurrency trading bots are computer programs designed to automate buying, selling, and managing cryptocurrency transactions. These bots utilize advanced algorithms and machine learning techniques to analyze market data, identify trading opportunities, and execute trades on behalf of their users. By automating the decision-making process, crypto trading bots can react to market changes faster than human traders
Hivelance, a leading provider of cryptocurrency trading bot development services, stands out as the premier choice for crypto traders and developers. Hivelance boasts a team of seasoned cryptocurrency experts and software engineers who deeply understand the crypto market and the latest trends in automated trading, Hivelance leverages the latest technologies and tools in the industry, including advanced AI and machine learning algorithms, to create highly efficient and adaptable crypto trading bots
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTier1 app
Even though at surface level ‘java.lang.OutOfMemoryError’ appears as one single error; underlyingly there are 9 types of OutOfMemoryError. Each type of OutOfMemoryError has different causes, diagnosis approaches and solutions. This session equips you with the knowledge, tools, and techniques needed to troubleshoot and conquer OutOfMemoryError in all its forms, ensuring smoother, more efficient Java applications.
How to Position Your Globus Data Portal for Success Ten Good PracticesGlobus
Science gateways allow science and engineering communities to access shared data, software, computing services, and instruments. Science gateways have gained a lot of traction in the last twenty years, as evidenced by projects such as the Science Gateways Community Institute (SGCI) and the Center of Excellence on Science Gateways (SGX3) in the US, The Australian Research Data Commons (ARDC) and its platforms in Australia, and the projects around Virtual Research Environments in Europe. A few mature frameworks have evolved with their different strengths and foci and have been taken up by a larger community such as the Globus Data Portal, Hubzero, Tapis, and Galaxy. However, even when gateways are built on successful frameworks, they continue to face the challenges of ongoing maintenance costs and how to meet the ever-expanding needs of the community they serve with enhanced features. It is not uncommon that gateways with compelling use cases are nonetheless unable to get past the prototype phase and become a full production service, or if they do, they don't survive more than a couple of years. While there is no guaranteed pathway to success, it seems likely that for any gateway there is a need for a strong community and/or solid funding streams to create and sustain its success. With over twenty years of examples to draw from, this presentation goes into detail for ten factors common to successful and enduring gateways that effectively serve as best practices for any new or developing gateway.
top nidhi software solution freedownloadvrstrong314
This presentation emphasizes the importance of data security and legal compliance for Nidhi companies in India. It highlights how online Nidhi software solutions, like Vector Nidhi Software, offer advanced features tailored to these needs. Key aspects include encryption, access controls, and audit trails to ensure data security. The software complies with regulatory guidelines from the MCA and RBI and adheres to Nidhi Rules, 2014. With customizable, user-friendly interfaces and real-time features, these Nidhi software solutions enhance efficiency, support growth, and provide exceptional member services. The presentation concludes with contact information for further inquiries.
Understanding Globus Data Transfers with NetSageGlobus
NetSage is an open privacy-aware network measurement, analysis, and visualization service designed to help end-users visualize and reason about large data transfers. NetSage traditionally has used a combination of passive measurements, including SNMP and flow data, as well as active measurements, mainly perfSONAR, to provide longitudinal network performance data visualization. It has been deployed by dozens of networks world wide, and is supported domestically by the Engagement and Performance Operations Center (EPOC), NSF #2328479. We have recently expanded the NetSage data sources to include logs for Globus data transfers, following the same privacy-preserving approach as for Flow data. Using the logs for the Texas Advanced Computing Center (TACC) as an example, this talk will walk through several different example use cases that NetSage can answer, including: Who is using Globus to share data with my institution, and what kind of performance are they able to achieve? How many transfers has Globus supported for us? Which sites are we sharing the most data with, and how is that changing over time? How is my site using Globus to move data internally, and what kind of performance do we see for those transfers? What percentage of data transfers at my institution used Globus, and how did the overall data transfer performance compare to the Globus users?
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Globus
The Earth System Grid Federation (ESGF) is a global network of data servers that archives and distributes the planet’s largest collection of Earth system model output for thousands of climate and environmental scientists worldwide. Many of these petabyte-scale data archives are located in proximity to large high-performance computing (HPC) or cloud computing resources, but the primary workflow for data users consists of transferring data, and applying computations on a different system. As a part of the ESGF 2.0 US project (funded by the United States Department of Energy Office of Science), we developed pre-defined data workflows, which can be run on-demand, capable of applying many data reduction and data analysis to the large ESGF data archives, transferring only the resultant analysis (ex. visualizations, smaller data files). In this talk, we will showcase a few of these workflows, highlighting how Globus Flows can be used for petabyte-scale climate analysis.
Designing for Privacy in Amazon Web ServicesKrzysztofKkol1
Data privacy is one of the most critical issues that businesses face. This presentation shares insights on the principles and best practices for ensuring the resilience and security of your workload.
Drawing on a real-life project from the HR industry, the various challenges will be demonstrated: data protection, self-healing, business continuity, security, and transparency of data processing. This systematized approach allowed to create a secure AWS cloud infrastructure that not only met strict compliance rules but also exceeded the client's expectations.
A Comprehensive Look at Generative AI in Retail App Testing.pdfkalichargn70th171
Traditional software testing methods are being challenged in retail, where customer expectations and technological advancements continually shape the landscape. Enter generative AI—a transformative subset of artificial intelligence technologies poised to revolutionize software testing.
Large Language Models and the End of ProgrammingMatt Welsh
Talk by Matt Welsh at Craft Conference 2024 on the impact that Large Language Models will have on the future of software development. In this talk, I discuss the ways in which LLMs will impact the software industry, from replacing human software developers with AI, to replacing conventional software with models that perform reasoning, computation, and problem-solving.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
Enhancing Research Orchestration Capabilities at ORNL.pdfGlobus
Cross-facility research orchestration comes with ever-changing constraints regarding the availability and suitability of various compute and data resources. In short, a flexible data and processing fabric is needed to enable the dynamic redirection of data and compute tasks throughout the lifecycle of an experiment. In this talk, we illustrate how we easily leveraged Globus services to instrument the ACE research testbed at the Oak Ridge Leadership Computing Facility with flexible data and task orchestration capabilities.
Accelerate Enterprise Software Engineering with PlatformlessWSO2
Key takeaways:
Challenges of building platforms and the benefits of platformless.
Key principles of platformless, including API-first, cloud-native middleware, platform engineering, and developer experience.
How Choreo enables the platformless experience.
How key concepts like application architecture, domain-driven design, zero trust, and cell-based architecture are inherently a part of Choreo.
Demo of an end-to-end app built and deployed on Choreo.
Check out the webinar slides to learn more about how XfilesPro transforms Salesforce document management by leveraging its world-class applications. For more details, please connect with sales@xfilespro.com
If you want to watch the on-demand webinar, please click here: https://www.xfilespro.com/webinars/salesforce-document-management-2-0-smarter-faster-better/
Experience our free, in-depth three-part Tendenci Platform Corporate Membership Management workshop series! In Session 1 on May 14th, 2024, we began with an Introduction and Setup, mastering the configuration of your Corporate Membership Module settings to establish membership types, applications, and more. Then, on May 16th, 2024, in Session 2, we focused on binding individual members to a Corporate Membership and Corporate Reps, teaching you how to add individual members and assign Corporate Representatives to manage dues, renewals, and associated members. Finally, on May 28th, 2024, in Session 3, we covered questions and concerns, addressing any queries or issues you may have.
For more Tendenci AMS events, check out www.tendenci.com/events
Why React Native as a Strategic Advantage for Startup Innovation.pdfayushiqss
Do you know that React Native is being increasingly adopted by startups as well as big companies in the mobile app development industry? Big names like Facebook, Instagram, and Pinterest have already integrated this robust open-source framework.
In fact, according to a report by Statista, the number of React Native developers has been steadily increasing over the years, reaching an estimated 1.9 million by the end of 2024. This means that the demand for this framework in the job market has been growing making it a valuable skill.
But what makes React Native so popular for mobile application development? It offers excellent cross-platform capabilities among other benefits. This way, with React Native, developers can write code once and run it on both iOS and Android devices thus saving time and resources leading to shorter development cycles hence faster time-to-market for your app.
Let’s take the example of a startup, which wanted to release their app on both iOS and Android at once. Through the use of React Native they managed to create an app and bring it into the market within a very short period. This helped them gain an advantage over their competitors because they had access to a large user base who were able to generate revenue quickly for them.
3. Exercise: Creating Objects
• Create a new Java project named Java102
• Create a new package named exercise.carfactory
• Create a class named Car in the exercise.carfactory
package
• Add color, make and model properties to the Car class
• Create a java program named CarFactory (in same
package) that creates two instances of the class Car,
changes their colors to Blue and Pink and prints a message
to the console
• Run the class CarFactory and observe the message in the
Console.
4. Solution: Creating Objects
package exercise.creatingobjects;
public class Car {
String make;
String model;
String color;
}
package exercise.creatingobjects;
public class CarFactory {
public static void main(String[] args) {
Car firstCar = new Car();
Car secondCar = new Car();
firstCar.color = "Blue";
secondCar.color = "Pink";
System.out.println("Just finished painting new cars");
}
}
Car.java
CarFactory.java
6. Exercise: Working with Methods
• What happens when you compile and run the
following code?
public class Cubes {
static int cube (int i){
int j = i * i * i;
return j;
}
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
for (int i=0 ;i<= N; i++) {
System.out.println(i + " " + cube(i));
}
}
}
7. Solution: Working with Methods
public class Cubes {
static int cube (int i){
int j = i * i * i;
return j;
}
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
for (int i=0 ;i<= N; i++) {
System.out.println(i + " " + cube(i));
}
}
}
% java Cubes 6
0 0
1 1
2 8
3 27
4 64
5 125
6 216
9. Exercise : Method Overloading
• Create a new package named exercise.methodoverloading
• Create a BasicRateTax class with a method calcTax() that returns 20% of a fixed
base income of £1000
• Create a java program named TaxCollector that creates a new BasicRateTax object,
calls the calcTax() method and prints the output to the console
• Run the TaxCollector program and ensure it always prints 200.00 as calculated tax
• Add new calcTax() method to BasicRateTax class that takes a double grossIncome
parameter and calculates the tax as 20% of the grossIncome if it’s greater than the
base income of £1000
• Change the TaxCollector program to call the new calcTax(double grossIncome)
method and passing the gross Income value from the command line
• Run the TaxCollector program and see if the tax is correctly calculated.
• Re-run the program with different Gross Income values and check the output
10. Solution: Method Overloading
package exercise.methodoverloading;
public class BasicRateTax {
private static final double BASE_INCOME = 1000.00;
private static final double BASIC_TAX_RATE = 0.20;
public double calcTax (){
return BASE_INCOME * BASIC_TAX_RATE;
}
public double calcTax(double grossIncome){
if (grossIncome < BASE_INCOME){
return calcTax();
}
return grossIncome * BASIC_TAX_RATE;
}
}
11. Solution: Method Overloading
package exercise.methodoverloading;
public class TaxCollector {
public static void main(String[] args) {
double grossIncome = Double.parseDouble(args[0]);
BasicRateTax taxCalculator = new BasicRateTax();
double tax = taxCalculator.calcTax(grossIncome);
System.out.println("Tax due is " + tax);
}
}
% java TaxCollector 2000
Tax due is 400.0
% java TaxCollector 10000
Tax due is 2000.0
13. Exercise: Inheritance
• Create a new package named exercise.inheritance
• Create a class named HigherRateTax in the exercise.inheritance package that
extends BasicRateTax and add an empty calcTax(double grossIncome) method
• Add the code to HigherRateTax.calcTax(double grossIncome) method to calculate
the tax as follows:
– 20% of grossIncome if up to £34,000 (hint: reuse the BasicRateTax.calcTax(double
grossIncom) method)
– 40% of grossIncome if above £34,000 but less than £150,000
– 50% of grossIncome if £150,000 or above
• Run the existing TaxCollector program with some large gross income amounts and
observe that your changes didn’t have any effect on the calculate tax. Why?
• Change the code of the TaxCollector to instantiate HigherRateTax instead of
BasicRateTax
• Run the TaxCollector program again and observe that now the new percentage is
properly applied. You are now using the overridden version of the method
calcTax().
14. Solution: Inheritance
package exercise.inheritance;
import exercise.methodoverloading.BasicRateTax;
public class HigherRateTax extends BasicRateTax {
public double calcTax(double grossIncome){
double tax = 0.0;
if (grossIncome <=34000.00){
tax = super.calcTax(grossIncome);
}else if (grossIncome > 34000 && grossIncome <=150000) {
tax = grossIncome * 0.40;
}else if (grossIncome > 150000){
tax = grossIncome * 0.50;
}
return tax;
}
}
15. Solution: Inheritance
package exercise.methodoverloading;
import exercise.inheritance.HigherRateTax;
public class TaxCollector {
public static void main(String[] args) {
double grossIncome = Double.parseDouble(args[0]);
BasicRateTax taxCalculator = new HigherRateTax ();
double tax = taxCalculator.calcTax(grossIncome);
System.out.println("Tax due is " + tax);
}
}
% java TaxCollector 51000
Tax due is 20400.0
% java TaxCollector 32000
Tax due is 6400.0
% java TaxCollector 155000
Tax due is 77500.0
17. Exercise: Using Libraries
• Create a new package named exercise.libraryclient
• Create a class named CardDealer with an empty
deal() method that takes no arguments and returns
a String
• Implement the card dealer to use the StdRandom
library to deal playing cards ramdomly from an
infinite deck of cards
• Create a CardDealerTest program to test the
CardDealer class
18. Exercise: Using the StdRandom Library
public class CardDealer {
private static final String[] SUITES = { "D", "H", "C", "S"
};
private static final int TOTAL_CARDS_PER_SUITE = 13;
public String deal() {
// select a random suite
String suite = SUITES[StdRandom.uniform(SUITES.length)];
// select a random rank
int rank = StdRandom.uniform (TOTAL_CARDS_PER_SUITE ) +
1;
String card = rank + suite;
// return the dealt card
return card;
}
}
19. Testing the CardDealer Program
public class CardDealerTest {
public static void main(String[] args) {
CardDealer dealer = new CardDealer();
for (int i=0;i<5;i++){
String card = dealer.deal();
System.out.println( “ Card “ + i + “ is “ + card);
}
}
}