 Java Problems: Student Details & Fibonacci Series

Subject Computer Science Java Programming

Question

You are provided with the Student class, which consists of two private variables- name, age. It also contains a constructor, and two methods i.e. toString
// which will return the String representation of the Student object, and setAge which will set the Students age.

//Import the Scanner class.
//-->

//Write the class header for the file and the main method header.
public class Solution{

public static void main(String[] args){

//Instantiate an object of the Student class, called stInstance. Set the name and age as your own name and age. Use the constructor to do so.
??? ??? = new ???(???,???);

// Print the Student details by calling the toString method.
//-->

// Instantiate an object of the Scanner class.
//-->

System.out.print("Please enter the student's new age: ");

// Input the Students age from the user into a variable called newAge.
//->

// Use the setAge method, to set the age of stInstance to the age you just read in from the user.
???.setAge(???);

// Display the Student details again, and note how the age has been changed.
//-->

// Change the header for the Student class to private instead of public. Try to compile and run the program and note what happens.
//--> ****** This is an experiment (dont include it in your submission) *******

// Print Fibonacci Series i.e 1, 1, 2, 3, 5, 8, 13, 21, ...
// The formula is currVal= prevVal + prevPrevVal
// Define 3 integer variables currVal, prevVal and prevPrevVal. Initialize prevVal and prevPrevVal variables to 1
// and initialize currVal to 2
//-->

System.out.print("Fibonacci Series between 1 and 100: ");

// Print out prevVal
//-->

// Print out prevPrevVal
//-->

// Write a do-while loop to print out Fibonacci numbers less than or equals 100
???{

// Print out the <currVal>
//-->

// Assign <prevVal> to <prevPrevVal>
//-->

// Assign <currVal> to <prevVal>
//-->

// Calculate <currVal> using the formula given earlier
//-->

} // Check the while condition if <currVal> is less than or equals 100
???(???)

}
}

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class Student {

private String name;
private int age;

public Student(String someName, int someAge)
{
name = someName;
age = someAge;
}

public String toString()
{
return ("Name is \t:" + name + "\nAge is \t\t:" + age);
}

public void setAge(int newAge)
{
age = newAge;
}

}...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Java Problems: Integers, Strings, File Management & Arrays \$33.00
Java
Programming
Coding
Computer Science
Input
Output
File Management
Arrays
Integers
Average Values
Methods
Functions
Parameters
Declaration
Strings
Prime Numbers
Java Programming: Strings, Odd & Even Numbers, Absolute Values \$25.00
Java
Programming
Computer Science
Odd Numbers
Even Numbers
Integers
Absolute Values
While Loop
IF-Statements
Data Sets
Input
Output
Sum
Functions
Methods
Strings
Lexicography Order
Java & UML Programming Problems \$20.00
Java
UML
Programming
Coding
Computer Science
Fraction
Denominator
Numerator
Big Integers
Printing Outputs
Decimal Values
Arithmetic Operations
Java Programming Assignment \$10.00
Java Programming
Computer Science
Program
Inch
Milimeter
Perimeter
Circle
Area
Java Program For Longest Path in Graph \$40.00
Java
Programming
Codes
Algorithms
Graph Theory
Classes
Nodes
Edges
Paths
Distances
Loops
Statements
Variables
Input Files
Output Files
HashMap
Array
Integers
Methods
Live Chats