Thanks guys, I may be a total noob with code outside of HTML and CSS, but I'm here to learn.
public class Computer
{
private String cpuType; // This is the first name attribute of a Computer object
private String moboType;
private int ramCount;
private int hddSize; // This is the last name attribute of a Computer object
// This is a constructor with no parameters for the Computer class
public Computer()
{
setCpuType("");
setMoboType("");
setRamCount(0);
setHddSize(0);
}
public void setCpuType(String cType)
{
cpuType = cType;
}
public void setMoboType(String mType)
{
moboType = mType;
}
public void setRamCount(int ramInSticks)
{
ramCount = ramInSticks;
}
public void setHddSize(int hddInGigs)
{
hddSize = hddInGigs;
}
public String getCpuType()
{
return cpuType;
}
public String getMoboType()
{
return moboType;
}
public int getRamCount()
{
return ramCount;
}
public int getHddSize()
{
return hddSize;
}
// This is a special toString() method that returns the attributes of a Computer object
// when the object used in a String context.
public String toString()
{
return "CPU Type: "+getCpuType()+"\n"+
"Motherboard Type: "+getMoboType()+"\n"+
"Sticks of RAM: "+getRamCount()+"\n"+
"Size of HDD (in Gigabytes): "+getHddSize();
}
}
public class ComputerBuilder
{
public static void main(String[] args)
{
Scanner inputObject = new Scanner(System.in);
Computer computer1 = new Computer();
String cpuType;
String moboType;
int ramCount;
int hddSize;
System.out.print("What type of CPU would you like to choose for this build? ");
cpuType = inputObject.nextLine();
computer1.setCpuType(cpuType);
System.out.print("What type of Motherboard would you like for this build? ");
moboType = inputObject.nextLine();
computer1.setMoboType(moboType);
System.out.print("How many sticks of RAM would you like? ");
ramCount = Integer.parseInt(inputObject.nextLine());
computer1.setRamCount(ramCount);
System.out.print("What size HDD (in GB) would you like as your boot drive? ");
hddSize = Integer.parseInt(inputObject.nextLine());
computer1.setHddSize(hddSize);
System.out.println(computer1);
}
}

New Topic/Question
Reply



MultiQuote








|