Question
The function called A4Q2 returns the value of the calculation of 9 times the variable x to the power of 2.1. Note you can perform
The function called A4Q2 returns the value of the calculation of 9 times the variable x to the power of 2.1. Note you can perform xy in processing by using pow(x,y). This question checks your ability to convert programs and calculations in English into java code.
public float A4Q2( float x ) { return x ; }
3:Take the function called A4Q3, which has been written for you. This function simulates the spread of a virus given an initial population of people and a reproduction rate R. The R rate is how many people each infected person will infect. So if the infection rate is 1.1 and the population is 200, the number of infected people will be 220. You have to make 2 additions to the code. Firstly you need to print every time the value of the infected variable changes. If you print out 200 twice, then you have too many print statements. Secondly, when infected people get above 1 million, you must return the number of people infected. For example, if the number of people infected goes from 99,999 to 1,001,222, you must stop the function A4Q3 and return 1001222.
public float A4Q3( float infected, float R ) { // dont' forget to make this repeat until infected is greater than 1000000.
{ infected = infected + (infected * R) ; //output the value of infected here } return 0.0f ; }
4: This question tests your ability to write a function from scratch and so has not been given to you. You must create your own function, which should begin with the word public. It should be called A4Q4 it takes the number of minutes a person has used a phone that month as a float and returns the charge also as a float. If the subscriber is charged £20 per month for 300 minutes (or less) of phone calls. So if a user has used 50 minutes, they get charged £20, and your function would return 20.00. Minutes longer than 300 minutes, are charged 40p per minute. So if someone had 301 minutes of calls they would be charged £20.4 ( 1 x 0.40) and you would return 20.4. If 310 minutes they are charged #£24.0 This question tests your ability to write functions and if statements.
public float A4Q4( float minutes ) { return 0; }
5: The class GameCharacter has been written for you in a comment. This class represents a character in a game. It has a name, a position on the screen ( hoz and vert ) and a PImage called picture to hold the character. There is a constructor for the character, and there is a method called drawMe for the character. The code for the class is in a random order, put the class into a workable order. Then alter A4Q5 to return an instance of GameCharacter .
public class GameCharacter { /*
int vert ; Object picture; { if( this.hoz }
} public GameCharacter(int hoz, int vert)
public void drawMe()
int hoz ;
{ this.hoz = hoz; this.vert = vert; } */ }// end of class
public Object A4Q5() { return null; // new GameCharacter(5, 5); }
public class Generator { // your feilds here public Generator(int length, boolean up , boolean numbers) { // your code here. }
public String generatePassword() { String result =""; // Based on the variables make loop. return result ; } }
6: Generator is a class that generates user passwords. The class variables are the numbers' length' - which is the overall length of the password, so if 4, the system might generate a password like "dsws". Uppercase , when true, means you should make upper case in the password "DJTY" and numbers which when true means you should use digits "5653" (assuming length = 4). Implement the method generatePassword of class Generator. This has no arguments ( the variables are set in the constructor) and returns a String. Function A4Q6 creates an instance of this class. Note you can generate a random letter using the code char letter = (char)(random('a',' Z'); This tests your ability write methods for a class.
public Object A4Q6() { return new Generator(9, false, false); }
7: You must write a simple class called A4Q7Student which represents a student with the following variables - you must decide what types to use. In A4Q7 you must make a new instance of this class and return it(see A4Q5 for an example). The values for this instance are in the value column.
Note your methods and fields should be public.
// ANSWER TO A4Q7Student class here.
public Object A4Q7() // replace Object with A4Q7Student when class written. { return new Object(); // replace with your class. }
8: Create just a public global variable outside any function/method called exactly A4Q8. This must hold an instance of the class A4Q7Student, which is given in the code.
// ANSWER TO Question 8 here
9: Write a function called A4Q9, which takes an ArrayList of Strings and then prints each item out using println.
public void A4Q9( ArrayList list) { }
A4Q5 Is a Value studentName Text "Test" studentAddress Text "Test Location" Text "TE22 2345" Postcode entry Year A counting number 2022 2021 currentPercentage A number that can 50 wwwwwww contain fractions.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
1 A4Q2 Java public float A4Q2float x return float Mathpowx 21 Ens...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started