Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is what I have so far: I\'m not sure how \"get\" and \"set\" works, also i

ID: 3783359 • Letter: T

Question

This is what I have so far: I'm not sure how "get" and "set" works, also i can't get it to ask for an input again if the input is invalid. Im supposed to use a loop. Also, how would I get it to ask again if the the input isn't a integer? If the user input "time" for Ram size, how would i ask again for a valid whole int?

import java.util.Scanner;

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;
}

public static void main(String[] args)
   {
       Scanner scanner = new Scanner(System.in);
       System.out.print("Please enter userID : ");
       String getuserID = scanner.next();
       System.out.print("Please enter password : ");
       String getpassword = scanner.next();
       System.out.print("Please enter video resolution: ");
       String newresolution = scanner.next();
       if (newresolution.equals("800x600") || newresolution.equals("1024x768") || newresolution.equals("1152x900"));
           else
           {
               while(true)
               {
               System.out.println("Information invalid, Please fill again");
               String getresolution = scanner.next();
               if (newresolution.equals("800x600") || newresolution.equals("1024x768") || newresolution.equals("1152x900"));
               break;
               }
           }
   }
}

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 f 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 Example input: userID: Elvis Presley password: Graceland video resolution: 1024x768 Ram size (in whole GB): 16 HD free space (in whole GB): 550 Video card RAM size (GB): 4

Explanation / Answer

// Encapsulation.java

import java.util.Scanner;
public class Encapsulation

{
private static String userID;
private static String password;
private static String resolution;
private static int Ramsize;
private static int freespace;
private static int videocard;
  
//Get and Set methods

public static String getuserID()
{
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter userID : ");
userID = scanner.next();
return userID;
}
public static String getpassword()
{
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter password : ");
password = scanner.next();
return password;
}
public static String getresolution()
{
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter video resolution: ");
resolution = scanner.next();
if (resolution.equals("800x600") || resolution.equals("1024x768") || resolution.equals("1152x900"));
else
{
while(true)
{
System.out.println("Information invalid, Please fill again");
String getresolution = scanner.next();
if (resolution.equals("800x600") || resolution.equals("1024x768") || resolution.equals("1152x900"));
break;
}
}
return resolution;
}
  
public static int getRamsize()
{
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter RAM size : ");
  
while(true)
{
if(scanner.hasNextInt())
{
Ramsize = scanner.nextInt();
break;
}
else
{
scanner.nextLine(); //Comsume the garbage value
System.out.println("Invalid Input! Integer required");
System.out.print(" Please enter RAM size : ");
}
}
return Ramsize;
}
public static int getfreespace()
{
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter HD free space : ");
  
while(true)
{
if(scanner.hasNextInt())
{
freespace = scanner.nextInt();
break;
}
else
{
scanner.nextLine(); //Comsume the garbage value
System.out.println("Invalid Input! Integer required");
System.out.print(" Please enter HD free space : ");

}   
}
return freespace;
}
  
public static int getvideocard()
{
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter video card RAM size: ");
  
while(true)
{
if(scanner.hasNextInt())
{
videocard = scanner.nextInt();
break;
}
else
{
scanner.nextLine(); //Comsume the garbage value
System.out.println("Invalid Input! Integer required");
System.out.print(" Please enter video card RAM size: ");
}   
}
return videocard;
}
  
public static void setuserID(String newuserID)
{
userID = newuserID;
}
public static void setpassword(String newpassword)
{
password = newpassword;
}
public static void setresolution(String resolution)
  
{
resolution=resolution;
}
  
public static void setRamsize (int newRamsize)
{
Ramsize = newRamsize;
}
  
public static void setfreespace (int newfreespace)
{
freespace = newfreespace;
}
  
public static void setvideocard (int newvideocard)
{
videocard = newvideocard;
}
public static void main(String[] args)
{
setuserID(getuserID());
setpassword(getpassword());
setresolution(getresolution());
setRamsize(getRamsize());
setfreespace(getfreespace());
setvideocard(getvideocard());

}
}


/*
output:

Please enter userID : Elvis Presley
Please enter password : Graceland
Please enter video resolution: 1024X34
Information invalid, Please fill again
1024X768
Please enter RAM size : time
Invalid Input! Integer required

Please enter RAM size : 16
Please enter HD free space : time
Invalid Input! Integer required

Please enter HD free space : 550
Please enter video card RAM size: number
Invalid Input! Integer required

Please enter video card RAM size: 4

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote