Question

In: Computer Science

Java: modify the given example code to make it possible to create a student object by...

Java: modify the given example code to make it possible to create a student object by only specifying the name, all other info may be absent. it may also be possible to add a tag with an absent value.

import java.util.HashMap;
import java.util.Map;

public class Student
{
   private final String aName;
   private String aGender;
   private int aAge;
   private Country aCountry;
   private Map<String, String> aTags = new HashMap<>();
   
   public Song(String pName)
   {
      aName = pName;
   }
   
   public String getName()
   {
      return aName;
   }
   
   public void editTag(String pTag, String pValue)
   {
      aTags.put(pTag, pValue);
   }
}

Solutions

Expert Solution

import java.util.HashMap;

import java.util.Map;

class Student {

    private final String aName;

    private String aGender;

    private int aAge;

    private Country aCountry;

    private Map<String, String> aTags = new HashMap<>();

    // constructor to create Student object only by specifying name

    Student(String name) {

        this.aName = name;

        // all other values are absent

        this.aGender = "";

        this.aAge = 0;

        this.aCountry = new Country();

    }

    public Song(String pName)

    {

        aName = pName;

    }

    public String getName() {

        return aName;

    }

    public void editTag(String pTag, String pValue) {

        aTags.put(pTag, pValue);

    }

    // tag without pvalue

    public void editTag(String pTag) {

        aTags.put(pTag, "");

    }

    // setters

    void setName(String name) {

        this.aName = name;

    }

    void setAge(int age) {

        this.aAge = age;

    }

    void setCountry(Country country) {

        this.aCountry = country;

    }

    // getters

    String getName() {

        return this.aName;

    }

    int getAge() {

        return this.aAge;

    }

    Country getCountry() {

        return this.aCountry;

    }

}

.

If you want exact output for some code in main, please provide main() and Country class code.


Related Solutions

Java: modify the given example code to make it possible to create a student object by...
Java: modify the given example code to make it possible to create a student object by only specifying the name, all other info may be absent. it may also be possible to add a tag with an absent value. use OPTIONAL TYPE and NULL object design pattern.   import java.util.HashMap; import java.util.Map; public class Student { private final String aName; private String aGender; private int aAge; private Country aCountry; private Map aTags = new HashMap<>(); public Student(String pName) { aName =...
Modify the provided code to create a program that calculates the amount of change given to...
Modify the provided code to create a program that calculates the amount of change given to a customer based on their total. The program prompts the user to enter an item choice, quantity, and payment amount. Use three functions: • bool isValidChoice(char) – Takes the user choice as an argument, and returns true if it is a valid selection. Otherwise it returns false. • float calcTotal(int, float) – Takes the item cost and the quantity as arguments. Calculates the subtotal,...
For this assignment, you will modify existing code to create a single Java™ program named BicycleDemo.java...
For this assignment, you will modify existing code to create a single Java™ program named BicycleDemo.java that incorporates the following: An abstract Bicycle class that contains private data relevant to all types of bicycles (cadence, speed, and gear) in addition to one new static variable: bicycleCount. The private data must be made visible via public getter and setter methods; the static variable must be set/manipulated in the Bicycle constructor and made visible via a public getter method. Two concrete classes...
JAVA programming language Modify the following code. Make changes so that Movies can be sorted by...
JAVA programming language Modify the following code. Make changes so that Movies can be sorted by title ----------------------------------------------------------------- package Model; import java.time.Duration; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; // TODO - Modify the movie class so that Java knows how to compare two Movies for sorting by title public class Movie extends DataStoreObj { private String title; private String description; private LocalDate releaseDate; private Duration runningTime; private Rating rating; private List<Genre> genres = new ArrayList<>(); private List<Actor> actors = new...
Python: You will modify the given code to create a guessing game that takes user input...
Python: You will modify the given code to create a guessing game that takes user input and allows you to make multiple guesses. There should also be a loop Use the following attached Sample Code as a guide. There are mistakes in the code!!! #Guessing Game import random number=random.randint(1, another number) print("Hello, CIS 101") print("Let's play a guessing Game!called guess my number.") print("The rules are: ") print("I think of a number and you'll have to guess it.") guess = random.randint(1,...
Modify the object provided in the code below to include a variety of overloaded operators in...
Modify the object provided in the code below to include a variety of overloaded operators in C++. Your object should have the following member variables: 1. float *arr a. A dynamic float array that constitutes the data in your myArray object. 2. int size a. The size of the array that the myArray object holds Modify the provided code to include a variety of overloaded operators Operators to overload: 1. bool operator!=(myArray& obj2) a. Tests to see if the calling...
JAVA programming language Please add or modify base on the given code Adding functionality Add functionality...
JAVA programming language Please add or modify base on the given code Adding functionality Add functionality for multiplication (*) Adding JUnit tests Add one appropriately-named method to test some valid values for tryParseInt You will use an assertEquals You'll check that tryParseInt returns the expected value The values to test: "-2" "-1" "0" "1" "2" Hint: You will need to cast the return value from tryParseInt to an int e.g., (int) ValidationHelper.tryParseInt("1") Add one appropriately-named method to test some invalid...
object oriented programming java Create a Student class that have two data members id (assign to...
object oriented programming java Create a Student class that have two data members id (assign to your ID) and name (assign to your name). Create the object of the Student class by new keyword and printing the objects value. You may name your object as Student1. The output should be like this: 20170500 Asma Zubaida
In this assignment you are going to create a Student class to demonstrate a Student object....
In this assignment you are going to create a Student class to demonstrate a Student object. Then create a StudentTest class to place the main method in, which demonstrates the Student object. Student class should have the following instance variables: firstName, middleName, lastName (String) id (int) grade (int) Student class should have the following methods: Set and Get methods for each variable Constructor that sets all variables using Set methods that you defined. Design the application in main that you...
Need to make Java code as following: Create a dice playing threading program to do the...
Need to make Java code as following: Create a dice playing threading program to do the following: 1. Start a thread for a process to simulate a computer rolling a die 1000 times. 2. Start another thread for a process to simulate a user rolling a die 1000 times. 3. Keep track of rolls for user and computer in an array(s). 4. Display on screen when the computer thread starts, the rolls, and when the computer thread ends. 5. Display...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT