My resolution isnt printing our correct it ask again for a n

My resolution isn\'t printing our correct, it ask again for a new input but thats about it. it doesnt check to see if its the correct input. here is my code:

import java.util.Scanner;
public class encap
{
   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 input = new Scanner(System.in);
       System.out.print(\"Please enter userID : \");
       userID = input.next();
       return userID;
   }
   public static String getpassword()
   {
       Scanner input = new Scanner(System.in);
       System.out.print(\"Please enter password : \");
       password = input.next();
       return password;
   }
   public static String getresolution()
   {
       Scanner input = new Scanner(System.in);
       System.out.print(\"Please enter video resolution: \");
       resolution = input.next();
       if (resolution.equals(\"800x600\") || resolution.equals(\"1024x768\") || resolution.equals(\"1152x900\"));
       else
       {
           while(true)
           {
               System.out.println(\"Information invalid, Please fill again\");
               String getresolution = input.next();
               if (resolution.equals(\"800x600\") || resolution.equals(\"1024x768\") || resolution.equals(\"1152x900\"));
               break;
           }
       }
       return resolution;
   }
  
   public static int getRamsize()
   {
       Scanner input = new Scanner(System.in);
       System.out.print(\"Please enter RAM size : \");
       while(true)
       {
           if(input.hasNextInt())
           {
               Ramsize = input.nextInt();
               break;
           }
           else
           {
           input.nextLine();
           System.out.println(\"Invalid Input! Integer required\");
           System.out.print(\"Please enter RAM size : \");
           }
       }
       return Ramsize;
   }
   public static int getfreespace()
   {
       Scanner input = new Scanner(System.in);
       System.out.print(\"Please enter HD free space : \");
       while(true)
       {
           if(input.hasNextInt())
           {
               freespace = input.nextInt();
               break;
           }
           else
           {
               input.nextLine();
               System.out.println(\"Invalid Input! Integer required\");
               System.out.print(\"Please enter HD free space : \");

           }   
       }
       return freespace;
   }
  
   public static int getvideocard()
   {
       Scanner input = new Scanner(System.in);
       System.out.print(\"Please enter video card RAM size: \");
       while(true)
       {
           if(input.hasNextInt())
           {
               videocard = input.nextInt();
               break;
           }
           else
           {
               input.nextLine();
               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 newresolution)
   {
       resolution = newresolution;
   }
  
   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());
   System.out.println(\"You have input the following information: \" + \"\ userID: \" + userID
           + \"\ password: \" + password + \"\ Video resolution: \" + resolution + \"\ Ram Size: \"
           + Ramsize + \"\ HD Free Space: \" + freespace + \"\ Video Card Ram Size: \" + videocard);
   }
}

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

Solution

HI Friend, Please find my correct code that follow the encapsulation rules.

Please let me know in case of any issue.

import java.util.Scanner;

public class encap

{

   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 input = new Scanner(System.in);

       encap obj1 = new encap();

       System.out.print(\"Please enter userID : \");

       String userID = input.next();

       obj1.setUserID(userID);

       System.out.print(\"Please enter password : \");

       String password = input.next();

       obj1.setPassword(password);

       System.out.print(\"Please enter video resolution: \");

       while(true)

       {

           String resolution = input.next();

           if (resolution.equals(\"800x600\") || resolution.equals(\"1024x768\") || resolution.equals(\"1152x900\")){

               obj1.setResolution(resolution);

               break;

           }

          

           System.out.println(\"Information invalid, Please fill again\");

       }

      

while (true) {

   System.out.print(\"Please enter RAM size : \");

String ramsize = input.next();

int intInputValue = 0;

try {

intInputValue = Integer.parseInt(ramsize);

obj1.setRamsize(intInputValue);

break;

} catch (NumberFormatException ne) {

   System.out.println(\"Invalid Input! Integer required\");

}

}

      

      

       while (true) {

           System.out.print(\"Please enter HD free space : \");

String freespace = input.next();

int intInputValue = 0;

try {

intInputValue = Integer.parseInt(freespace);

obj1.setFreespace(intInputValue);

break;

} catch (NumberFormatException ne) {

   System.out.println(\"Invalid Input! Integer required\");

}

}

      

       while (true) {

           System.out.print(\"Please enter video card RAM size: \");

String videocard = input.next();

int intInputValue = 0;

try {

intInputValue = Integer.parseInt(videocard);

obj1.setVideocard(intInputValue);

break;

} catch (NumberFormatException ne) {

   System.out.println(\"Invalid Input! Integer required\");

}

}

      

       System.out.println(\"You have input the following information: \" + \"\ userID: \" + obj1.getUserID()

       + \"\ password: \" + obj1.getPassword() + \"\ Video resolution: \" + obj1.getResolution() + \"\ Ram Size: \"

       + obj1.getRamsize() + \"\ HD Free Space: \" + obj1.getFreespace() +

       \"\ Video Card Ram Size: \" + obj1.getVideocard());

   }

}

My resolution isn\'t printing our correct, it ask again for a new input but thats about it. it doesnt check to see if its the correct input. here is my code: im
My resolution isn\'t printing our correct, it ask again for a new input but thats about it. it doesnt check to see if its the correct input. here is my code: im
My resolution isn\'t printing our correct, it ask again for a new input but thats about it. it doesnt check to see if its the correct input. here is my code: im
My resolution isn\'t printing our correct, it ask again for a new input but thats about it. it doesnt check to see if its the correct input. here is my code: im
My resolution isn\'t printing our correct, it ask again for a new input but thats about it. it doesnt check to see if its the correct input. here is my code: im
My resolution isn\'t printing our correct, it ask again for a new input but thats about it. it doesnt check to see if its the correct input. here is my code: im
My resolution isn\'t printing our correct, it ask again for a new input but thats about it. it doesnt check to see if its the correct input. here is my code: im

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site