100% de satisfacción garantizada Inmediatamente disponible después del pago Tanto en línea como en PDF No estas atado a nada 4.2 TrustPilot
logo-home
Otro

code java

Puntuación
-
Vendido
-
Páginas
8
Subido en
11-09-2023
Escrito en
2023/2024

Past question papers on java code to practice on if you need to understand more java coding

Institución
Grado









Ups! No podemos cargar tu documento ahora. Inténtalo de nuevo o contacta con soporte.

Escuela, estudio y materia

Institución
Grado

Información del documento

Subido en
11 de septiembre de 2023
Número de páginas
8
Escrito en
2023/2024
Tipo
Otro
Personaje
Desconocido

Temas

Vista previa del contenido

Practice Questions
Note:
These are practical programming questions taken from previous assessments and tutorials. They cover
the entire syllabus.

Write a class that represents the outcome of a soccer match. Its member attributes should include:

• The names of each team.
• The scores of each team.

Its member methods should include:

• A constructor that allows the programmer to set the names and scores of each team.
• A constructor that allows the programmer to set the names of each team, but sets the score
of each team to 0.
• set() methods to set the score attributes.
• a Result() method that returns the name of the winning team, or "Draw" if the match is
drawn




The code below is used to get the user to enter an even integer - even integers leave no remainder
when divided by 2.




If the user enters a number that is not even, it will ask the user to enter a number again. However,
this code needs to be changed to prompt the user when they enter a non-integer.

a) Write the code that needs to be added to handle the case where the user enters a non-integer.
Also, give any existing lines of that need to be changed, by giving the line number and the new line of
code.

b) Where should the code from part a) be added? Give the line number.




Page 1 of 8

, The following class is used to give a simple representation of the income, expenses and profit of a
business. There are parts of the class that are missing that you need to write.

public class Business {
private float income, expenses, profit;
//###################################
// Your answer to Part (A) will go here.
//###################################

void setIncome(float newIncome) {
income = newIncome;
}
//###################################
// Your answer to Parts (B), (C) and (D) will go here.
//###################################

}


• (10 marks) (A) Write two constructors that initialise the values of the income and expenses
variables. One constructor should allow the user to specify the initial values of these
variables, the other constructor should initialise these variables to 0.
• (5 marks) (B) Write a method CalcProfit() that sets the value of the profit variable. Profit is
the income less then expenses.
• (5 marks) (C) Write a method PerProfit() that recalculates the profit using the method
written in part (B) and returns the profit as a percentage of the income.
• (5 marks) (D) Write a method isProfitable() that recalculates the profit using the method
written in part (B) and returns a true value if the profit is positive and a false value if the
profit is negative.
• (2 marks) (E) Rewrite the variable declarations to make only the income variable accessible
outside the class.




The following class is used to represent a flour mill. The mill uses wheat to produce flour. The boolean
Error attribute is used to indicate that there was not enough wheat to produce the required number
of bags of flour.

public class FlourMill {
private int FlourBags = 0;
private float WheatKgs = 0;
boolean Error = false;
FlourMill(float InitialWheat) {
WheatKgs = InitialWheat;

Page 2 of 8
$7.74
Accede al documento completo:

100% de satisfacción garantizada
Inmediatamente disponible después del pago
Tanto en línea como en PDF
No estas atado a nada

Conoce al vendedor
Seller avatar
Tyrisc

Conoce al vendedor

Seller avatar
Tyrisc University of KwaZulu Natal
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
3
Miembro desde
3 año
Número de seguidores
1
Documentos
11
Última venta
3 año hace

0.0

0 reseñas

5
0
4
0
3
0
2
0
1
0

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes