Write a Java program using objectoriented techniquesThis pro
Write a Java program using object-oriented techniques.This program needs to manage the settings of an online video game. It must support the following operations:
1) Method to request a userID and password, each as a string
2) Method to request the wanted video resolution as a string (valid settings: 800x600, 1024x768, 1152x900)
3) Method to request computer information each as an integer (use: RAM size, HD free space, video card RAM size)
4) Method (or methods) to display the selected settings to the user for verification. If the data entered is not accepted, request the information again (note: it is fine to request ALL the information again, it is not necessary to only request specific info to be re-entered, but you can if you would like) The class/object should hold the primitive values listed above (such as: userID, resolution, etc.) but it should not allow the values to be altered directly.
The programmer should be required to use “get” and “set” methods instead. The “set” method for the video resolution should verify that the selected value entered by the user is one of the valid settings listed above. This assignment does require use of a class and to instantiate at least one object, but it does not need to utilize polymorphism, inheritance, the use of an interface, etc. It does require encapsulation, as suggested by the “get” and “set” method requirements, otherwise it is best to keep it simple.
This is what i have so far, i was told i needed a void while loop ( to check the video resolution) and scanner (to get user input):
public class Encapsulation{
private String userID;
private String password;
private String resolution;
private int Ramsize;
private int freespace;
private int videocard;
//Get and Set methods
public String getuserID(){
return userID;
}
public String getpassword(){
return password;
}
public String getresolution(){
return resolution;
}
public int getRamsize(){
return Ramsize;
}
public int getfreespace(){
return freespace;
}
public int getvideocard(){
return videocard;
}
public void setuserID(String newuserID){
userID = newuserID;
}
public void setpassword(String newpassword){
password = newpassword;
}
public void setresolution(String newresolution){
resolution = newresolution;
}
public void setRamsize (int newRamsize){
Ramsize = newRamsize;
}
public void setfreespace (int newfreespace){
freespace = newfreespace;
}
public void setvideocard (int newvideocard){
videocard = newvideocard;
}
}
Solution
The code is correct, just making a little change to add validation condition of the resolution.
public class Encapsulation{
private String userID;
private String password;
private String resolution;
private int Ramsize;
private int freespace;
private int videocard;
//Get and Set methods
public String getuserID(){
return userID;
}
public String getpassword(){
return password;
}
public String getresolution(){
return resolution;
}
public int getRamsize(){
return Ramsize;
}
public int getfreespace(){
return freespace;
}
public int getvideocard(){
return videocard;
}
public void setuserID(String newuserID){
userID = newuserID;
}
public void setpassword(String newpassword){
password = newpassword;
}
public void setresolution(String newresolution){
// if resolution matches with any of these three valid values resolution is set,otherwise error message is displayed.
if(newresolution.equal(\" 800x600\") || newresolution.equals(\" 1024x768\") || newresolution.equals(\"1152x900\")) resolution=newresolution;
else
System.out.Println(\"Information invalid, Please fill again\");
}
public void setRamsize (int newRamsize){
Ramsize = newRamsize;
}
public void setfreespace (int newfreespace){
freespace = newfreespace;
}
public void setvideocard (int newvideocard){
videocard = newvideocard;
}
}


