Question

In: Computer Science

Create a java program for Student profile with the following requirements. Each Student has: two variables...

Create a java program for Student profile with the following requirements.

  1. Each Student has: two variables id, and name.
  2. A Student can be initialization with two constructers:
  • Constructer without parameters, that set the id to zero and the name to an empty string.
  • Constructer with tow parameters to initialize the variables id and name by a specific value.
  1. Add a set method for each variable that change them to a specific value.
  2. Add a get method for each variable which return its value.

To test the program, create a class StudentTest with the main method.

In the main method:

  1. Create two empty Student profiles S1and S2.
  2. Print the S1and S2 information.
  3. Create a new student profile S3, specify the student id and name.
  4. Change S3id and name.
  5. Print the id and name of S3.

Answer:

Solutions

Expert Solution

import java.util.*;
class Student
{
int id;
String name;
Student() //Default Constructor
{
id=0;
name=null;
}
Student(int newId,String newName) //Parameterized Constructor
{
this.name=newName;
this.id=newId;
}
public void set(int i,String n) //Set Method
{
this.id=i;
this.name = n;
}
public int getid() //Get method for returning ID
{
return id;
}
public String getname() //Get method for returning Name
{
return name;
}
}
public class StudentTest //Test Class
{
   public static void main(String[] args) {
       Student S1 =new Student();
       Student S2 =new Student();
       System.out.println(S1.getid());
       System.out.println(S1.getname());
       System.out.println(S2.getid());
       System.out.println(S2.getname());
       Student S3 =new Student(3,"Student_Three");
   S3.set(4,"Student_Change");
   System.out.println(S3.getid());
       System.out.println(S3.getname());
   }
}


Related Solutions

Create a simple Java class for a Month object with the following requirements:  This program...
Create a simple Java class for a Month object with the following requirements:  This program will have a header block comment with your name, the course and section, as well as a brief description of what the class does.  All methods will have comments concerning their purpose, their inputs, and their outputs  One integer property: monthNumber (protected to only allow values 1-12). This is a numeric representation of the month (e.g. 1 represents January, 2 represents February,...
Code in Java Write a Student class which has two instance variables, ID and name. This...
Code in Java Write a Student class which has two instance variables, ID and name. This class should have a two-parameter constructor that will set the value of ID and name variables. Write setters and getters for both instance variables. The setter for ID should check if the length of ID lies between 6 to 8 and setter for name should check that the length of name should lie between 0 to 20. If the value could not be set,...
Program Requirements: This assignment requires you to create one program in Java to simulate a Point-of-Sale...
Program Requirements: This assignment requires you to create one program in Java to simulate a Point-of-Sale (POS) system. The solution must be in JAVA language. You create the main program called POSmain.java and two classes: ShoppingCart and CashRegister. Your POSmain program should take three file names from command line arguments. The first file contains a list of products and their prices; the second and third files are lists of items in two shopping carts of two customers. The POSmain program...
in JAVA Create a class called “MinMax” that satisfies the following requirements: a. create an integer...
in JAVA Create a class called “MinMax” that satisfies the following requirements: a. create an integer array called nums that has 20 cells b. generate a random number between 5 and 30, and populate the array nums c. print the minimum and maximum number in the array nums d. print sum and average of numbers in the array nums Your output look like this: (Note: numbers shown below will be different in your program due to the random numbers) minimum...
1. Write a Java program from scratch that meets the following requirements: a. The program is...
1. Write a Java program from scratch that meets the following requirements: a. The program is in a file called Duplicates.java that defines a class called Duplicates (upper/lower case matters) b. The program includes a Java method called noDuplicates that takes an array of integers and returns true if all the integers in that array are distinct (i.e., no duplicates). Otherwise it returns false. Make sure the method is public static. example tests: noDuplicates({}) returns true noDuplicates({-1, 1}) returns true...
In Java create a program that does the following. Suppose you shop for rice in two...
In Java create a program that does the following. Suppose you shop for rice in two different packages. You would like to write a program to compare the cost. The program prompts the user to enter the weight and price of each package and displays the one with the better price. Here are two sample runs: Enter the weight for package 1: 50 Enter the price for package 1: 24.59 Enter the weight for package 2: 25 Enter the price...
4 Implement a Java program that meets the following requirements • You can use the Java...
4 Implement a Java program that meets the following requirements • You can use the Java standard sequence data structure API types for sets, lists, stack,queue and priority queue as needed. All are available in the java.util package, which you will want to import in your program. 1. Argue in code comments which data structure, stack or queue, you will use to implement this method. Implement a method which creates some String objects as food orders for a small restaurant,...
JAVA Create an HourlyEmployee class that inherits from Employee and has two new instance variables: hours,...
JAVA Create an HourlyEmployee class that inherits from Employee and has two new instance variables: hours, which represents the hours worked, and wage, which represents the employee's pay per hour. (Both are doubles.) Create a constructor that takes the arguments first name, last name, social security number, hourly wage, and the number of hours worked. Also create accessors, mutators, an earnings method that returns the money earned by the employee this week, and a toString method that returns information about...
Create a Java program that receives name, GPA, and graduation year information about a student as...
Create a Java program that receives name, GPA, and graduation year information about a student as user input and prints it to the console. Please use the following constructs in your program: Write your code in a Java class. Define name, GPA and graduation year as variables in our class. Create separate setter and getter methods for those variables. Use your main method, to receive the user input. Initialize an object of the class to call the setter methods and...
Write one Java program and satisfy the following requirements: Rewrite the following if -else if -...
Write one Java program and satisfy the following requirements: Rewrite the following if -else if - else statement as an equivalent switch statement.   if (letter == 'A' | | letter == 'a')         System.out.println("Excellent");         else if (letter == 'B' | | letter == 'b')                System.out.println("You can do better");         else if (letter == 'C' | | letter == 'c')                System.out.println("Try harder");         else if (letter == 'D' | | letter == 'd')                System.out.println("Try much harder");        ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT